summaryrefslogtreecommitdiff
path: root/tests/commands/global_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/commands/global_test.py')
-rw-r--r--tests/commands/global_test.py77
1 files changed, 47 insertions, 30 deletions
diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py
index e3d91f8a..102d75c2 100644
--- a/tests/commands/global_test.py
+++ b/tests/commands/global_test.py
@@ -17,6 +17,8 @@
"""Tests for global commands."""
from __future__ import absolute_import
+
+import contextlib
import os
import tempfile
@@ -63,16 +65,21 @@ class TestComposeCommand(unittest.TestCase):
# This whole mess is required becasue ComposeCommand.apply is waaaaay
# too complicated, it needs to be split into more manageable segments.
- with mock.patch('alot.commands.globals.settings.get_account_by_address',
- mock.Mock(return_value=account)):
- with mock.patch('alot.commands.globals.settings.get_accounts',
- mock.Mock(return_value=[account])):
- with mock.patch('alot.commands.globals.settings.get_addressbooks',
- mock.Mock(side_effect=Stop)):
- try:
- yield cmd.apply(mock.Mock())
- except Stop:
- pass
+ func_patcher_get_account_by_address = mock.patch(
+ 'alot.commands.globals.settings.get_account_by_address',
+ mock.Mock(return_value=account))
+ func_patcher_get_accounts = mock.patch(
+ 'alot.commands.globals.settings.get_accounts',
+ mock.Mock(return_value=[account]))
+ func_patcher_get_addressbooks = mock.patch(
+ 'alot.commands.globals.settings.get_addressbooks',
+ mock.Mock(side_effect=Stop))
+ with contextlib.ExitStack() as stack:
+ stack.enter_context(func_patcher_get_account_by_address)
+ stack.enter_context(func_patcher_get_accounts)
+ stack.enter_context(func_patcher_get_addressbooks)
+ with self.assertRaises(Stop):
+ yield cmd.apply(mock.Mock())
self.assertTrue(envelope.sign)
self.assertIs(envelope.sign_key, mock.sentinel.gpg_key)
@@ -85,16 +92,21 @@ class TestComposeCommand(unittest.TestCase):
# This whole mess is required becasue ComposeCommand.apply is waaaaay
# too complicated, it needs to be split into more manageable segments.
- with mock.patch('alot.commands.globals.settings.get_account_by_address',
- mock.Mock(return_value=account)):
- with mock.patch('alot.commands.globals.settings.get_accounts',
- mock.Mock(return_value=[account])):
- with mock.patch('alot.commands.globals.settings.get_addressbooks',
- mock.Mock(side_effect=Stop)):
- try:
- yield cmd.apply(mock.Mock())
- except Stop:
- pass
+ func_patcher_get_account_by_address = mock.patch(
+ 'alot.commands.globals.settings.get_account_by_address',
+ mock.Mock(return_value=account))
+ func_patcher_get_accounts = mock.patch(
+ 'alot.commands.globals.settings.get_accounts',
+ mock.Mock(return_value=[account]))
+ func_patcher_get_addressbooks = mock.patch(
+ 'alot.commands.globals.settings.get_addressbooks',
+ mock.Mock(side_effect=Stop))
+ with contextlib.ExitStack() as stack:
+ stack.enter_context(func_patcher_get_account_by_address)
+ stack.enter_context(func_patcher_get_accounts)
+ stack.enter_context(func_patcher_get_addressbooks)
+ with self.assertRaises(Stop):
+ yield cmd.apply(mock.Mock())
self.assertFalse(envelope.sign)
self.assertIs(envelope.sign_key, None)
@@ -107,16 +119,21 @@ class TestComposeCommand(unittest.TestCase):
# This whole mess is required becasue ComposeCommand.apply is waaaaay
# too complicated, it needs to be split into more manageable segments.
- with mock.patch('alot.commands.globals.settings.get_account_by_address',
- mock.Mock(return_value=account)):
- with mock.patch('alot.commands.globals.settings.get_accounts',
- mock.Mock(return_value=[account])):
- with mock.patch('alot.commands.globals.settings.get_addressbooks',
- mock.Mock(side_effect=Stop)):
- try:
- yield cmd.apply(mock.Mock())
- except Stop:
- pass
+ func_patcher_get_account_by_address = mock.patch(
+ 'alot.commands.globals.settings.get_account_by_address',
+ mock.Mock(return_value=account))
+ func_patcher_get_accounts = mock.patch(
+ 'alot.commands.globals.settings.get_accounts',
+ mock.Mock(return_value=[account]))
+ func_patcher_get_addressbooks = mock.patch(
+ 'alot.commands.globals.settings.get_addressbooks',
+ mock.Mock(side_effect=Stop))
+ with contextlib.ExitStack() as stack:
+ stack.enter_context(func_patcher_get_account_by_address)
+ stack.enter_context(func_patcher_get_accounts)
+ stack.enter_context(func_patcher_get_addressbooks)
+ with self.assertRaises(Stop):
+ yield cmd.apply(mock.Mock())
self.assertFalse(envelope.sign)
self.assertIs(envelope.sign_key, None)