From 5028c081cbb1721af75e70c2f7e2662f47e05196 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 11 Feb 2021 18:52:14 -0800 Subject: [PATCH] python: Merge concatenated string literals that Black would uglify. Signed-off-by: Anders Kaseorg --- analytics/lib/fixtures.py | 3 +- .../check_postgresql_replication_lag | 3 +- scripts/purge-old-deployments | 7 ++--- tools/check-capitalization | 3 +- .../spiders/check_help_documentation.py | 3 +- tools/lib/provision.py | 3 +- tools/lib/provision_inner.py | 3 +- tools/lint | 21 +++++--------- tools/test-backend | 3 +- tools/tests/test_capitalization_checker.py | 6 ++-- zerver/forms.py | 4 +-- zerver/lib/outgoing_webhook.py | 3 +- zerver/lib/webhooks/git.py | 6 ++-- .../commands/generate_realm_creation_link.py | 6 ++-- zerver/management/commands/import.py | 3 +- zerver/management/commands/realm_domain.py | 3 +- .../commands/send_webhook_fixture_message.py | 6 ++-- .../management/commands/turn_off_digests.py | 3 +- zerver/tests/test_decorators.py | 12 +++----- zerver/tests/test_docs.py | 6 ++-- zerver/tests/test_markdown.py | 15 ++++------ zerver/tests/test_message_dict.py | 3 +- zerver/tests/test_message_edit.py | 10 ++----- zerver/tests/test_message_fetch.py | 6 ++-- zerver/tests/test_new_users.py | 9 ++---- zerver/tests/test_openapi.py | 3 +- zerver/tests/test_push_notifications.py | 28 ++++++------------- zerver/tests/test_reactions.py | 4 +-- zerver/tests/test_service_bot_system.py | 3 +- zerver/tests/test_signup.py | 9 ++---- zerver/views/realm_domains.py | 3 +- zerver/webhooks/basecamp/view.py | 3 +- zerver/webhooks/bitbucket2/view.py | 6 ++-- zerver/webhooks/clubhouse/view.py | 18 ++++-------- zerver/webhooks/front/tests.py | 3 +- zerver/webhooks/github/view.py | 3 +- zerver/webhooks/gocd/view.py | 11 ++++---- zerver/webhooks/librato/view.py | 3 +- zerver/webhooks/thinkst/view.py | 3 +- zerver/webhooks/travis/view.py | 9 +++--- zerver/worker/queue_processors.py | 3 +- zproject/backends.py | 3 +- 42 files changed, 91 insertions(+), 174 deletions(-) diff --git a/analytics/lib/fixtures.py b/analytics/lib/fixtures.py index be7de5f5fa..41f8c8dfa3 100644 --- a/analytics/lib/fixtures.py +++ b/analytics/lib/fixtures.py @@ -46,8 +46,7 @@ def generate_time_series_data(days: int=100, business_hours_base: float=10, else: raise AssertionError(f"Unknown frequency: {frequency}") if length < 2: - raise AssertionError("Must be generating at least 2 data points. " - f"Currently generating {length}") + raise AssertionError(f"Must be generating at least 2 data points. Currently generating {length}") growth_base = growth ** (1. / (length-1)) values_no_noise = [seasonality[i % len(seasonality)] * (growth_base**i) for i in range(length)] diff --git a/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag b/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag index a4834800d7..abdc6b8e70 100755 --- a/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag +++ b/puppet/zulip/files/nagios_plugins/zulip_postgresql/check_postgresql_replication_lag @@ -93,8 +93,7 @@ if replication_info: else: replication_info = run_sql_query( - 'client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn' - ' from pg_stat_replication' + 'client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn from pg_stat_replication' ) if replication_info == 0: report('CRITICAL', 'No replicas!') diff --git a/scripts/purge-old-deployments b/scripts/purge-old-deployments index c664453feb..6eee8fe525 100755 --- a/scripts/purge-old-deployments +++ b/scripts/purge-old-deployments @@ -17,16 +17,15 @@ def parse_args() -> argparse.Namespace: "examined and removed.") parser.add_argument( "--threshold", dest="threshold_days", type=int, default=14, - metavar="", help="Deployments older than " - "threshold days will be deleted. (defaults to 14)") + metavar="", + help="Deployments older than threshold days will be deleted. (defaults to 14)") parser.add_argument( "--dry-run", action="store_true", help="If specified then script will only print the deployments and " "caches that it will delete/keep back. It will not delete anything.") parser.add_argument( "--verbose", action="store_true", - help="If specified then script will print a detailed report " - "of what is going on.") + help="If specified then script will print a detailed report of what is going on.") args = parser.parse_args() args.verbose |= args.dry_run # Always print a detailed report in case of dry run. diff --git a/tools/check-capitalization b/tools/check-capitalization index 0c9370b703..82365b1fc6 100755 --- a/tools/check-capitalization +++ b/tools/check-capitalization @@ -22,8 +22,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--show-ignored', action='store_true', - help='Show strings that passed the check because they ' - 'contained ignored phrases.') + help='Show strings that passed the check because they contained ignored phrases.') parser.add_argument('--no-generate', action='store_true', help="Don't run makemessages command.") diff --git a/tools/documentation_crawler/documentation_crawler/spiders/check_help_documentation.py b/tools/documentation_crawler/documentation_crawler/spiders/check_help_documentation.py index 082001eaee..1b9f597619 100644 --- a/tools/documentation_crawler/documentation_crawler/spiders/check_help_documentation.py +++ b/tools/documentation_crawler/documentation_crawler/spiders/check_help_documentation.py @@ -30,8 +30,7 @@ class UnusedImagesLinterSpider(BaseDocumentationSpider): def closed(self, *args: Any, **kwargs: Any) -> None: unused_images = set(os.listdir(self.images_static_dir)) - self.static_images if unused_images: - exception_message = "The following images are not used in documentation " \ - "and can be removed: {}" + exception_message = "The following images are not used in documentation and can be removed: {}" self._set_error_state() unused_images_relatedpath = [ os.path.join(self.images_path, img) for img in unused_images] diff --git a/tools/lib/provision.py b/tools/lib/provision.py index dd6ee2f26e..f8a373aff0 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -79,8 +79,7 @@ if platform.architecture()[0] == '64bit': elif platform.architecture()[0] == '32bit': arch = "i386" else: - logging.critical("Only x86 is supported;" - " ask on chat.zulip.org if you want another architecture.") + logging.critical("Only x86 is supported; ask on chat.zulip.org if you want another architecture.") # Note: It's probably actually not hard to add additional # architectures. sys.exit(1) diff --git a/tools/lib/provision_inner.py b/tools/lib/provision_inner.py index e2e6c5d353..540695a757 100755 --- a/tools/lib/provision_inner.py +++ b/tools/lib/provision_inner.py @@ -110,8 +110,7 @@ def setup_bash_profile() -> None: BASH_PROFILE = BASH_PROFILES[0] DOT_PROFILE = BASH_PROFILES[2] - OLD_PROFILE_TEXT = "source /srv/zulip-py3-venv/bin/activate\n" + \ - "cd /srv/zulip\n" + OLD_PROFILE_TEXT = "source /srv/zulip-py3-venv/bin/activate\ncd /srv/zulip\n" if os.path.exists(DOT_PROFILE): try: diff --git a/tools/lint b/tools/lint index ecb82f5b36..03c1886346 100755 --- a/tools/lint +++ b/tools/lint @@ -50,25 +50,20 @@ def run() -> None: linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css'], fix_arg='--fix', - description="Standard CSS style and formatting linter " - "(config: stylelint.config.js)") + description="Standard CSS style and formatting linter (config: stylelint.config.js)") linter_config.external_linter('eslint', ['node', 'node_modules/.bin/eslint', '--max-warnings=0', '--cache', '--ext', '.js,.ts'], ['js', 'ts'], fix_arg='--fix', - description="Standard JavaScript style and formatting linter " - "(config: .eslintrc).") + description="Standard JavaScript style and formatting linter (config: .eslintrc).") linter_config.external_linter('puppet', ['puppet', 'parser', 'validate'], ['pp'], - description="Runs the puppet parser validator, " - "checking for syntax errors.") + description="Runs the puppet parser validator, checking for syntax errors.") linter_config.external_linter('puppet-lint', ['puppet-lint', '--fail-on-warnings', *PUPPET_CHECK_RULES_TO_EXCLUDE], ['pp'], fix_arg='--fix', - description="Standard puppet linter " - "(config: tools/linter_lib/exclude.py)") + description="Standard puppet linter (config: tools/linter_lib/exclude.py)") linter_config.external_linter('templates', ['tools/check-templates'], ['hbs', 'html'], - description="Custom linter checks whitespace formatting " - "of HTML templates", + description="Custom linter checks whitespace formatting of HTML templates", fix_arg='--fix') linter_config.external_linter('openapi', ['node', 'tools/check-openapi'], ['yaml'], description="Validates our OpenAPI/Swagger API documentation " @@ -89,8 +84,7 @@ def run() -> None: pass_targets=False, description="Shares duplicate packages in yarn.lock") linter_config.external_linter('gitlint', ['tools/commit-message-lint'], - description="Checks commit messages for common formatting errors " - "(config: .gitlint)") + description="Checks commit messages for common formatting errors (config: .gitlint)") linter_config.external_linter('isort', ['isort'], ['py'], description="Sorts Python import statements", check_arg=['--check-only', '--diff']) @@ -112,8 +106,7 @@ def run() -> None: "--dangerously-allow-arbitrary-code-execution-from-rules"] linter_config.external_linter('semgrep-py', [*semgrep_command, "--lang=python"], ['py'], fix_arg='--autofix', - description="Syntactic Grep (semgrep) Code Search Tool " - "(config: ./tools/semgrep.yml)") + description="Syntactic Grep (semgrep) Code Search Tool (config: ./tools/semgrep.yml)") linter_config.external_linter('thirdparty', ['tools/check-thirdparty'], description="Check docs/THIRDPARTY copyright file syntax") diff --git a/tools/test-backend b/tools/test-backend index a19463d22e..8e5353d32d 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -382,8 +382,7 @@ def main() -> None: TestRunner = get_runner(settings) if parallel > 1: - print("-- Running tests in parallel mode with {} " - "processes.".format(parallel), flush=True) + print(f"-- Running tests in parallel mode with {parallel} processes.", flush=True) else: print("-- Running tests in serial mode.", flush=True) diff --git a/tools/tests/test_capitalization_checker.py b/tools/tests/test_capitalization_checker.py index a03118132c..24a92bade8 100644 --- a/tools/tests/test_capitalization_checker.py +++ b/tools/tests/test_capitalization_checker.py @@ -7,11 +7,9 @@ from tools.lib.capitalization import check_capitalization, get_safe_text, is_cap class GetSafeTextTestCase(TestCase): def test_get_safe_text(self) -> None: - string = ('Messages in __page_params.product_name__ go to a ' - 'stream and have a topic.') + string = ('Messages in __page_params.product_name__ go to a stream and have a topic.') safe_text = get_safe_text(string) - self.assertEqual(safe_text, 'Messages in __page_params_product_name__ ' - 'go to a stream and have a topic.') + self.assertEqual(safe_text, 'Messages in __page_params_product_name__ go to a stream and have a topic.') string = "Zulip Zulip. Zulip some text!" safe_text = get_safe_text(string) diff --git a/zerver/forms.py b/zerver/forms.py index 82771dc8d0..3f854cabb8 100644 --- a/zerver/forms.py +++ b/zerver/forms.py @@ -156,9 +156,7 @@ class HomepageForm(forms.Form): from_multiuse_invite = self.from_multiuse_invite if realm is None: - raise ValidationError(_("The organization you are trying to " - "join using {email} does not " - "exist.").format(email=email)) + raise ValidationError(_("The organization you are trying to join using {email} does not exist.").format(email=email)) if not from_multiuse_invite and realm.invite_required: raise ValidationError(_("Please request an invite for {email} " diff --git a/zerver/lib/outgoing_webhook.py b/zerver/lib/outgoing_webhook.py index 550123a79d..f6150eca72 100644 --- a/zerver/lib/outgoing_webhook.py +++ b/zerver/lib/outgoing_webhook.py @@ -236,8 +236,7 @@ def notify_bot_owner(event: Dict[str, Any], if status_code: notification_message += f"\nThe webhook got a response with status code *{status_code}*." if response_content: - notification_message += "\nThe response contains the following payload:\n" \ - f"```\n{response_content!r}\n```" + notification_message += f"\nThe response contains the following payload:\n```\n{response_content!r}\n```" if exception: notification_message += "\nWhen trying to send a request to the webhook service, an exception " \ f"of type {type(exception).__name__} occurred:\n```\n{exception}\n```" diff --git a/zerver/lib/webhooks/git.py b/zerver/lib/webhooks/git.py index a4983cc6bb..bc1aa1fd56 100644 --- a/zerver/lib/webhooks/git.py +++ b/zerver/lib/webhooks/git.py @@ -26,13 +26,11 @@ PUSH_COMMITS_MESSAGE_TEMPLATE_WITHOUT_COMMITTERS = PUSH_COMMITS_BASE + """ {commits_data} """ PUSH_DELETE_BRANCH_MESSAGE_TEMPLATE = "{user_name} [deleted]({compare_url}) the branch {branch_name}." -PUSH_LOCAL_BRANCH_WITHOUT_COMMITS_MESSAGE_TEMPLATE = ("{user_name} [pushed]({compare_url}) " - "the branch {branch_name}.") +PUSH_LOCAL_BRANCH_WITHOUT_COMMITS_MESSAGE_TEMPLATE = "{user_name} [pushed]({compare_url}) the branch {branch_name}." PUSH_COMMITS_MESSAGE_EXTENSION = "Commits by {}" PUSH_COMMITTERS_LIMIT_INFO = 3 -FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = ("{user_name} [force pushed]({url}) " - "to branch {branch_name}. Head is now {head}.") +FORCE_PUSH_COMMITS_MESSAGE_TEMPLATE = "{user_name} [force pushed]({url}) to branch {branch_name}. Head is now {head}." CREATE_BRANCH_MESSAGE_TEMPLATE = "{user_name} created [{branch_name}]({url}) branch." CREATE_BRANCH_WITHOUT_URL_MESSAGE_TEMPLATE = "{user_name} created {branch_name} branch." REMOVE_BRANCH_MESSAGE_TEMPLATE = "{user_name} deleted branch {branch_name}." diff --git a/zerver/management/commands/generate_realm_creation_link.py b/zerver/management/commands/generate_realm_creation_link.py index d9fa493356..27faaab4bf 100644 --- a/zerver/management/commands/generate_realm_creation_link.py +++ b/zerver/management/commands/generate_realm_creation_link.py @@ -21,12 +21,10 @@ class Command(ZulipBaseCommand): # first check if the db has been initialized Realm.objects.first() except ProgrammingError: - raise CommandError("The Zulip database does not appear to exist. " - "Have you run initialize-database?") + raise CommandError("The Zulip database does not appear to exist. Have you run initialize-database?") url = generate_realm_creation_url(by_admin=True) - self.stdout.write(self.style.SUCCESS("Please visit the following " - "secure single-use link to register your ")) + self.stdout.write(self.style.SUCCESS("Please visit the following secure single-use link to register your ")) self.stdout.write(self.style.SUCCESS("new Zulip organization:\033[0m")) self.stdout.write("") self.stdout.write(self.style.SUCCESS(f" \033[1;92m{url}\033[0m")) diff --git a/zerver/management/commands/import.py b/zerver/management/commands/import.py index 0029e2e4d9..4652d7047b 100644 --- a/zerver/management/commands/import.py +++ b/zerver/management/commands/import.py @@ -76,8 +76,7 @@ import a database dump from one or more JSON files.""" if not os.path.exists(path): raise CommandError(f"Directory not found: '{path}'") if not os.path.isdir(path): - raise CommandError("Export file should be folder; if it's a " - "tarball, please unpack it first.") + raise CommandError("Export file should be folder; if it's a tarball, please unpack it first.") paths.append(path) for path in paths: diff --git a/zerver/management/commands/realm_domain.py b/zerver/management/commands/realm_domain.py index 54dc88584a..21ff07f564 100644 --- a/zerver/management/commands/realm_domain.py +++ b/zerver/management/commands/realm_domain.py @@ -47,8 +47,7 @@ class Command(ZulipBaseCommand): allow_subdomains=options["allow_subdomains"]) sys.exit(0) except IntegrityError: - raise CommandError(f"The domain {domain} is already a part " - "of your organization.") + raise CommandError(f"The domain {domain} is already a part of your organization.") elif options["op"] == "remove": try: RealmDomain.objects.get(realm=realm, domain=domain).delete() diff --git a/zerver/management/commands/send_webhook_fixture_message.py b/zerver/management/commands/send_webhook_fixture_message.py index b6ea82d1e3..e7a7d6ef1e 100644 --- a/zerver/management/commands/send_webhook_fixture_message.py +++ b/zerver/management/commands/send_webhook_fixture_message.py @@ -36,12 +36,10 @@ approach shown above. 'into Zulip') parser.add_argument('-u', '--url', - help='The URL on your Zulip server that you want ' - 'to post the fixture to') + help='The URL on your Zulip server that you want to post the fixture to') parser.add_argument('-H', '--custom-headers', - help='The headers you want to provide along with ' - 'your mock request to Zulip.') + help='The headers you want to provide along with your mock request to Zulip.') self.add_realm_args(parser, help="Specify which realm/subdomain to connect to; default is zulip") diff --git a/zerver/management/commands/turn_off_digests.py b/zerver/management/commands/turn_off_digests.py index 1f308a88f1..8e7e3b3c93 100644 --- a/zerver/management/commands/turn_off_digests.py +++ b/zerver/management/commands/turn_off_digests.py @@ -11,8 +11,7 @@ class Command(ZulipBaseCommand): self.add_realm_args(parser) self.add_user_list_args(parser, - help='Turn off digests for this comma-separated ' - 'list of email addresses.', + help='Turn off digests for this comma-separated list of email addresses.', all_users_help="Turn off digests for everyone in realm.") def handle(self, **options: str) -> None: diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 2a77fbe261..2500f8fc0a 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -1486,8 +1486,7 @@ class TestAuthenticatedJsonPostViewDecorator(ZulipTestCase): with self.assertLogs(level="WARNING") as m, \ mock.patch('zerver.decorator.get_subdomain', return_value=''): self.assert_json_error_contains(self._do_test(user), - "Account is not associated with this " - "subdomain") + "Account is not associated with this subdomain") self.assertEqual( m.output, ["WARNING:root:User {} ({}) attempted to access API on wrong subdomain ({})".format(email, 'zulip', ''), @@ -1497,8 +1496,7 @@ class TestAuthenticatedJsonPostViewDecorator(ZulipTestCase): with self.assertLogs(level="WARNING") as m, \ mock.patch('zerver.decorator.get_subdomain', return_value='acme'): self.assert_json_error_contains(self._do_test(user), - "Account is not associated with this " - "subdomain") + "Account is not associated with this subdomain") self.assertEqual( m.output, ["WARNING:root:User {} ({}) attempted to access API on wrong subdomain ({})".format(email, 'zulip', 'acme'), @@ -1545,8 +1543,7 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase): with self.assertLogs(level="WARNING") as m, \ mock.patch('zerver.decorator.get_subdomain', return_value=''): self.assert_json_error_contains(self._do_test(email), - "Account is not associated with this " - "subdomain") + "Account is not associated with this subdomain") self.assertEqual( m.output, ["WARNING:root:User {} ({}) attempted to access API on wrong subdomain ({})".format(email, "zulip", "")] @@ -1555,8 +1552,7 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase): with self.assertLogs(level="WARNING") as m, \ mock.patch('zerver.decorator.get_subdomain', return_value='acme'): self.assert_json_error_contains(self._do_test(email), - "Account is not associated with this " - "subdomain") + "Account is not associated with this subdomain") self.assertEqual( m.output, ["WARNING:root:User {} ({}) attempted to access API on wrong subdomain ({})".format(email, "zulip", "acme")] diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 2a798d01a5..fead18c1c1 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -490,8 +490,7 @@ class PrivacyTermsTest(ZulipTestCase): response) def test_custom_terms_of_service_template(self) -> None: - not_configured_message = 'This installation of Zulip does not have a configured ' \ - 'terms of service' + not_configured_message = 'This installation of Zulip does not have a configured terms of service' with self.settings(TERMS_OF_SERVICE=None): response = self.client_get('/terms/') self.assert_in_success_response([not_configured_message], response) @@ -501,8 +500,7 @@ class PrivacyTermsTest(ZulipTestCase): self.assert_not_in_success_response([not_configured_message], response) def test_custom_privacy_policy_template(self) -> None: - not_configured_message = 'This installation of Zulip does not have a configured ' \ - 'privacy policy' + not_configured_message = 'This installation of Zulip does not have a configured privacy policy' with self.settings(PRIVACY_POLICY=None): response = self.client_get('/privacy/') self.assert_in_success_response([not_configured_message], response) diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index f78c3ee27e..d5f181985a 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -1009,8 +1009,7 @@ class MarkdownTest(ZulipTestCase): realm_filter.save() self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') msg = Message(sender=self.example_user('othello')) msg.set_topic_name("#444") @@ -1679,8 +1678,7 @@ class MarkdownTest(ZulipTestCase): realm_filter.save() self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') # Create a user that potentially interferes with the pattern. test_user = create_user( email='atomic@example.com', @@ -1736,8 +1734,7 @@ class MarkdownTest(ZulipTestCase): realm_filter.save() self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') # Create a user-group that potentially interferes with the pattern. user_id = user_profile.id user_group = self.create_user_group_for_test('support #123') @@ -1908,8 +1905,7 @@ class MarkdownTest(ZulipTestCase): realm_filter.save() self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') # Create a topic link that potentially interferes with the pattern. denmark = get_stream('Denmark', realm) msg = Message(sender=sender_user_profile, sending_client=get_client("test")) @@ -1974,8 +1970,7 @@ class MarkdownTest(ZulipTestCase): realm_filter.save() self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') # Create a stream that potentially interferes with the pattern. stream = Stream.objects.create(name='Stream #1234', realm=realm) msg = Message(sender=sender_user_profile, sending_client=get_client("test")) diff --git a/zerver/tests/test_message_dict.py b/zerver/tests/test_message_dict.py index e66d58ebf2..20232fa28e 100644 --- a/zerver/tests/test_message_dict.py +++ b/zerver/tests/test_message_dict.py @@ -256,8 +256,7 @@ class MessageDictTest(ZulipTestCase): url_format_string=url_format_string) self.assertEqual( realm_filter.__str__(), - '[0-9]{2,8})' - ' https://trac.example.com/ticket/%(id)s>') + '[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>') def get_message(sender: UserProfile) -> Message: msg_id = self.send_stream_message(sender, 'Denmark', 'hello world', topic_name, diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py index b4eb3ca9dd..edc1a68cd7 100644 --- a/zerver/tests/test_message_edit.py +++ b/zerver/tests/test_message_edit.py @@ -293,9 +293,7 @@ class EditMessageTest(ZulipTestCase): self.example_user("hamlet"), "Scotland", topic_name="editing", - content=('content before edit, line 1\n' - '\n' - 'content before edit, line 3')) + content='content before edit, line 1\n\ncontent before edit, line 3') new_content_2 = ('content before edit, line 1\n' 'content after edit, line 2\n' 'content before edit, line 3') @@ -310,8 +308,7 @@ class EditMessageTest(ZulipTestCase): message_history_2 = json_response_2['message_history'] self.assertEqual(message_history_2[0]['rendered_content'], - ('

