Skip to content

Commit 769b7d2

Browse files
[3.11] Move implementation specific RE tests to separate class (GH-106563) (GH-106565)
(cherry picked from commit 8cb6f97) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 2d037fb commit 769b7d2

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

Lib/test/test_re.py

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,33 +1077,6 @@ def test_ignore_case_range(self):
10771077
def test_category(self):
10781078
self.assertEqual(re.match(r"(\s)", " ").group(1), " ")
10791079

1080-
@cpython_only
1081-
def test_case_helpers(self):
1082-
import _sre
1083-
for i in range(128):
1084-
c = chr(i)
1085-
lo = ord(c.lower())
1086-
self.assertEqual(_sre.ascii_tolower(i), lo)
1087-
self.assertEqual(_sre.unicode_tolower(i), lo)
1088-
iscased = c in string.ascii_letters
1089-
self.assertEqual(_sre.ascii_iscased(i), iscased)
1090-
self.assertEqual(_sre.unicode_iscased(i), iscased)
1091-
1092-
for i in list(range(128, 0x1000)) + [0x10400, 0x10428]:
1093-
c = chr(i)
1094-
self.assertEqual(_sre.ascii_tolower(i), i)
1095-
if i != 0x0130:
1096-
self.assertEqual(_sre.unicode_tolower(i), ord(c.lower()))
1097-
iscased = c != c.lower() or c != c.upper()
1098-
self.assertFalse(_sre.ascii_iscased(i))
1099-
self.assertEqual(_sre.unicode_iscased(i),
1100-
c != c.lower() or c != c.upper())
1101-
1102-
self.assertEqual(_sre.ascii_tolower(0x0130), 0x0130)
1103-
self.assertEqual(_sre.unicode_tolower(0x0130), ord('i'))
1104-
self.assertFalse(_sre.ascii_iscased(0x0130))
1105-
self.assertTrue(_sre.unicode_iscased(0x0130))
1106-
11071080
def test_not_literal(self):
11081081
self.assertEqual(re.search(r"\s([^a])", " b").group(1), "b")
11091082
self.assertEqual(re.search(r"\s([^a]*)", " bb").group(1), "bb")
@@ -1800,20 +1773,6 @@ def test_bug_6509(self):
18001773
pat = re.compile(b'..')
18011774
self.assertEqual(pat.sub(lambda m: b'bytes', b'a5'), b'bytes')
18021775

1803-
def test_dealloc(self):
1804-
# issue 3299: check for segfault in debug build
1805-
import _sre
1806-
# the overflow limit is different on wide and narrow builds and it
1807-
# depends on the definition of SRE_CODE (see sre.h).
1808-
# 2**128 should be big enough to overflow on both. For smaller values
1809-
# a RuntimeError is raised instead of OverflowError.
1810-
long_overflow = 2**128
1811-
self.assertRaises(TypeError, re.finditer, "a", {})
1812-
with self.assertRaises(OverflowError):
1813-
_sre.compile("abc", 0, [long_overflow], 0, {}, ())
1814-
with self.assertRaises(TypeError):
1815-
_sre.compile({}, 0, [], 0, [], [])
1816-
18171776
def test_search_dot_unicode(self):
18181777
self.assertTrue(re.search("123.*-", '123abc-'))
18191778
self.assertTrue(re.search("123.*-", '123\xe9-'))
@@ -1871,21 +1830,6 @@ def test_repeat_minmax_overflow(self):
18711830
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128)
18721831
self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128))
18731832

1874-
@cpython_only
1875-
def test_repeat_minmax_overflow_maxrepeat(self):
1876-
try:
1877-
from _sre import MAXREPEAT
1878-
except ImportError:
1879-
self.skipTest('requires _sre.MAXREPEAT constant')
1880-
string = "x" * 100000
1881-
self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string))
1882-
self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(),
1883-
(0, 100000))
1884-
self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string))
1885-
self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT)
1886-
self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
1887-
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT)
1888-
18891833
def test_backref_group_name_in_exception(self):
18901834
# Issue 17341: Poor error message when compiling invalid regex
18911835
self.checkPatternError('(?P=<foo>)',
@@ -2720,6 +2664,64 @@ def test_deprecated_modules(self):
27202664
self.assertTrue(hasattr(mod, attr))
27212665
del sys.modules[name]
27222666

2667+
@cpython_only
2668+
def test_case_helpers(self):
2669+
import _sre
2670+
for i in range(128):
2671+
c = chr(i)
2672+
lo = ord(c.lower())
2673+
self.assertEqual(_sre.ascii_tolower(i), lo)
2674+
self.assertEqual(_sre.unicode_tolower(i), lo)
2675+
iscased = c in string.ascii_letters
2676+
self.assertEqual(_sre.ascii_iscased(i), iscased)
2677+
self.assertEqual(_sre.unicode_iscased(i), iscased)
2678+
2679+
for i in list(range(128, 0x1000)) + [0x10400, 0x10428]:
2680+
c = chr(i)
2681+
self.assertEqual(_sre.ascii_tolower(i), i)
2682+
if i != 0x0130:
2683+
self.assertEqual(_sre.unicode_tolower(i), ord(c.lower()))
2684+
iscased = c != c.lower() or c != c.upper()
2685+
self.assertFalse(_sre.ascii_iscased(i))
2686+
self.assertEqual(_sre.unicode_iscased(i),
2687+
c != c.lower() or c != c.upper())
2688+
2689+
self.assertEqual(_sre.ascii_tolower(0x0130), 0x0130)
2690+
self.assertEqual(_sre.unicode_tolower(0x0130), ord('i'))
2691+
self.assertFalse(_sre.ascii_iscased(0x0130))
2692+
self.assertTrue(_sre.unicode_iscased(0x0130))
2693+
2694+
@cpython_only
2695+
def test_dealloc(self):
2696+
# issue 3299: check for segfault in debug build
2697+
import _sre
2698+
# the overflow limit is different on wide and narrow builds and it
2699+
# depends on the definition of SRE_CODE (see sre.h).
2700+
# 2**128 should be big enough to overflow on both. For smaller values
2701+
# a RuntimeError is raised instead of OverflowError.
2702+
long_overflow = 2**128
2703+
self.assertRaises(TypeError, re.finditer, "a", {})
2704+
with self.assertRaises(OverflowError):
2705+
_sre.compile("abc", 0, [long_overflow], 0, {}, ())
2706+
with self.assertRaises(TypeError):
2707+
_sre.compile({}, 0, [], 0, [], [])
2708+
2709+
@cpython_only
2710+
def test_repeat_minmax_overflow_maxrepeat(self):
2711+
try:
2712+
from _sre import MAXREPEAT
2713+
except ImportError:
2714+
self.skipTest('requires _sre.MAXREPEAT constant')
2715+
string = "x" * 100000
2716+
self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string))
2717+
self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(),
2718+
(0, 100000))
2719+
self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string))
2720+
self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT)
2721+
self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT)
2722+
self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT)
2723+
2724+
27232725
class ExternalTests(unittest.TestCase):
27242726

27252727
def test_re_benchmarks(self):

0 commit comments

Comments
 (0)