summaryrefslogtreecommitdiff
path: root/tests/commands
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-07-17 21:43:07 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-07-26 10:36:11 -0700
commit5293665df4c7747e7126d724bb53502184e958c7 (patch)
tree6dd14dca8b2f091e94bfcc861f83f58169b41014 /tests/commands
parent1af48c55cd5b0bf67b545db7c99fcf46be51a3ba (diff)
tests/commands/global: use utilities.async_test
Diffstat (limited to 'tests/commands')
-rw-r--r--tests/commands/global_test.py75
1 files 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')