diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-19 19:21:25 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-12-19 19:21:25 (GMT) |
commit | c8cc42edf489706c71384d9bfcf5fe457f8a3692 (patch) | |
tree | 7089fc169684a98fb7a214870e9a1eea7ebc3b13 /Lib/test | |
parent | 1e81a399a25edd23d76601c0c421bdad46b5c19c (diff) | |
download | cpython-c8cc42edf489706c71384d9bfcf5fe457f8a3692.zip cpython-c8cc42edf489706c71384d9bfcf5fe457f8a3692.tar.gz cpython-c8cc42edf489706c71384d9bfcf5fe457f8a3692.tar.bz2 |
Issue #5815: Fixed support for locales with modifiers. Fixed support for
locale encodings with hyphens.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_locale.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 48bf36d..76202df 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -365,6 +365,64 @@ class TestEnUSCollation(BaseLocalizedTest, TestCollation): self.assertLess(locale.strxfrm('à'), locale.strxfrm('b')) +class NormalizeTest(unittest.TestCase): + def check(self, localename, expected): + self.assertEqual(locale.normalize(localename), expected, msg=localename) + + def test_locale_alias(self): + for localename, alias in locale.locale_alias.items(): + with self.subTest(locale=(localename, alias)): + self.check(localename, alias) + + def test_empty(self): + self.check('', '') + + def test_c(self): + self.check('c', 'C') + self.check('posix', 'C') + + def test_english(self): + self.check('en', 'en_US.ISO8859-1') + self.check('EN', 'en_US.ISO8859-1') + self.check('en_US', 'en_US.ISO8859-1') + self.check('en_us', 'en_US.ISO8859-1') + self.check('en_GB', 'en_GB.ISO8859-1') + self.check('en_US.UTF-8', 'en_US.UTF-8') + self.check('en_US.utf8', 'en_US.UTF-8') + self.check('en_US:UTF-8', 'en_US.UTF-8') + self.check('en_US.ISO8859-1', 'en_US.ISO8859-1') + self.check('en_US.US-ASCII', 'en_US.ISO8859-1') + self.check('english', 'en_EN.ISO8859-1') + + def test_hyphenated_encoding(self): + self.check('az_AZ.iso88599e', 'az_AZ.ISO8859-9E') + self.check('az_AZ.ISO8859-9E', 'az_AZ.ISO8859-9E') + self.check('tt_RU.koi8c', 'tt_RU.KOI8-C') + self.check('tt_RU.KOI8-C', 'tt_RU.KOI8-C') + self.check('lo_LA.cp1133', 'lo_LA.IBM-CP1133') + self.check('lo_LA.ibmcp1133', 'lo_LA.IBM-CP1133') + self.check('lo_LA.IBM-CP1133', 'lo_LA.IBM-CP1133') + self.check('uk_ua.microsoftcp1251', 'uk_UA.CP1251') + self.check('uk_ua.microsoft-cp1251', 'uk_UA.CP1251') + self.check('ka_ge.georgianacademy', 'ka_GE.GEORGIAN-ACADEMY') + self.check('ka_GE.GEORGIAN-ACADEMY', 'ka_GE.GEORGIAN-ACADEMY') + self.check('cs_CZ.iso88592', 'cs_CZ.ISO8859-2') + self.check('cs_CZ.ISO8859-2', 'cs_CZ.ISO8859-2') + + def test_euro_modifier(self): + self.check('de_DE@euro', 'de_DE.ISO8859-15') + self.check('en_US.ISO8859-15@euro', 'en_US.ISO8859-15') + + def test_latin_modifier(self): + self.check('be_BY.UTF-8@latin', 'be_BY.UTF-8@latin') + self.check('sr_RS.UTF-8@latin', 'sr_RS.UTF-8@latin') + + def test_valencia_modifier(self): + self.check('ca_ES.UTF-8@valencia', 'ca_ES.UTF-8@valencia') + self.check('ca_ES@valencia', 'ca_ES.ISO8859-1@valencia') + self.check('ca@valencia', 'ca_ES.ISO8859-1@valencia') + + class TestMiscellaneous(unittest.TestCase): def test_getpreferredencoding(self): # Invoke getpreferredencoding to make sure it does not cause exceptions. |