From 55544214d386c23fa45e75973f5c7233f30aa04d Mon Sep 17 00:00:00 2001 From: wbanks Date: Tue, 10 Sep 2024 14:07:24 -0400 Subject: [PATCH] Formatting --- .../clients/redis/bounce_rate.py | 3 +- notifications_utils/formatters.py | 12 ++++---- notifications_utils/sanitise_text.py | 4 +-- notifications_utils/strftime_codes.py | 28 +++++++++---------- tests/test_formatters.py | 12 ++++---- tests/test_recipient_csv.py | 12 ++++---- tests/test_recipient_validation.py | 4 +-- tests/test_sanitise_text.py | 2 +- tests/test_template_types.py | 8 +++--- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/notifications_utils/clients/redis/bounce_rate.py b/notifications_utils/clients/redis/bounce_rate.py index 845108aa..526d4aa7 100644 --- a/notifications_utils/clients/redis/bounce_rate.py +++ b/notifications_utils/clients/redis/bounce_rate.py @@ -1,4 +1,5 @@ -"""This module is used to calculate the bounce rate for a service. It uses Redis to store the total number of hard bounces """ +"""This module is used to calculate the bounce rate for a service. It uses Redis to store the total number of hard bounces""" + from datetime import datetime from notifications_utils.clients.redis.redis_client import RedisClient diff --git a/notifications_utils/formatters.py b/notifications_utils/formatters.py index cb83e987..79ee215f 100644 --- a/notifications_utils/formatters.py +++ b/notifications_utils/formatters.py @@ -16,12 +16,12 @@ LINK_STYLE = "word-wrap: break-word;" OBSCURE_WHITESPACE = ( - "\u180E" # Mongolian vowel separator - "\u200B" # zero width space - "\u200C" # zero width non-joiner - "\u200D" # zero width joiner + "\u180e" # Mongolian vowel separator + "\u200b" # zero width space + "\u200c" # zero width non-joiner + "\u200d" # zero width joiner "\u2060" # word joiner - "\uFEFF" # zero width non-breaking space + "\ufeff" # zero width non-breaking space ) EMAIL_P_OPEN_TAG = '

' @@ -85,7 +85,7 @@ def unlink_govuk_escaped(message): - return re.sub(govuk_not_a_link, r"\1" + ".\u200B" + r"\2", message) # Unicode zero-width space + return re.sub(govuk_not_a_link, r"\1" + ".\u200b" + r"\2", message) # Unicode zero-width space def nl2br(value): diff --git a/notifications_utils/sanitise_text.py b/notifications_utils/sanitise_text.py index b1d91413..bbd55bd0 100644 --- a/notifications_utils/sanitise_text.py +++ b/notifications_utils/sanitise_text.py @@ -13,8 +13,8 @@ class SanitiseText: "’": "'", # RIGHT SINGLE QUOTATION MARK (U+2019) "“": '"', # LEFT DOUBLE QUOTATION MARK (U+201C) "”": '"', # RIGHT DOUBLE QUOTATION MARK (U+201D) - "\u200B": "", # ZERO WIDTH SPACE (U+200B) - "\u00A0": "", # NON BREAKING WHITE SPACE (U+200B) + "\u200b": "", # ZERO WIDTH SPACE (U+200B) + "\u00a0": "", # NON BREAKING WHITE SPACE (U+200B) "\t": " ", # TAB } diff --git a/notifications_utils/strftime_codes.py b/notifications_utils/strftime_codes.py index 410dc79d..b311c256 100644 --- a/notifications_utils/strftime_codes.py +++ b/notifications_utils/strftime_codes.py @@ -1,23 +1,23 @@ """This module provides platform compatible format codes for strftime. - By default, Python does not check the format codes sent to strftime: - these are sent directly to the platform's implementation. This leads - developers to use platform specific format codes for strftime that - can't easily run on other platforms that are popular and normally - easy to support for by the Python language. +By default, Python does not check the format codes sent to strftime: +these are sent directly to the platform's implementation. This leads +developers to use platform specific format codes for strftime that +can't easily run on other platforms that are popular and normally +easy to support for by the Python language. - Hence we have this module that makes the translation between platform - specific format codes. To refer to the different platform specific - codes and what is deemed safe (i.e. ANSI C/ POSIX compatible): +Hence we have this module that makes the translation between platform +specific format codes. To refer to the different platform specific +codes and what is deemed safe (i.e. ANSI C/ POSIX compatible): - For windows, see: - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?redirectedfrom=MSDN&view=msvc-160 +For windows, see: +https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?redirectedfrom=MSDN&view=msvc-160 - For *nix compatible (non-POSIX compatible), see: - https://man7.org/linux/man-pages/man3/strftime.3.html +For *nix compatible (non-POSIX compatible), see: +https://man7.org/linux/man-pages/man3/strftime.3.html - 'somewhat POSIX'/ ANSI C compatible, see - https://en.cppreference.com/w/c/chrono/strftime +'somewhat POSIX'/ ANSI C compatible, see +https://en.cppreference.com/w/c/chrono/strftime """ import platform diff --git a/tests/test_formatters.py b/tests/test_formatters.py index c8007207..648bd6ff 100644 --- a/tests/test_formatters.py +++ b/tests/test_formatters.py @@ -168,9 +168,9 @@ def test_preserves_whitespace_when_making_links(markdown_function, expected_outp @pytest.mark.parametrize( "template_content,expected", [ - ("gov.uk", "gov.\u200Buk"), - ("GOV.UK", "GOV.\u200BUK"), - ("Gov.uk", "Gov.\u200Buk"), + ("gov.uk", "gov.\u200buk"), + ("GOV.UK", "GOV.\u200bUK"), + ("Gov.uk", "Gov.\u200buk"), ("https://gov.uk", "https://gov.uk"), ("https://www.gov.uk", "https://www.gov.uk"), ("www.gov.uk", "www.gov.uk"), @@ -951,7 +951,7 @@ def test_make_list_from_linebreaks(): """ \t bar """, - " \u180E\u200B \u200C bar \u200D \u2060\uFEFF ", + " \u180e\u200b \u200c bar \u200d \u2060\ufeff ", ], ) def test_strip_whitespace(value): @@ -963,7 +963,7 @@ def test_strip_whitespace(value): [ "notifications-email", " \tnotifications-email \x0c ", - "\rn\u200Coti\u200Dfi\u200Bcati\u2060ons-\u180Eemai\uFEFFl\uFEFF", + "\rn\u200coti\u200dfi\u200bcati\u2060ons-\u180eemai\ufeffl\ufeff", ], ) def test_strip_and_remove_obscure_whitespace(value): @@ -996,7 +996,7 @@ def test_strip_unsupported_characters(): def test_normalise_whitespace(): - assert normalise_whitespace("\u200C Your tax is\ndue\n\n") == "Your tax is due" + assert normalise_whitespace("\u200c Your tax is\ndue\n\n") == "Your tax is due" class TestAddLanguageDivs: diff --git a/tests/test_recipient_csv.py b/tests/test_recipient_csv.py index 033c951a..06442f56 100644 --- a/tests/test_recipient_csv.py +++ b/tests/test_recipient_csv.py @@ -844,14 +844,14 @@ def test_ignores_spaces_and_case_in_placeholders(key, expected): ("\n", None), # newline ("\r", None), # carriage return ("\t", None), # tab - ("\u180E", "MONGOLIAN VOWEL SEPARATOR"), - ("\u200B", "ZERO WIDTH SPACE"), - ("\u200C", "ZERO WIDTH NON-JOINER"), - ("\u200D", "ZERO WIDTH JOINER"), + ("\u180e", "MONGOLIAN VOWEL SEPARATOR"), + ("\u200b", "ZERO WIDTH SPACE"), + ("\u200c", "ZERO WIDTH NON-JOINER"), + ("\u200d", "ZERO WIDTH JOINER"), ("\u2060", "WORD JOINER"), - ("\uFEFF", "ZERO WIDTH NO-BREAK SPACE"), + ("\ufeff", "ZERO WIDTH NO-BREAK SPACE"), # all the things - (" \n\r\t\u000A\u000D\u180E\u200B\u200C\u200D\u2060\uFEFF", None), + (" \n\r\t\u000a\u000d\u180e\u200b\u200c\u200d\u2060\ufeff", None), ), ) def test_ignores_leading_whitespace_in_file(character, name): diff --git a/tests/test_recipient_validation.py b/tests/test_recipient_validation.py index f3d74cf2..0cc55979 100644 --- a/tests/test_recipient_validation.py +++ b/tests/test_recipient_validation.py @@ -332,7 +332,7 @@ def test_validate_email_address_accepts_valid(email_address): " email@domain.com ", "\temail@domain.com", "\temail@domain.com\n", - "\u200Bemail@domain.com\u200B", + "\u200bemail@domain.com\u200b", ], ) def test_validate_email_address_strips_whitespace(email): @@ -400,7 +400,7 @@ def test_validate_address_allows_any_non_empty_value(column): ], ) def test_non_ascii_address_line_is_fine(column): - valid_address = "\u041F\u0435\u0442\u044F" + valid_address = "\u041f\u0435\u0442\u044f" assert validate_recipient(valid_address, "letter", column=column) == valid_address diff --git a/tests/test_sanitise_text.py b/tests/test_sanitise_text.py index a8d458bc..cf4a5292 100644 --- a/tests/test_sanitise_text.py +++ b/tests/test_sanitise_text.py @@ -16,7 +16,7 @@ def test_encode_chars_sms_fr_not_downgraded(chars, cls): (("–", "-"), "compatibility transform unicode char (EN DASH (U+2013)"), (("—", "-"), "compatibility transform unicode char (EM DASH (U+2014)"), (("…", "..."), "compatibility transform unicode char (HORIZONTAL ELLIPSIS (U+2026)"), - (("\u200B", ""), "compatibility transform unicode char (ZERO WIDTH SPACE (U+200B)"), + (("\u200b", ""), "compatibility transform unicode char (ZERO WIDTH SPACE (U+200B)"), (("‘", "'"), "compatibility transform unicode char (LEFT SINGLE QUOTATION MARK (U+2018)"), (("’", "'"), "compatibility transform unicode char (RIGHT SINGLE QUOTATION MARK (U+2019)"), (("“", '"'), "compatibility transform unicode char (LEFT DOUBLE QUOTATION MARK (U+201C) "), diff --git a/tests/test_template_types.py b/tests/test_template_types.py index a5c80c87..abf9acc8 100644 --- a/tests/test_template_types.py +++ b/tests/test_template_types.py @@ -484,9 +484,9 @@ def test_HTML_template_has_URLs_replaced_with_links(content, html_snippet): @pytest.mark.parametrize( "template_content,expected", [ - ("gov.uk", "gov.\u200Buk"), - ("GOV.UK", "GOV.\u200BUK"), - ("Gov.uk", "Gov.\u200Buk"), + ("gov.uk", "gov.\u200buk"), + ("GOV.UK", "GOV.\u200bUK"), + ("Gov.uk", "Gov.\u200buk"), ("https://gov.uk", "https://gov.uk"), ("https://www.gov.uk", "https://www.gov.uk"), ("www.gov.uk", "www.gov.uk"), @@ -2064,7 +2064,7 @@ def test_whitespace_in_subjects(template_class, subject, extra_args): ) def test_whitespace_in_subject_placeholders(template_class): assert ( - template_class({"content": "", "subject": "\u200C Your tax ((status))"}, values={"status": " is\ndue "}).subject + template_class({"content": "", "subject": "\u200c Your tax ((status))"}, values={"status": " is\ndue "}).subject == "Your tax is due" )