summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2018-04-24 14:28:20 -0700
committerDylan Baker <dylan@pnwbakers.com>2018-04-24 14:28:20 -0700
commitd84220dd55cc4eb54d48cb8e325e417e369cde65 (patch)
tree31b848c6e91f7b9ed39a23bd4d1abfa440a104a2 /tests
parentb6f36c0106af4b833bd7b7cbbafd7405afc23763 (diff)
Revert "Extract some context managers for patch objects."
This reverts commit d01d2e51da45dd87f0abf98b8a856f3b3de69153. I don't think that this patch really improved readability that much. The right solution is to split ComposeCommand.apply so we don't need so many mocks.
Diffstat (limited to 'tests')
-rw-r--r--tests/commands/envelope_test.py12
-rw-r--r--tests/commands/global_test.py77
2 files changed, 34 insertions, 55 deletions
diff --git a/tests/commands/envelope_test.py b/tests/commands/envelope_test.py
index 30e21c03..ee1c0acc 100644
--- a/tests/commands/envelope_test.py
+++ b/tests/commands/envelope_test.py
@@ -230,10 +230,8 @@ class TestSignCommand(unittest.TestCase):
"""
env, ui = self._make_ui_mock()
- func_patcher = mock.patch(
- 'alot.commands.envelope.settings.get_account_by_address',
- mock.Mock(return_value=mock.Mock(gpg_key=None)))
- with func_patcher:
+ with mock.patch('alot.commands.envelope.settings.get_account_by_address',
+ mock.Mock(return_value=mock.Mock(gpg_key=None))):
cmd = envelope.SignCommand(action='sign', keyid=None)
cmd.apply(ui)
@@ -247,10 +245,8 @@ class TestSignCommand(unittest.TestCase):
"""
env, ui = self._make_ui_mock()
- func_patcher = mock.patch(
- 'alot.commands.envelope.settings.get_account_by_address',
- mock.Mock(return_value=mock.Mock(gpg_key='sentinel')))
- with func_patcher:
+ with mock.patch('alot.commands.envelope.settings.get_account_by_address',
+ mock.Mock(return_value=mock.Mock(gpg_key='sentinel'))):
cmd = envelope.SignCommand(action='sign', keyid=None)
cmd.apply(ui)
diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py
index 59943e5e..850c9447 100644
--- a/tests/commands/global_test.py
+++ b/tests/commands/global_test.py
@@ -17,8 +17,6 @@
"""Tests for global commands."""
from __future__ import absolute_import
-
-import contextlib
import os
import tempfile
@@ -66,21 +64,16 @@ 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.
- 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())
+ 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
self.assertTrue(envelope.sign)
self.assertIs(envelope.sign_key, mock.sentinel.gpg_key)
@@ -93,21 +86,16 @@ 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.
- 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())
+ 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
self.assertFalse(envelope.sign)
self.assertIs(envelope.sign_key, None)
@@ -120,21 +108,16 @@ 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.
- 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())
+ 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
self.assertFalse(envelope.sign)
self.assertIs(envelope.sign_key, None)