diff options
| author | django-bot <ops@djangoproject.com> | 2025-07-22 20:41:41 -0700 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2025-07-23 20:17:55 -0300 |
| commit | 69a93a88edb56ba47f624dac7a21aacc47ea474f (patch) | |
| tree | f57507a4435d032493cae40e06ecb254790b67b2 /tests/i18n | |
| parent | 55b0cc21310b76ce4018dd793ba50556eaf0af06 (diff) | |
Refs #36500 -- Rewrapped long docstrings and block comments via a script.
Rewrapped long docstrings and block comments to 79 characters + newline
using script from https://github.com/medmunds/autofix-w505.
Diffstat (limited to 'tests/i18n')
| -rwxr-xr-x | tests/i18n/sampleproject/update_catalogs.py | 3 | ||||
| -rw-r--r-- | tests/i18n/test_compilation.py | 21 | ||||
| -rw-r--r-- | tests/i18n/test_extraction.py | 33 | ||||
| -rw-r--r-- | tests/i18n/tests.py | 44 |
4 files changed, 59 insertions, 42 deletions
diff --git a/tests/i18n/sampleproject/update_catalogs.py b/tests/i18n/sampleproject/update_catalogs.py index 8780f629e4..af8953c312 100755 --- a/tests/i18n/sampleproject/update_catalogs.py +++ b/tests/i18n/sampleproject/update_catalogs.py @@ -13,7 +13,8 @@ blocktranslate. This issue is difficult to debug, it could be a problem with extraction, interpolation, or both. How this script helps: - * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to templates. + * Add {% translate "Two %% Three %%%" %} and blocktranslate equivalent to + templates. * Run this script. * Test extraction - verify the new msgid in sampleproject's django.po. * Add a translation to sampleproject's django.po. diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py index 3a57dbf076..e99e3e4acc 100644 --- a/tests/i18n/test_compilation.py +++ b/tests/i18n/test_compilation.py @@ -199,18 +199,18 @@ class IgnoreDirectoryCompilationTests(MessageCompilationTests): def test_no_dirs_accidentally_skipped(self): os_walk_results = [ - # To discover .po filepaths, compilemessages uses with a starting list of - # basedirs to inspect, which in this scenario are: + # To discover .po filepaths, compilemessages uses with a starting + # list of basedirs to inspect, which in this scenario are: # ["conf/locale", "locale"] - # Then os.walk is used to discover other locale dirs, ignoring dirs matching - # `ignore_patterns`. Mock the results to place an ignored directory directly - # before and after a directory named "locale". + # Then os.walk is used to discover other locale dirs, ignoring dirs + # matching `ignore_patterns`. Mock the results to place an ignored + # directory directly before and after a directory named "locale". [("somedir", ["ignore", "locale", "ignore"], [])], # This will result in three basedirs discovered: # ["conf/locale", "locale", "somedir/locale"] - # os.walk is called for each locale in each basedir looking for .po files. - # In this scenario, we need to mock os.walk results for "en", "fr", and "it" - # locales for each basedir: + # os.walk is called for each locale in each basedir looking for .po + # files. In this scenario, we need to mock os.walk results for + # "en", "fr", and "it" locales for each basedir: [("exclude/locale/LC_MESSAGES", [], ["en.po"])], [("exclude/locale/LC_MESSAGES", [], ["fr.po"])], [("exclude/locale/LC_MESSAGES", [], ["it.po"])], @@ -277,8 +277,9 @@ class CompilationErrorHandling(MessageCompilationTests): call_command("compilemessages", locale=["ja"], verbosity=0) def test_msgfmt_error_including_non_ascii(self): - # po file contains invalid msgstr content (triggers non-ascii error content). - # Make sure the output of msgfmt is unaffected by the current locale. + # po file contains invalid msgstr content (triggers non-ascii error + # content). Make sure the output of msgfmt is unaffected by the current + # locale. env = os.environ.copy() env.update({"LC_ALL": "C"}) with mock.patch( diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index e4a6260c33..b02b24ab5b 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -101,7 +101,8 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase): def assertLocationCommentPresent(self, po_filename, line_number, *comment_parts): r""" - self.assertLocationCommentPresent('django.po', 42, 'dirA', 'dirB', 'foo.py') + self.assertLocationCommentPresent('django.po', 42, 'dirA', 'dirB', + 'foo.py') verifies that the django.po file has a gettext-style location comment of the form @@ -368,7 +369,9 @@ class BasicExtractorTests(ExtractorTests): management.call_command("makemessages", locale=[LOCALE], verbosity=0) def test_extraction_warning(self): - """test xgettext warning about multiple bare interpolation placeholders""" + """ + test xgettext warning about multiple bare interpolation placeholders + """ shutil.copyfile("./code.sample", "./code_sample.py") out = StringIO() management.call_command("makemessages", locale=[LOCALE], stdout=out) @@ -438,7 +441,9 @@ class BasicExtractorTests(ExtractorTests): ) def test_template_comments(self): - """Template comment tags on the same line of other constructs (#19552)""" + """ + Template comment tags on the same line of other constructs (#19552) + """ # Test detection/end user reporting of old, incorrect templates # translator comments syntax with warnings.catch_warnings(record=True) as ws: @@ -656,7 +661,8 @@ class JavaScriptExtractorTests(ExtractorTests): def test_i18n_catalog_not_ignored_when_not_invoked_for_django(self): # Create target file so it exists in the filesystem but is NOT ignored. - # "invoked_for_django" is False when "conf/locale" folder does not exist. + # "invoked_for_django" is False when "conf/locale" folder does not + # exist. self.assertIs(os.path.exists(os.path.join("conf", "locale")), False) i18n_catalog_js = os.path.join("views", "templates", "i18n_catalog.js") os.makedirs(os.path.dirname(i18n_catalog_js)) @@ -757,9 +763,9 @@ class CopyPluralFormsExtractorTests(ExtractorTests): def test_translate_and_plural_blocktranslate_collision(self): """ - Ensures a correct workaround for the gettext bug when handling a literal - found inside a {% translate %} tag and also in another file inside a - {% blocktranslate %} with a plural (#17375). + Ensures a correct workaround for the gettext bug when handling a + literal found inside a {% translate %} tag and also in another file + inside a {% blocktranslate %} with a plural (#17375). """ management.call_command( "makemessages", locale=[LOCALE], extensions=["html", "djtpl"], verbosity=0 @@ -810,7 +816,9 @@ class NoWrapExtractorTests(ExtractorTests): class LocationCommentsTests(ExtractorTests): def test_no_location_enabled(self): - """Behavior is correct if --no-location switch is specified. See #16903.""" + """ + Behavior is correct if --no-location switch is specified. See #16903. + """ management.call_command( "makemessages", locale=[LOCALE], verbosity=0, no_location=True ) @@ -823,7 +831,8 @@ class LocationCommentsTests(ExtractorTests): "makemessages", locale=[LOCALE], verbosity=0, no_location=False ) self.assertTrue(os.path.exists(self.PO_FILE)) - # #16903 -- Standard comment with source file relative path should be present + # #16903 -- Standard comment with source file relative path should be + # present self.assertLocationCommentPresent( self.PO_FILE, "Translatable literal #6b", "templates", "test.html" ) @@ -942,7 +951,8 @@ class ExcludedLocaleExtractionTests(ExtractorTests): def _set_times_for_all_po_files(self): """ - Set access and modification times to the Unix epoch time for all the .po files. + Set access and modification times to the Unix epoch time for all the + .po files. """ for locale in self.LOCALES: os.utime(self.PO_FILE % locale, (0, 0)) @@ -1010,7 +1020,8 @@ class CustomLayoutExtractionTests(ExtractorTests): def _test_project_locale_paths(self, locale_path): """ - * translations for an app containing a locale folder are stored in that folder + * translations for an app containing a locale folder are stored in that + folder * translations outside of that app are in LOCALE_PATHS[0] """ with override_settings(LOCALE_PATHS=[locale_path]): diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 1f50ba1112..b4bdf160d6 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -92,7 +92,8 @@ class TranslationTests(SimpleTestCase): @translation.override("fr") def test_plural(self): """ - Test plurals with ngettext. French differs from English in that 0 is singular. + Test plurals with ngettext. French differs from English in that 0 is + singular. """ self.assertEqual( ngettext("%(num)d year", "%(num)d years", 0) % {"num": 0}, @@ -119,9 +120,9 @@ class TranslationTests(SimpleTestCase): @translation.override("fr") def test_multiple_plurals_per_language(self): """ - Normally, French has 2 plurals. As other/locale/fr/LC_MESSAGES/django.po - has a different plural equation with 3 plurals, this tests if those - plural are honored. + Normally, French has 2 plurals. As + other/locale/fr/LC_MESSAGES/django.po has a different plural equation + with 3 plurals, this tests if those plural are honored. """ self.assertEqual(ngettext("%d singular", "%d plural", 0) % 0, "0 pluriel1") self.assertEqual(ngettext("%d singular", "%d plural", 1) % 1, "1 singulier") @@ -415,8 +416,8 @@ class TranslationTests(SimpleTestCase): @override_settings(LOCALE_PATHS=extended_locale_paths) def test_safe_status(self): """ - Translating a string requiring no auto-escaping with gettext or pgettext - shouldn't change the "safe" status. + Translating a string requiring no auto-escaping with gettext or + pgettext shouldn't change the "safe" status. """ trans_real._active = Local() trans_real._translations = {} @@ -1278,8 +1279,8 @@ class FormattingTests(SimpleTestCase): self.assertEqual(sanitize_separators(123), 123) with translation.override("ru", deactivate=True): - # Russian locale has non-breaking space (\xa0) as thousand separator - # Usual space is accepted too when sanitizing inputs + # Russian locale has non-breaking space (\xa0) as thousand + # separator Usual space is accepted too when sanitizing inputs with self.settings(USE_THOUSAND_SEPARATOR=True): self.assertEqual(sanitize_separators("1\xa0234\xa0567"), "1234567") self.assertEqual(sanitize_separators("77\xa0777,777"), "77777.777") @@ -1347,7 +1348,8 @@ class FormattingTests(SimpleTestCase): def test_iter_format_modules_stability(self): """ Tests the iter_format_modules function always yields format modules in - a stable and correct order in presence of both base ll and ll_CC formats. + a stable and correct order in presence of both base ll and ll_CC + formats. """ en_format_mod = import_module("django.conf.locale.en.formats") en_gb_format_mod = import_module("django.conf.locale.en_GB.formats") @@ -1364,7 +1366,8 @@ class FormattingTests(SimpleTestCase): def test_localize_templatetag_and_filter(self): """ - Test the {% localize %} templatetag and the localize/unlocalize filters. + Test the {% localize %} templatetag and the localize/unlocalize + filters. """ context = Context( {"int": 1455, "float": 3.14, "date": datetime.date(2016, 12, 31)} @@ -1618,11 +1621,11 @@ class MiscTests(SimpleTestCase): ) def test_support_for_deprecated_chinese_language_codes(self): """ - Some browsers (Firefox, IE, etc.) use deprecated language codes. As these - language codes will be removed in Django 1.9, these will be incorrectly - matched. For example zh-tw (traditional) will be interpreted as zh-hans - (simplified), which is wrong. So we should also accept these deprecated - language codes. + Some browsers (Firefox, IE, etc.) use deprecated language codes. As + these language codes will be removed in Django 1.9, these will be + incorrectly matched. For example zh-tw (traditional) will be + interpreted as zh-hans (simplified), which is wrong. So we should also + accept these deprecated language codes. refs #18419 -- this is explicitly for browser compatibility """ @@ -1915,8 +1918,8 @@ class TestLanguageInfo(SimpleTestCase): def test_fallback_language_code(self): """ - get_language_info return the first fallback language info if the lang_info - struct does not contain the 'name' key. + get_language_info return the first fallback language info if the + lang_info struct does not contain the 'name' key. """ li = get_language_info("zh-my") self.assertEqual(li["code"], "zh-hans") @@ -1963,7 +1966,8 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase): def test_default_lang_without_prefix(self): """ With i18n_patterns(..., prefix_default_language=False), the default - language (settings.LANGUAGE_CODE) should be accessible without a prefix. + language (settings.LANGUAGE_CODE) should be accessible without a + prefix. """ response = self.client.get("/simple/") self.assertEqual(response.content, b"Yes") @@ -1990,8 +1994,8 @@ class UnprefixedDefaultLanguageTests(SimpleTestCase): def test_no_redirect_on_404(self): """ A request for a nonexistent URL shouldn't cause a redirect to - /<default_language>/<request_url> when prefix_default_language=False and - /<default_language>/<request_url> has a URL match (#27402). + /<default_language>/<request_url> when prefix_default_language=False + and /<default_language>/<request_url> has a URL match (#27402). """ # A match for /group1/group2/ must exist for this to act as a # regression test. |
