diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:56:45 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-10-30 22:56:45 (GMT) |
commit | 7cc0a1f7cb6af03ada42174404bed86bdbb4e16c (patch) | |
tree | a4f0f8e321275727722fe034af531f56529e4b92 /Lib/test/test_re.py | |
parent | c689101a5eed64923993d61c4fe46d794d1293f5 (diff) | |
parent | 4659cc075667f6a38f3f69c9838585c71ec44d53 (diff) | |
download | cpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.zip cpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.tar.gz cpython-7cc0a1f7cb6af03ada42174404bed86bdbb4e16c.tar.bz2 |
Issue #22410: Module level functions in the re module now cache compiled
locale-dependent regular expressions taking into account the locale.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index dfc797c..4029561 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,6 +1,7 @@ from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \ cpython_only, captured_stdout import io +import locale import re from re import Scanner import sre_compile @@ -1276,6 +1277,42 @@ subpattern None # with ignore case. self.assertEqual(re.fullmatch('[a-c]+', 'ABC', re.I).span(), (0, 3)) + def test_locale_caching(self): + # Issue #22410 + oldlocale = locale.setlocale(locale.LC_CTYPE) + self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) + for loc in 'en_US.iso88591', 'en_US.utf8': + try: + locale.setlocale(locale.LC_CTYPE, loc) + except locale.Error: + # Unsupported locale on this system + self.skipTest('test needs %s locale' % loc) + + re.purge() + self.check_en_US_iso88591() + self.check_en_US_utf8() + re.purge() + self.check_en_US_utf8() + self.check_en_US_iso88591() + + def check_en_US_iso88591(self): + locale.setlocale(locale.LC_CTYPE, 'en_US.iso88591') + self.assertTrue(re.match(b'\xc5\xe5', b'\xc5\xe5', re.L|re.I)) + self.assertTrue(re.match(b'\xc5', b'\xe5', re.L|re.I)) + self.assertTrue(re.match(b'\xe5', b'\xc5', re.L|re.I)) + self.assertTrue(re.match(b'(?Li)\xc5\xe5', b'\xc5\xe5')) + self.assertTrue(re.match(b'(?Li)\xc5', b'\xe5')) + self.assertTrue(re.match(b'(?Li)\xe5', b'\xc5')) + + def check_en_US_utf8(self): + locale.setlocale(locale.LC_CTYPE, 'en_US.utf8') + self.assertTrue(re.match(b'\xc5\xe5', b'\xc5\xe5', re.L|re.I)) + self.assertIsNone(re.match(b'\xc5', b'\xe5', re.L|re.I)) + self.assertIsNone(re.match(b'\xe5', b'\xc5', re.L|re.I)) + self.assertTrue(re.match(b'(?Li)\xc5\xe5', b'\xc5\xe5')) + self.assertIsNone(re.match(b'(?Li)\xc5', b'\xe5')) + self.assertIsNone(re.match(b'(?Li)\xe5', b'\xc5')) + class PatternReprTests(unittest.TestCase): def check(self, pattern, expected): |