From 018279b18e7c95b40d94a09fc68fa3b3aa1fc6b0 Mon Sep 17 00:00:00 2001 From: Ben Finney Date: Mon, 23 Apr 2018 16:30:28 +1000 Subject: Wrap long statements on open-bracket syntax. --- tests/commands/global_test.py | 20 +++++++++++++------- tests/commands/utils_tests.py | 6 ++++-- tests/completion_test.py | 6 ++++-- tests/crypto_test.py | 24 ++++++++++++++++-------- tests/db/utils_test.py | 24 ++++++++++++++++-------- 5 files changed, 53 insertions(+), 27 deletions(-) (limited to 'tests') diff --git a/tests/commands/global_test.py b/tests/commands/global_test.py index 102d75c2..59943e5e 100644 --- a/tests/commands/global_test.py +++ b/tests/commands/global_test.py @@ -50,7 +50,8 @@ class TestComposeCommand(unittest.TestCase): return envelope @staticmethod - def _make_account_mock(sign_by_default=True, gpg_key=mock.sentinel.gpg_key): + def _make_account_mock( + sign_by_default=True, gpg_key=mock.sentinel.gpg_key): account = mock.Mock() account.sign_by_default = sign_by_default account.gpg_key = gpg_key @@ -153,8 +154,9 @@ class TestComposeCommand(unittest.TestCase): cmd = g_commands.ComposeCommand(template=f.name) # Crutch to exit the giant `apply` method early. - with mock.patch('alot.commands.globals.settings.get_account_by_address', - mock.Mock(side_effect=Stop)): + with mock.patch( + 'alot.commands.globals.settings.get_account_by_address', + mock.Mock(side_effect=Stop)): try: yield cmd.apply(mock.Mock()) except Stop: @@ -189,7 +191,8 @@ class TestExternalCommand(unittest.TestCase): def test_no_spawn_stdin_attached(self): ui = utilities.make_ui() - cmd = g_commands.ExternalCommand(u"test -t 0", stdin=u'0', refocus=False) + cmd = g_commands.ExternalCommand( + u"test -t 0", stdin=u'0', refocus=False) cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') @@ -199,7 +202,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_called_once_with('', priority='error') - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @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): ui = utilities.make_ui() @@ -207,7 +211,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_not_called() - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @mock.patch( + 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) def test_spawn_stdin_success(self): ui = utilities.make_ui() @@ -217,7 +222,8 @@ class TestExternalCommand(unittest.TestCase): cmd.apply(ui) ui.notify.assert_not_called() - @mock.patch('alot.commands.globals.settings.get', mock.Mock(return_value='')) + @mock.patch( + 'alot.commands.globals.settings.get', mock.Mock(return_value='')) @mock.patch.dict(os.environ, {'DISPLAY': ':0'}) def test_spawn_failure(self): ui = utilities.make_ui() diff --git a/tests/commands/utils_tests.py b/tests/commands/utils_tests.py index 487d0d3b..c17473dc 100644 --- a/tests/commands/utils_tests.py +++ b/tests/commands/utils_tests.py @@ -57,7 +57,8 @@ def setUpModule(): with gpg.core.Context(armor=True) as ctx: # Add the public and private keys. They have no password - search_dir = os.path.join(os.path.dirname(__file__), '../static/gpg-keys') + search_dir = os.path.join( + os.path.dirname(__file__), '../static/gpg-keys') for each in os.listdir(search_dir): if os.path.splitext(each)[1] == '.gpg': with open(os.path.join(search_dir, each)) as f: @@ -106,7 +107,8 @@ class TestGetKeys(unittest.TestCase): @inlineCallbacks def test_get_keys_ambiguous(self): """Test gettings keys when when the key is ambiguous.""" - key = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) + key = crypto.get_key( + FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() # Creat a ui.choice object that can satisfy twisted, but can also be diff --git a/tests/completion_test.py b/tests/completion_test.py index 5b335779..15a80a89 100644 --- a/tests/completion_test.py +++ b/tests/completion_test.py @@ -57,7 +57,8 @@ class AbooksCompleterTest(unittest.TestCase): self.assertTupleEqual(actual[0], expected[0]) def test_empty_real_name_returns_plain_email_address(self): - actual = self.__class__.example_abook_completer.complete("real-name", 9) + actual = self.__class__.example_abook_completer.complete( + "real-name", 9) expected = [("no-real-name@example.com", 24)] self._assert_only_one_list_entry(actual, expected) @@ -79,7 +80,8 @@ class AbooksCompleterTest(unittest.TestCase): def test_real_name_double_quotes(self): actual = self.__class__.example_abook_completer.complete("dquote", 6) expected = [("", 0)] - expected = [(r""""double \"quote\" person" """, 46)] + expected = [ + (r""""double \"quote\" person" """, 46)] self._assert_only_one_list_entry(actual, expected) def test_real_name_with_quotes_and_comma(self): diff --git a/tests/crypto_test.py b/tests/crypto_test.py index 25cce8ba..c3db1055 100644 --- a/tests/crypto_test.py +++ b/tests/crypto_test.py @@ -59,7 +59,8 @@ def tearDownModule(): lookfor = 'gpg-agent --homedir {}'.format(os.environ['GNUPGHOME']) out = subprocess.check_output( - ['ps', 'xo', 'pid,cmd'], stderr=DEVNULL).decode(urwid.util.detected_encoding) + ['ps', 'xo', 'pid,cmd'], + stderr=DEVNULL).decode(urwid.util.detected_encoding) for each in out.strip().split('\n'): pid, cmd = each.strip().split(' ', 1) if cmd.startswith(lookfor): @@ -113,7 +114,8 @@ class TestDetachedSignatureFor(unittest.TestCase): def test_valid_signature_generated(self): to_sign = b"this is some text.\nit is more than nothing.\n" with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) with tempfile.NamedTemporaryFile(delete=False) as f: f.write(detached) @@ -135,7 +137,8 @@ class TestVerifyDetached(unittest.TestCase): def test_verify_signature_good(self): to_sign = b"this is some text.\nIt's something\n." with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) try: crypto.verify_detached(to_sign, detached) @@ -146,7 +149,8 @@ class TestVerifyDetached(unittest.TestCase): to_sign = b"this is some text.\nIt's something\n." similar = b"this is some text.\r\n.It's something\r\n." with gpg.core.Context() as ctx: - _, detached = crypto.detached_signature_for(to_sign, [ctx.get_key(FPR)]) + _, detached = crypto.detached_signature_for( + to_sign, [ctx.get_key(FPR)]) with self.assertRaises(GPGProblem): crypto.verify_detached(similar, detached) @@ -180,7 +184,8 @@ class TestValidateKey(unittest.TestCase): def test_encrypt(self): with self.assertRaises(GPGProblem) as caught: - crypto.validate_key(utilities.make_key(can_encrypt=False), encrypt=True) + crypto.validate_key( + utilities.make_key(can_encrypt=False), encrypt=True) self.assertEqual(caught.exception.code, GPGCode.KEY_CANNOT_ENCRYPT) @@ -286,7 +291,8 @@ class TestGetKey(unittest.TestCase): # once. with gpg.core.Context() as ctx: expected = ctx.get_key(FPR).uids[0].uid - actual = crypto.get_key(FPR, validate=True, encrypt=True, sign=True).uids[0].uid + actual = crypto.get_key( + FPR, validate=True, encrypt=True, sign=True).uids[0].uid self.assertEqual(expected, actual) def test_missing_key(self): @@ -306,7 +312,8 @@ class TestGetKey(unittest.TestCase): except GPGProblem as e: raise AssertionError(e) - @mock.patch('alot.crypto.check_uid_validity', mock.Mock(return_value=False)) + @mock.patch( + 'alot.crypto.check_uid_validity', mock.Mock(return_value=False)) def test_signed_only_false(self): with self.assertRaises(GPGProblem) as e: crypto.get_key(FPR, signed_only=True) @@ -370,7 +377,8 @@ class TestEncrypt(unittest.TestCase): enc_file = f.name self.addCleanup(os.unlink, enc_file) - dec = subprocess.check_output(['gpg', '--decrypt', enc_file], stderr=DEVNULL) + dec = subprocess.check_output( + ['gpg', '--decrypt', enc_file], stderr=DEVNULL) self.assertEqual(to_encrypt, dec) diff --git a/tests/db/utils_test.py b/tests/db/utils_test.py index 9013f5ce..25c3641d 100644 --- a/tests/db/utils_test.py +++ b/tests/db/utils_test.py @@ -385,7 +385,8 @@ class TestAddSignatureHeaders(unittest.TestCase): self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers) self.assertIn( - (utils.X_SIGNATURE_MESSAGE_HEADER, u'Untrusted: mocked'), mail.headers) + (utils.X_SIGNATURE_MESSAGE_HEADER, u'Untrusted: mocked'), + mail.headers) def test_unicode_as_bytes(self): mail = self.FakeMail() @@ -395,7 +396,8 @@ class TestAddSignatureHeaders(unittest.TestCase): self.assertIn((utils.X_SIGNATURE_VALID_HEADER, u'True'), mail.headers) self.assertIn( - (utils.X_SIGNATURE_MESSAGE_HEADER, u'Valid: AndreĆ”'), mail.headers) + (utils.X_SIGNATURE_MESSAGE_HEADER, u'Valid: AndreĆ”'), + mail.headers) def test_error_message_unicode(self): mail = self.check(mock.Mock(), mock.Mock(), u'error message') @@ -433,7 +435,8 @@ class TestMessageFromFile(TestCaseClassCleanup): with open(os.path.join(search_dir, each)) as f: ctx.op_import(f) - cls.keys = [ctx.get_key("DD19862809A7573A74058FF255937AFBB156245D")] + cls.keys = [ + ctx.get_key("DD19862809A7573A74058FF255937AFBB156245D")] def test_erase_alot_header_signature_valid(self): """Alot uses special headers for passing certain kinds of information, @@ -490,7 +493,8 @@ class TestMessageFromFile(TestCaseClassCleanup): m = self._make_signed() m = utils.message_from_file(io.StringIO(m.as_string())) # Don't test for valid/invalid since that might change - self.assertIn('ambig ', m[utils.X_SIGNATURE_MESSAGE_HEADER]) + self.assertIn( + 'ambig ', m[utils.X_SIGNATURE_MESSAGE_HEADER]) def test_signed_wrong_mimetype_second_payload(self): m = self._make_signed() @@ -601,7 +605,8 @@ class TestMessageFromFile(TestCaseClassCleanup): m = self._make_encrypted(True) m = utils.message_from_file(io.StringIO(m.as_string())) self.assertIn(utils.X_SIGNATURE_MESSAGE_HEADER, m) - self.assertIn('ambig ', m[utils.X_SIGNATURE_MESSAGE_HEADER]) + self.assertIn( + 'ambig ', m[utils.X_SIGNATURE_MESSAGE_HEADER]) # TODO: tests for the RFC 2440 style combined signed/encrypted blob @@ -728,7 +733,8 @@ class TestExtractBody(unittest.TestCase): @mock.patch('alot.db.utils.settings.mailcap_find_match', mock.Mock(return_value=(None, {'view': 'cat'}))) def test_prefer_html(self): - expected = 'This is an html email' + expected = ( + 'This is an html email') mail = self._make_mixed_plain_html() actual = utils.extract_body(mail) @@ -755,7 +761,8 @@ class TestExtractBody(unittest.TestCase): 'This is an html email', 'html')) actual = utils.extract_body(mail) - expected = 'This is an html email' + expected = ( + 'This is an html email') self.assertEqual(actual, expected) @@ -768,7 +775,8 @@ class TestExtractBody(unittest.TestCase): 'This is an html email', 'html')) actual = utils.extract_body(mail) - expected = 'This is an html email' + expected = ( + 'This is an html email') self.assertEqual(actual, expected) -- cgit v1.2.3