From 5293665df4c7747e7126d724bb53502184e958c7 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 17 Jul 2018 21:43:07 -0700 Subject: tests/commands/global: use utilities.async_test --- tests/commands/global_test.py | 75 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 88762799..2c6fd845 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -1,5 +1,5 @@ # encoding=utf-8 -# Copyright © 2017 Dylan Baker +# Copyright © 2017-2018 Dylan Baker # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,6 @@ import os import tempfile from twisted.trial import unittest -from twisted.internet.defer import inlineCallbacks, ensureDeferred import mock from alot.commands import globals as g_commands @@ -55,8 +54,8 @@ class TestComposeCommand(unittest.TestCase): account.signature = None return account - @inlineCallbacks - def test_apply_sign_by_default_okay(self): + @utilities.async_test + async def test_apply_sign_by_default_okay(self): envelope = self._make_envelope_mock() account = self._make_account_mock() cmd = g_commands.ComposeCommand(envelope=envelope) @@ -70,15 +69,15 @@ class TestComposeCommand(unittest.TestCase): with mock.patch('alot.commands.globals.settings.get_addressbooks', mock.Mock(side_effect=Stop)): try: - yield ensureDeferred(cmd.apply(mock.Mock())) + await cmd.apply(mock.Mock()) except Stop: pass self.assertTrue(envelope.sign) self.assertIs(envelope.sign_key, mock.sentinel.gpg_key) - @inlineCallbacks - def test_apply_sign_by_default_false_doesnt_set_key(self): + @utilities.async_test + async def test_apply_sign_by_default_false_doesnt_set_key(self): envelope = self._make_envelope_mock() account = self._make_account_mock(sign_by_default=False) cmd = g_commands.ComposeCommand(envelope=envelope) @@ -92,15 +91,15 @@ class TestComposeCommand(unittest.TestCase): with mock.patch('alot.commands.globals.settings.get_addressbooks', mock.Mock(side_effect=Stop)): try: - yield ensureDeferred(cmd.apply(mock.Mock())) + await cmd.apply(mock.Mock()) except Stop: pass self.assertFalse(envelope.sign) self.assertIs(envelope.sign_key, None) - @inlineCallbacks - def test_apply_sign_by_default_but_no_key(self): + @utilities.async_test + async def test_apply_sign_by_default_but_no_key(self): envelope = self._make_envelope_mock() account = self._make_account_mock(gpg_key=None) cmd = g_commands.ComposeCommand(envelope=envelope) @@ -114,15 +113,15 @@ class TestComposeCommand(unittest.TestCase): with mock.patch('alot.commands.globals.settings.get_addressbooks', mock.Mock(side_effect=Stop)): try: - yield ensureDeferred(cmd.apply(mock.Mock())) + await cmd.apply(mock.Mock()) except Stop: pass self.assertFalse(envelope.sign) self.assertIs(envelope.sign_key, None) - @inlineCallbacks - def test_decode_template_on_loading(self): + @utilities.async_test + async def test_decode_template_on_loading(self): subject = u'This is a täßϑ subject.' to = u'recipient@mail.com' _from = u'foo.bar@mail.fr' @@ -140,7 +139,7 @@ class TestComposeCommand(unittest.TestCase): 'alot.commands.globals.settings.get_account_by_address', mock.Mock(side_effect=Stop)): try: - yield ensureDeferred(cmd.apply(mock.Mock())) + await cmd.apply(mock.Mock()) except Stop: pass @@ -176,71 +175,71 @@ class TestComposeCommand(unittest.TestCase): class TestExternalCommand(unittest.TestCase): - @inlineCallbacks - def test_no_spawn_no_stdin_success(self): + @utilities.async_test + async def test_no_spawn_no_stdin_success(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u'true', refocus=False) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_not_called() - @inlineCallbacks - def test_no_spawn_stdin_success(self): + @utilities.async_test + async def test_no_spawn_stdin_success(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u"awk '{ exit $0 }'", stdin=u'0', refocus=False) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_not_called() - @inlineCallbacks - def test_no_spawn_no_stdin_attached(self): + @utilities.async_test + async def test_no_spawn_no_stdin_attached(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u'test -t 0', refocus=False) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_not_called() - @inlineCallbacks - def test_no_spawn_stdin_attached(self): + @utilities.async_test + async def test_no_spawn_stdin_attached(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand( u"test -t 0", stdin=u'0', refocus=False) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') - @inlineCallbacks - def test_no_spawn_failure(self): + @utilities.async_test + async def test_no_spawn_failure(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u'false', refocus=False) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') - @inlineCallbacks + @utilities.async_test @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): + async def test_spawn_no_stdin_success(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u'true', refocus=False, spawn=True) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_not_called() - @inlineCallbacks + @utilities.async_test @mock.patch( 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) - def test_spawn_stdin_success(self): + async def test_spawn_stdin_success(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand( u"awk '{ exit $0 }'", stdin=u'0', refocus=False, spawn=True) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_not_called() - @inlineCallbacks + @utilities.async_test @mock.patch( 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) - def test_spawn_failure(self): + async def test_spawn_failure(self): ui = utilities.make_ui() cmd = g_commands.ExternalCommand(u'false', refocus=False, spawn=True) - yield ensureDeferred(cmd.apply(ui)) + await cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') -- cgit v1.2.3