summaryrefslogtreecommitdiff
path: root/tests/commands
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-17 15:42:03 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:35:47 -0700
commit3db06a6a2b9a82640eb44ccd808375a3687b97f9 (patch)
tree3048afadab847b8f90d14f3993b93818a5e180eb /tests/commands
parent75a92ad5f5b85dcdab20d14bf0434a7502f2bf30 (diff)
commands/globals: implement ExternalCommand.apply as coroutine
Rather than returning a deferred in some cases, this makes the function a coroutine, in some cases it calls regular subprocess, in other cases it uses asyncio subprocess.
Diffstat (limited to 'tests/commands')
-rw-r--r--tests/commands/global_test.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py
index b0e52913..88762799 100644
--- a/tests/commands/global_test.py
+++ b/tests/commands/global_test.py
@@ -176,47 +176,54 @@ class TestComposeCommand(unittest.TestCase):
class TestExternalCommand(unittest.TestCase):
+ @inlineCallbacks
def test_no_spawn_no_stdin_success(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'true', refocus=False)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_not_called()
+ @inlineCallbacks
def test_no_spawn_stdin_success(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u"awk '{ exit $0 }'", stdin=u'0',
refocus=False)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_not_called()
+ @inlineCallbacks
def test_no_spawn_no_stdin_attached(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'test -t 0', refocus=False)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_not_called()
+ @inlineCallbacks
def test_no_spawn_stdin_attached(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(
u"test -t 0", stdin=u'0', refocus=False)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_called_once_with('', priority='error')
+ @inlineCallbacks
def test_no_spawn_failure(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'false', refocus=False)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_called_once_with('', priority='error')
+ @inlineCallbacks
@mock.patch(
'alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
def test_spawn_no_stdin_success(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'true', refocus=False, spawn=True)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_not_called()
+ @inlineCallbacks
@mock.patch(
'alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
@@ -225,14 +232,15 @@ class TestExternalCommand(unittest.TestCase):
cmd = g_commands.ExternalCommand(
u"awk '{ exit $0 }'",
stdin=u'0', refocus=False, spawn=True)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_not_called()
+ @inlineCallbacks
@mock.patch(
'alot.commands.globals.settings.get', mock.Mock(return_value=''))
@mock.patch.dict(os.environ, {'DISPLAY': ':0'})
def test_spawn_failure(self):
ui = utilities.make_ui()
cmd = g_commands.ExternalCommand(u'false', refocus=False, spawn=True)
- cmd.apply(ui)
+ yield ensureDeferred(cmd.apply(ui))
ui.notify.assert_called_once_with('', priority='error')