From cd11aa50f8061fdc41a3e62c70a1ace7d1784eef Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 22 Aug 2017 12:50:28 -0700 Subject: 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. --- tests/commands/global_test.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests') 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') -- cgit v1.2.3