diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-08-22 12:50:28 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-08-23 08:22:31 -0700 |
commit | cd11aa50f8061fdc41a3e62c70a1ace7d1784eef (patch) | |
tree | 0e13c2afe1ecdc620d71c409ba4fb8efc337b998 /tests | |
parent | 02bfa35038dd7a8eb8e3808ac98a7620fea3081f (diff) |
tests/commands/global: Test ExternalCommand when not spawning
This doesn't test the spawn path, which is a little bit more
complicated since it's running code in a thread instead of in the main
thread.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/commands/global_test.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 860a6ccb..c3516a7a 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -116,3 +116,34 @@ class TestComposeCommand(unittest.TestCase): self.assertFalse(envelope.sign) self.assertIs(envelope.sign_key, None) + + +class TestExternalCommand(unittest.TestCase): + + class Success(Exception): + pass + + def on_success(self): + raise self.Success + + def test_no_spawn_no_stdin_success(self): + cmd = g_commands.ExternalCommand( + u'true', + refocus=False, on_success=self.on_success) + with self.assertRaises(self.Success): + cmd.apply(mock.Mock()) + + def test_no_spawn_stdin_success(self): + cmd = g_commands.ExternalCommand( + u"awk '{ exit $0 }'", + stdin=u'0', refocus=False, on_success=self.on_success) + with self.assertRaises(self.Success): + cmd.apply(mock.Mock()) + + def test_no_spawn_failure(self): + ui = mock.Mock() + cmd = g_commands.ExternalCommand( + u'false', + refocus=False, on_success=self.on_success) + cmd.apply(ui) + ui.notify.assert_called_once_with('', priority='error') |