content before edit, line 1

\n' - '

content before edit, line 3

')) + '

content before edit, line 1

\n

content before edit, line 3

') self.assertEqual(message_history_2[1]['rendered_content'], ('

content before edit, line 1
\n' 'content after edit, line 2
\n' @@ -321,8 +318,7 @@ class EditMessageTest(ZulipTestCase): 'content after edit, line 2
' 'content
before edit, line 3

')) self.assertEqual(message_history_2[1]['prev_rendered_content'], - ('

content before edit, line 1

\n' - '

content before edit, line 3

')) + '

content before edit, line 1

\n

content before edit, line 3

') def test_edit_link(self) -> None: # Link editing diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index b301f32d8e..dd6017ca9d 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -3248,9 +3248,9 @@ class MessageHasKeywordsTest(ZulipTestCase): # This message should claim attachments 1 only because attachment 2 # is not being parsed as a link by Markdown. - body = ("Some files here ...[zulip.txt]({})" + - "{}.... Some more...." + - "{}").format(dummy_urls[0], dummy_urls[1], dummy_urls[1]) + body = (f"Some files here ...[zulip.txt]({dummy_urls[0]})" + f"{dummy_urls[1]}.... Some more...." + f"{dummy_urls[1]}") self.send_stream_message(user_profile, "Denmark", body, "test") assert_attachment_claimed(dummy_path_ids[0], True) assert_attachment_claimed(dummy_path_ids[1], False) diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index d170ec1c79..071955ace0 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -123,12 +123,9 @@ class TestBrowserAndOsUserAgentStrings(ZulipTestCase): 'Chrome/54.0.2840.59 Safari/537.36', 'Chrome', 'Linux'), ('mozilla/5.0 (windows nt 6.1; win64; x64) applewebkit/537.36 (khtml, like gecko) ' + 'chrome/56.0.2924.87 safari/537.36', 'Chrome', 'Windows'), - ('mozilla/5.0 (windows nt 6.1; wow64; rv:51.0) ' + - 'gecko/20100101 firefox/51.0', 'Firefox', 'Windows'), - ('mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) ' + - 'like gecko', 'Internet Explorer', 'Windows'), - ('Mozilla/5.0 (Android; Mobile; rv:27.0) ' + - 'Gecko/27.0 Firefox/27.0', 'Firefox', 'Android'), + ('mozilla/5.0 (windows nt 6.1; wow64; rv:51.0) gecko/20100101 firefox/51.0', 'Firefox', 'Windows'), + ('mozilla/5.0 (windows nt 6.1; wow64; trident/7.0; rv:11.0) like gecko', 'Internet Explorer', 'Windows'), + ('Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0', 'Firefox', 'Android'), ('Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) ' 'AppleWebKit/602.1.50 (KHTML, like Gecko) ' 'CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1', 'Chrome', 'iOS'), diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.py index d4561ac971..7a3294c3e2 100644 --- a/zerver/tests/test_openapi.py +++ b/zerver/tests/test_openapi.py @@ -102,8 +102,7 @@ class OpenAPIToolsTest(ZulipTestCase): def test_validate_against_openapi_schema(self) -> None: with self.assertRaises(ValidationError, - msg=("Additional properties are not" + - " allowed ('foo' was unexpected)")): + msg="Additional properties are not allowed ('foo' was unexpected)"): bad_content: Dict[str, object] = { 'msg': '', 'result': 'success', diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 8584391e6a..cbb33a902d 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -923,8 +923,7 @@ class HandlePushNotificationTest(PushNotificationTest): return_value={'apns': True}), \ mock.patch('zerver.lib.push_notifications.get_message_payload_gcm', return_value=({'gcm': True}, {})), \ - mock.patch('zerver.lib.push_notifications' - '.send_notifications_to_bouncer') as mock_send: + mock.patch('zerver.lib.push_notifications.send_notifications_to_bouncer') as mock_send: handle_push_notification(user_profile.id, missed_message) mock_send.assert_called_with(user_profile.id, {'apns': True}, @@ -957,10 +956,8 @@ class HandlePushNotificationTest(PushNotificationTest): return_value={'apns': True}), \ mock.patch('zerver.lib.push_notifications.get_message_payload_gcm', return_value=({'gcm': True}, {})), \ - mock.patch('zerver.lib.push_notifications' - '.send_apple_push_notification') as mock_send_apple, \ - mock.patch('zerver.lib.push_notifications' - '.send_android_push_notification') as mock_send_android, \ + mock.patch('zerver.lib.push_notifications.send_apple_push_notification') as mock_send_apple, \ + mock.patch('zerver.lib.push_notifications.send_android_push_notification') as mock_send_android, \ mock.patch('zerver.lib.push_notifications.push_notifications_enabled', return_value = True) as mock_push_notifications: handle_push_notification(self.user_profile.id, missed_message) @@ -980,8 +977,7 @@ class HandlePushNotificationTest(PushNotificationTest): ) with self.settings(PUSH_NOTIFICATION_BOUNCER_URL=True), \ - mock.patch('zerver.lib.push_notifications' - '.send_notifications_to_bouncer') as mock_send: + mock.patch('zerver.lib.push_notifications.send_notifications_to_bouncer') as mock_send: handle_remove_push_notification(user_profile.id, [message.id]) mock_send.assert_called_with( user_profile.id, @@ -1030,10 +1026,8 @@ class HandlePushNotificationTest(PushNotificationTest): PushDeviceToken.objects.filter(user=self.user_profile, kind=PushDeviceToken.APNS)) - with mock.patch('zerver.lib.push_notifications' - '.send_android_push_notification') as mock_send_android, \ - mock.patch('zerver.lib.push_notifications' - '.send_apple_push_notification') as mock_send_apple: + with mock.patch('zerver.lib.push_notifications.send_android_push_notification') as mock_send_android, \ + mock.patch('zerver.lib.push_notifications.send_apple_push_notification') as mock_send_apple: handle_remove_push_notification(self.user_profile.id, [message.id]) mock_send_android.assert_called_with( android_devices, @@ -1116,10 +1110,8 @@ class HandlePushNotificationTest(PushNotificationTest): return_value={'apns': True}), \ mock.patch('zerver.lib.push_notifications.get_message_payload_gcm', return_value=({'gcm': True}, {})), \ - mock.patch('zerver.lib.push_notifications' - '.send_apple_push_notification') as mock_send_apple, \ - mock.patch('zerver.lib.push_notifications' - '.send_android_push_notification') as mock_send_android, \ + mock.patch('zerver.lib.push_notifications.send_apple_push_notification') as mock_send_apple, \ + mock.patch('zerver.lib.push_notifications.send_android_push_notification') as mock_send_android, \ mock.patch('zerver.lib.push_notifications.logger.error') as mock_logger, \ mock.patch('zerver.lib.push_notifications.push_notifications_enabled', return_value = True) as mock_push_notifications: handle_push_notification(self.user_profile.id, missed_message) @@ -1914,9 +1906,7 @@ class GCMSendTest(PushNotificationTest): data = self.get_gcm_data() send_android_push_notification_to_user(self.user_profile, data, {}) - msg = ("GCM: Got canonical ref %s " - "replacing %s but new ID not " - "registered! Updating.") + msg = "GCM: Got canonical ref %s replacing %s but new ID not registered! Updating." mock_warning.assert_called_once_with(msg, t2, t1) self.assertEqual(get_count('1111'), 0) diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py index 7b13a44ea7..12a3aea697 100644 --- a/zerver/tests/test_reactions.py +++ b/zerver/tests/test_reactions.py @@ -646,9 +646,7 @@ class DefaultEmojiReactionTests(EmojiReactionBase): def test_delete_insufficient_arguments_reaction(self) -> None: result = self.delete_reaction({}) - self.assert_json_error(result, 'At least one of the following ' - 'arguments must be present: emoji_name, ' - 'emoji_code') + self.assert_json_error(result, 'At least one of the following arguments must be present: emoji_name, emoji_code') def test_delete_non_existing_emoji_reaction(self) -> None: reaction_info = { diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.py index 965cdefb03..23d2457893 100644 --- a/zerver/tests/test_service_bot_system.py +++ b/zerver/tests/test_service_bot_system.py @@ -217,8 +217,7 @@ class TestServiceBotStateHandler(ZulipTestCase): key = 'capacity-filling entry' storage.put(key, 'x' * (settings.USER_STATE_SIZE_LIMIT - len(key))) - with self.assertRaisesMessage(StateError, "Request exceeds storage limit by 32 characters. " - "The limit is 100 characters."): + with self.assertRaisesMessage(StateError, "Request exceeds storage limit by 32 characters. The limit is 100 characters."): storage.put('too much data', 'a few bits too long') second_storage = StateHandler(self.second_bot_profile) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index cc7df831c7..659849a969 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -1603,8 +1603,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!" email_change_key = email_change_url.split('/')[-1] url = '/accounts/do_confirm/' + email_change_key result = self.client_get(url) - self.assert_in_success_response(["Whoops. We couldn't find your " - "confirmation link in the system."], result) + self.assert_in_success_response(["Whoops. We couldn't find your confirmation link in the system."], result) def test_confirmation_expired(self) -> None: email = self.nonreg_email("alice") @@ -1621,8 +1620,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!" target_url = '/' + url.split('/', 3)[3] result = self.client_get(target_url) - self.assert_in_success_response(["Whoops. The confirmation link has expired " - "or been deactivated."], result) + self.assert_in_success_response(["Whoops. The confirmation link has expired or been deactivated."], result) def test_send_more_than_one_invite_to_same_user(self) -> None: self.user_profile = self.example_user('iago') @@ -3281,8 +3279,7 @@ class UserSignUpTest(InviteUserBase): def test_failed_signup_due_to_nonexistent_realm(self) -> None: email = 'user@acme.com' form = HomepageForm({'email': email}, realm=None) - self.assertIn("organization you are trying to join using {} does " - "not exist".format(email), form.errors['email'][0]) + self.assertIn(f"organization you are trying to join using {email} does not exist", form.errors['email'][0]) def test_access_signup_page_in_root_domain_without_realm(self) -> None: result = self.client_get('/register', subdomain="", follow=True) diff --git a/zerver/views/realm_domains.py b/zerver/views/realm_domains.py index a99ed4addd..8a588fec1b 100644 --- a/zerver/views/realm_domains.py +++ b/zerver/views/realm_domains.py @@ -26,8 +26,7 @@ def create_realm_domain(request: HttpRequest, user_profile: UserProfile, except ValidationError as e: return json_error(_('Invalid domain: {}').format(e.messages[0])) if RealmDomain.objects.filter(realm=user_profile.realm, domain=domain).exists(): - return json_error(_("The domain {domain} is already" - " a part of your organization.").format(domain=domain)) + return json_error(_("The domain {domain} is already a part of your organization.").format(domain=domain)) realm_domain = do_add_realm_domain(user_profile.realm, domain, allow_subdomains) return json_success({'new_domain': [realm_domain.id, realm_domain.domain]}) diff --git a/zerver/webhooks/basecamp/view.py b/zerver/webhooks/basecamp/view.py index a08291d1f8..b24de5b882 100644 --- a/zerver/webhooks/basecamp/view.py +++ b/zerver/webhooks/basecamp/view.py @@ -17,8 +17,7 @@ DOCUMENT_TEMPLATE = "{user_name} {verb} the document [{title}]({url})" QUESTION_TEMPLATE = "{user_name} {verb} the question [{title}]({url})" QUESTIONS_ANSWER_TEMPLATE = ("{user_name} {verb} the [answer]({answer_url}) " + "of the question [{question_title}]({question_url})") -COMMENT_TEMPLATE = ("{user_name} {verb} the [comment]({answer_url}) " - "of the task [{task_title}]({task_url})") +COMMENT_TEMPLATE = "{user_name} {verb} the [comment]({answer_url}) of the task [{task_title}]({task_url})" MESSAGE_TEMPLATE = "{user_name} {verb} the message [{title}]({url})" TODO_LIST_TEMPLATE = "{user_name} {verb} the todo list [{title}]({url})" TODO_TEMPLATE = "{user_name} {verb} the todo task [{title}]({url})" diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index abb025f7ba..85b68bd658 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -31,10 +31,8 @@ from zerver.models import UserProfile BITBUCKET_TOPIC_TEMPLATE = '{repository_name}' BITBUCKET_FORK_BODY = "{actor} forked the repository into [{fork_name}]({fork_url})." -BITBUCKET_COMMIT_STATUS_CHANGED_BODY = ('[System {key}]({system_url}) changed status of' - ' {commit_info} to {status}.') -BITBUCKET_REPO_UPDATED_CHANGED = ('{actor} changed the {change} of the **{repo_name}**' - ' repo from **{old}** to **{new}**') +BITBUCKET_COMMIT_STATUS_CHANGED_BODY = '[System {key}]({system_url}) changed status of {commit_info} to {status}.' +BITBUCKET_REPO_UPDATED_CHANGED = '{actor} changed the {change} of the **{repo_name}** repo from **{old}** to **{new}**' BITBUCKET_REPO_UPDATED_ADDED = '{actor} changed the {change} of the **{repo_name}** repo to **{new}**' PULL_REQUEST_SUPPORTED_ACTIONS = [ diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index 7be9398689..04a57624e2 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -23,23 +23,17 @@ NAME_CHANGED_TEMPLATE = ("The name of the {entity} {name_template} was changed f ARCHIVED_TEMPLATE = "The {entity} {name_template} was {action}." STORY_TASK_TEMPLATE = "Task **{task_description}** was {action} the story {name_template}." STORY_TASK_COMPLETED_TEMPLATE = "Task **{task_description}** ({name_template}) was completed. :tada:" -STORY_ADDED_REMOVED_EPIC_TEMPLATE = ("The story {story_name_template} was {action} the" - " epic {epic_name_template}.") -STORY_EPIC_CHANGED_TEMPLATE = ("The story {story_name_template} was moved from {old_epic_name_template}" - " to {new_epic_name_template}.") +STORY_ADDED_REMOVED_EPIC_TEMPLATE = "The story {story_name_template} was {action} the epic {epic_name_template}." +STORY_EPIC_CHANGED_TEMPLATE = "The story {story_name_template} was moved from {old_epic_name_template} to {new_epic_name_template}." STORY_ESTIMATE_TEMPLATE = "The estimate for the story {story_name_template} was set to {estimate}." FILE_ATTACHMENT_TEMPLATE = "A {type} attachment `{file_name}` was added to the story {name_template}." STORY_LABEL_TEMPLATE = "The label **{label_name}** was added to the story {name_template}." -STORY_UPDATE_PROJECT_TEMPLATE = ("The story {name_template} was moved from" - " the **{old}** project to **{new}**.") -STORY_UPDATE_TYPE_TEMPLATE = ("The type of the story {name_template} was changed" - " from **{old_type}** to **{new_type}**.") +STORY_UPDATE_PROJECT_TEMPLATE = "The story {name_template} was moved from the **{old}** project to **{new}**." +STORY_UPDATE_TYPE_TEMPLATE = "The type of the story {name_template} was changed from **{old_type}** to **{new_type}**." DELETE_TEMPLATE = "The {entity_type} **{name}** was deleted." STORY_UPDATE_OWNER_TEMPLATE = "New owner added to the story {name_template}." -STORY_GITHUB_PR_TEMPLATE = ("New GitHub PR [#{name}]({url}) opened for story" - " {name_template} ({old} -> {new}).") -STORY_GITHUB_BRANCH_TEMPLATE = ("New GitHub branch [{name}]({url})" - " associated with story {name_template} ({old} -> {new}).") +STORY_GITHUB_PR_TEMPLATE = "New GitHub PR [#{name}]({url}) opened for story {name_template} ({old} -> {new})." +STORY_GITHUB_BRANCH_TEMPLATE = "New GitHub branch [{name}]({url}) associated with story {name_template} ({old} -> {new})." def get_action_with_primary_id(payload: Dict[str, Any]) -> Dict[str, Any]: diff --git a/zerver/webhooks/front/tests.py b/zerver/webhooks/front/tests.py index 8b06dc62ba..a68a6e7331 100644 --- a/zerver/webhooks/front/tests.py +++ b/zerver/webhooks/front/tests.py @@ -180,8 +180,7 @@ class FrontHookTests(WebhookTestCase): def test_comment(self) -> None: expected_topic = 'cnv_keocka' - expected_message = "**Bender Rodriguez** left a comment:\n" \ - "```quote\nSure.\n```" + expected_message = "**Bender Rodriguez** left a comment:\n```quote\nSure.\n```" self.check_webhook( "comment", diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 78aa0abda9..d95bdc63e5 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -414,8 +414,7 @@ def get_pull_request_review_requested_body(helper: Helper) -> str: pr_number = payload['pull_request']['number'] pr_url = payload['pull_request']['html_url'] message = "**{sender}** requested {reviewers} for a review on [PR #{pr_number}]({pr_url})." - message_with_title = ("**{sender}** requested {reviewers} for a review on " - "[PR #{pr_number} {title}]({pr_url}).") + message_with_title = "**{sender}** requested {reviewers} for a review on [PR #{pr_number} {title}]({pr_url})." body = message_with_title if include_title else message all_reviewers = [] diff --git a/zerver/webhooks/gocd/view.py b/zerver/webhooks/gocd/view.py index b15558d335..274c0e3dbf 100644 --- a/zerver/webhooks/gocd/view.py +++ b/zerver/webhooks/gocd/view.py @@ -11,12 +11,11 @@ from zerver.lib.response import json_success from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile -MESSAGE_TEMPLATE = ( - 'Author: {}\n' - 'Build status: {} {}\n' - 'Details: [build log]({})\n' - 'Comment: {}' -) +MESSAGE_TEMPLATE = """\ +Author: {} +Build status: {} {} +Details: [build log]({}) +Comment: {}""" @webhook_view('Gocd') @has_request_variables diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py index 4db372a407..1969156940 100644 --- a/zerver/webhooks/librato/view.py +++ b/zerver/webhooks/librato/view.py @@ -130,8 +130,7 @@ class LibratoWebhookHandler(LibratoWebhookParser): condition: Dict[str, Any]) -> str: summary_function, threshold, condition_type, duration = self.parse_condition(condition) metric_name, recorded_at = self.parse_violation(violation) - metric_condition_template = ("\n * Metric `{metric_name}`, {summary_function} " - "was {condition_type} {threshold}") + metric_condition_template = "\n * Metric `{metric_name}`, {summary_function} was {condition_type} {threshold}" content = metric_condition_template.format( metric_name=metric_name, summary_function=summary_function, condition_type=condition_type, threshold=threshold) diff --git a/zerver/webhooks/thinkst/view.py b/zerver/webhooks/thinkst/view.py index 1315c940b6..e205f84884 100644 --- a/zerver/webhooks/thinkst/view.py +++ b/zerver/webhooks/thinkst/view.py @@ -62,8 +62,7 @@ def body(message: Dict[str, Any]) -> str: title = canary_kind(message).title() name = canary_name(message) - body = (f"**:alert: {title} *{name}* has been triggered!**\n\n" - f"{message['Intro']}\n\n") + body = f"**:alert: {title} *{name}* has been triggered!**\n\n{message['Intro']}\n\n" if 'IncidentHash' in message: body += f"**Incident Id:** `{message['IncidentHash']}`\n" diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.py index c393e37368..47bae289ea 100644 --- a/zerver/webhooks/travis/view.py +++ b/zerver/webhooks/travis/view.py @@ -14,11 +14,10 @@ GOOD_STATUSES = ['Passed', 'Fixed'] BAD_STATUSES = ['Failed', 'Broken', 'Still Failing', 'Errored', 'Canceled'] PENDING_STATUSES = ['Pending'] -MESSAGE_TEMPLATE = ( - 'Author: {}\n' - 'Build status: {} {}\n' - 'Details: [changes]({}), [build log]({})' -) +MESSAGE_TEMPLATE = """\ +Author: {} +Build status: {} {} +Details: [changes]({}), [build log]({})""" @webhook_view('Travis') @has_request_variables diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 1c16143219..6e608261c3 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -635,8 +635,7 @@ class MirrorWorker(QueueProcessingWorker): try: rate_limit_mirror_by_realm(recipient_realm) except RateLimited: - logger.warning("MirrorWorker: Rejecting an email from: %s " - "to realm: %s - rate limited.", + logger.warning("MirrorWorker: Rejecting an email from: %s to realm: %s - rate limited.", msg['From'], recipient_realm.name) return diff --git a/zproject/backends.py b/zproject/backends.py index 2d1d746c01..e83bc6b210 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -987,8 +987,7 @@ class ExternalAuthResult: data_dict = {} if login_token is not None: - assert (not data_dict) and (user_profile is None), ("Passing in data_dict or user_profile " + - "with login_token is disallowed.") + assert (not data_dict) and (user_profile is None), "Passing in data_dict or user_profile with login_token is disallowed." self.instantiate_with_token(login_token, delete_stored_data) else: self.data_dict = data_dict.copy()