diff options
author | Ronnie van den Crommenacker <ronnie@owello.nl> | 2022-03-17 12:02:59 +0100 |
---|---|---|
committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-06-08 16:17:12 +0200 |
commit | c32858a8ce961d276215a040ae0ab1e4409b70f8 (patch) | |
tree | 87f3eed5729768bbb8bd23e5ef63d5daf710a636 /tests/i18n | |
parent | 49b470b9187b6be60e573fed08c8f4a87f133750 (diff) | |
download | django-c32858a8ce961d276215a040ae0ab1e4409b70f8.tar.gz |
Fixed #33565 -- Improved locale format validation for the makemessages command.
Diffstat (limited to 'tests/i18n')
-rw-r--r-- | tests/i18n/test_extraction.py | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index c2ae10efd8..5287677bab 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -175,7 +175,43 @@ class BasicExtractorTests(ExtractorTests): self.assertIn("processing locale de", out.getvalue()) self.assertIs(Path(self.PO_FILE).exists(), True) - def test_invalid_locale(self): + def test_valid_locale_with_country(self): + out = StringIO() + management.call_command( + "makemessages", locale=["en_GB"], stdout=out, verbosity=1 + ) + self.assertNotIn("invalid locale en_GB", out.getvalue()) + self.assertIn("processing locale en_GB", out.getvalue()) + self.assertIs(Path("locale/en_GB/LC_MESSAGES/django.po").exists(), True) + + def test_valid_locale_tachelhit_latin_morocco(self): + out = StringIO() + management.call_command( + "makemessages", locale=["shi_Latn_MA"], stdout=out, verbosity=1 + ) + self.assertNotIn("invalid locale shi_Latn_MA", out.getvalue()) + self.assertIn("processing locale shi_Latn_MA", out.getvalue()) + self.assertIs(Path("locale/shi_Latn_MA/LC_MESSAGES/django.po").exists(), True) + + def test_valid_locale_private_subtag(self): + out = StringIO() + management.call_command( + "makemessages", locale=["nl_NL-x-informal"], stdout=out, verbosity=1 + ) + self.assertNotIn("invalid locale nl_NL-x-informal", out.getvalue()) + self.assertIn("processing locale nl_NL-x-informal", out.getvalue()) + self.assertIs( + Path("locale/nl_NL-x-informal/LC_MESSAGES/django.po").exists(), True + ) + + def test_invalid_locale_uppercase(self): + out = StringIO() + management.call_command("makemessages", locale=["PL"], stdout=out, verbosity=1) + self.assertIn("invalid locale PL, did you mean pl?", out.getvalue()) + self.assertNotIn("processing locale pl", out.getvalue()) + self.assertIs(Path("locale/pl/LC_MESSAGES/django.po").exists(), False) + + def test_invalid_locale_hyphen(self): out = StringIO() management.call_command( "makemessages", locale=["pl-PL"], stdout=out, verbosity=1 @@ -184,6 +220,52 @@ class BasicExtractorTests(ExtractorTests): self.assertNotIn("processing locale pl-PL", out.getvalue()) self.assertIs(Path("locale/pl-PL/LC_MESSAGES/django.po").exists(), False) + def test_invalid_locale_lower_country(self): + out = StringIO() + management.call_command( + "makemessages", locale=["pl_pl"], stdout=out, verbosity=1 + ) + self.assertIn("invalid locale pl_pl, did you mean pl_PL?", out.getvalue()) + self.assertNotIn("processing locale pl_pl", out.getvalue()) + self.assertIs(Path("locale/pl_pl/LC_MESSAGES/django.po").exists(), False) + + def test_invalid_locale_private_subtag(self): + out = StringIO() + management.call_command( + "makemessages", locale=["nl-nl-x-informal"], stdout=out, verbosity=1 + ) + self.assertIn( + "invalid locale nl-nl-x-informal, did you mean nl_NL-x-informal?", + out.getvalue(), + ) + self.assertNotIn("processing locale nl-nl-x-informal", out.getvalue()) + self.assertIs( + Path("locale/nl-nl-x-informal/LC_MESSAGES/django.po").exists(), False + ) + + def test_invalid_locale_plus(self): + out = StringIO() + management.call_command( + "makemessages", locale=["en+GB"], stdout=out, verbosity=1 + ) + self.assertIn("invalid locale en+GB, did you mean en_GB?", out.getvalue()) + self.assertNotIn("processing locale en+GB", out.getvalue()) + self.assertIs(Path("locale/en+GB/LC_MESSAGES/django.po").exists(), False) + + def test_invalid_locale_end_with_underscore(self): + out = StringIO() + management.call_command("makemessages", locale=["en_"], stdout=out, verbosity=1) + self.assertIn("invalid locale en_", out.getvalue()) + self.assertNotIn("processing locale en_", out.getvalue()) + self.assertIs(Path("locale/en_/LC_MESSAGES/django.po").exists(), False) + + def test_invalid_locale_start_with_underscore(self): + out = StringIO() + management.call_command("makemessages", locale=["_en"], stdout=out, verbosity=1) + self.assertIn("invalid locale _en", out.getvalue()) + self.assertNotIn("processing locale _en", out.getvalue()) + self.assertIs(Path("locale/_en/LC_MESSAGES/django.po").exists(), False) + def test_comments_extractor(self): management.call_command("makemessages", locale=[LOCALE], verbosity=0) self.assertTrue(os.path.exists(self.PO_FILE)) |