@@ -1046,33 +1046,6 @@ def test_ignore_case_range(self):
1046
1046
def test_category (self ):
1047
1047
self .assertEqual (re .match (r"(\s)" , " " ).group (1 ), " " )
1048
1048
1049
- @cpython_only
1050
- def test_case_helpers (self ):
1051
- import _sre
1052
- for i in range (128 ):
1053
- c = chr (i )
1054
- lo = ord (c .lower ())
1055
- self .assertEqual (_sre .ascii_tolower (i ), lo )
1056
- self .assertEqual (_sre .unicode_tolower (i ), lo )
1057
- iscased = c in string .ascii_letters
1058
- self .assertEqual (_sre .ascii_iscased (i ), iscased )
1059
- self .assertEqual (_sre .unicode_iscased (i ), iscased )
1060
-
1061
- for i in list (range (128 , 0x1000 )) + [0x10400 , 0x10428 ]:
1062
- c = chr (i )
1063
- self .assertEqual (_sre .ascii_tolower (i ), i )
1064
- if i != 0x0130 :
1065
- self .assertEqual (_sre .unicode_tolower (i ), ord (c .lower ()))
1066
- iscased = c != c .lower () or c != c .upper ()
1067
- self .assertFalse (_sre .ascii_iscased (i ))
1068
- self .assertEqual (_sre .unicode_iscased (i ),
1069
- c != c .lower () or c != c .upper ())
1070
-
1071
- self .assertEqual (_sre .ascii_tolower (0x0130 ), 0x0130 )
1072
- self .assertEqual (_sre .unicode_tolower (0x0130 ), ord ('i' ))
1073
- self .assertFalse (_sre .ascii_iscased (0x0130 ))
1074
- self .assertTrue (_sre .unicode_iscased (0x0130 ))
1075
-
1076
1049
def test_not_literal (self ):
1077
1050
self .assertEqual (re .search (r"\s([^a])" , " b" ).group (1 ), "b" )
1078
1051
self .assertEqual (re .search (r"\s([^a]*)" , " bb" ).group (1 ), "bb" )
@@ -1769,20 +1742,6 @@ def test_bug_6509(self):
1769
1742
pat = re .compile (b'..' )
1770
1743
self .assertEqual (pat .sub (lambda m : b'bytes' , b'a5' ), b'bytes' )
1771
1744
1772
- def test_dealloc (self ):
1773
- # issue 3299: check for segfault in debug build
1774
- import _sre
1775
- # the overflow limit is different on wide and narrow builds and it
1776
- # depends on the definition of SRE_CODE (see sre.h).
1777
- # 2**128 should be big enough to overflow on both. For smaller values
1778
- # a RuntimeError is raised instead of OverflowError.
1779
- long_overflow = 2 ** 128
1780
- self .assertRaises (TypeError , re .finditer , "a" , {})
1781
- with self .assertRaises (OverflowError ):
1782
- _sre .compile ("abc" , 0 , [long_overflow ], 0 , {}, ())
1783
- with self .assertRaises (TypeError ):
1784
- _sre .compile ({}, 0 , [], 0 , [], [])
1785
-
1786
1745
def test_search_dot_unicode (self ):
1787
1746
self .assertTrue (re .search ("123.*-" , '123abc-' ))
1788
1747
self .assertTrue (re .search ("123.*-" , '123\xe9 -' ))
@@ -1840,21 +1799,6 @@ def test_repeat_minmax_overflow(self):
1840
1799
self .assertRaises (OverflowError , re .compile , r".{%d,}?" % 2 ** 128 )
1841
1800
self .assertRaises (OverflowError , re .compile , r".{%d,%d}" % (2 ** 129 , 2 ** 128 ))
1842
1801
1843
- @cpython_only
1844
- def test_repeat_minmax_overflow_maxrepeat (self ):
1845
- try :
1846
- from _sre import MAXREPEAT
1847
- except ImportError :
1848
- self .skipTest ('requires _sre.MAXREPEAT constant' )
1849
- string = "x" * 100000
1850
- self .assertIsNone (re .match (r".{%d}" % (MAXREPEAT - 1 ), string ))
1851
- self .assertEqual (re .match (r".{,%d}" % (MAXREPEAT - 1 ), string ).span (),
1852
- (0 , 100000 ))
1853
- self .assertIsNone (re .match (r".{%d,}?" % (MAXREPEAT - 1 ), string ))
1854
- self .assertRaises (OverflowError , re .compile , r".{%d}" % MAXREPEAT )
1855
- self .assertRaises (OverflowError , re .compile , r".{,%d}" % MAXREPEAT )
1856
- self .assertRaises (OverflowError , re .compile , r".{%d,}?" % MAXREPEAT )
1857
-
1858
1802
def test_backref_group_name_in_exception (self ):
1859
1803
# Issue 17341: Poor error message when compiling invalid regex
1860
1804
self .checkPatternError ('(?P=<foo>)' ,
@@ -2441,16 +2385,6 @@ def test_regression_gh94675(self):
2441
2385
p .terminate ()
2442
2386
p .join ()
2443
2387
2444
- def test_sre_template_invalid_group_index (self ):
2445
- # see gh-106524
2446
- import _sre
2447
- with self .assertRaises (TypeError ) as cm :
2448
- _sre .template ("" , ["" , - 1 , "" ])
2449
- self .assertIn ("invalid template" , str (cm .exception ))
2450
- with self .assertRaises (TypeError ) as cm :
2451
- _sre .template ("" , ["" , (), "" ])
2452
- self .assertIn ("an integer is required" , str (cm .exception ))
2453
-
2454
2388
2455
2389
def get_debug_out (pat ):
2456
2390
with captured_stdout () as out :
@@ -2699,6 +2633,75 @@ def test_deprecated_modules(self):
2699
2633
self .assertTrue (hasattr (mod , attr ))
2700
2634
del sys .modules [name ]
2701
2635
2636
+ @cpython_only
2637
+ def test_case_helpers (self ):
2638
+ import _sre
2639
+ for i in range (128 ):
2640
+ c = chr (i )
2641
+ lo = ord (c .lower ())
2642
+ self .assertEqual (_sre .ascii_tolower (i ), lo )
2643
+ self .assertEqual (_sre .unicode_tolower (i ), lo )
2644
+ iscased = c in string .ascii_letters
2645
+ self .assertEqual (_sre .ascii_iscased (i ), iscased )
2646
+ self .assertEqual (_sre .unicode_iscased (i ), iscased )
2647
+
2648
+ for i in list (range (128 , 0x1000 )) + [0x10400 , 0x10428 ]:
2649
+ c = chr (i )
2650
+ self .assertEqual (_sre .ascii_tolower (i ), i )
2651
+ if i != 0x0130 :
2652
+ self .assertEqual (_sre .unicode_tolower (i ), ord (c .lower ()))
2653
+ iscased = c != c .lower () or c != c .upper ()
2654
+ self .assertFalse (_sre .ascii_iscased (i ))
2655
+ self .assertEqual (_sre .unicode_iscased (i ),
2656
+ c != c .lower () or c != c .upper ())
2657
+
2658
+ self .assertEqual (_sre .ascii_tolower (0x0130 ), 0x0130 )
2659
+ self .assertEqual (_sre .unicode_tolower (0x0130 ), ord ('i' ))
2660
+ self .assertFalse (_sre .ascii_iscased (0x0130 ))
2661
+ self .assertTrue (_sre .unicode_iscased (0x0130 ))
2662
+
2663
+ @cpython_only
2664
+ def test_dealloc (self ):
2665
+ # issue 3299: check for segfault in debug build
2666
+ import _sre
2667
+ # the overflow limit is different on wide and narrow builds and it
2668
+ # depends on the definition of SRE_CODE (see sre.h).
2669
+ # 2**128 should be big enough to overflow on both. For smaller values
2670
+ # a RuntimeError is raised instead of OverflowError.
2671
+ long_overflow = 2 ** 128
2672
+ self .assertRaises (TypeError , re .finditer , "a" , {})
2673
+ with self .assertRaises (OverflowError ):
2674
+ _sre .compile ("abc" , 0 , [long_overflow ], 0 , {}, ())
2675
+ with self .assertRaises (TypeError ):
2676
+ _sre .compile ({}, 0 , [], 0 , [], [])
2677
+
2678
+ @cpython_only
2679
+ def test_repeat_minmax_overflow_maxrepeat (self ):
2680
+ try :
2681
+ from _sre import MAXREPEAT
2682
+ except ImportError :
2683
+ self .skipTest ('requires _sre.MAXREPEAT constant' )
2684
+ string = "x" * 100000
2685
+ self .assertIsNone (re .match (r".{%d}" % (MAXREPEAT - 1 ), string ))
2686
+ self .assertEqual (re .match (r".{,%d}" % (MAXREPEAT - 1 ), string ).span (),
2687
+ (0 , 100000 ))
2688
+ self .assertIsNone (re .match (r".{%d,}?" % (MAXREPEAT - 1 ), string ))
2689
+ self .assertRaises (OverflowError , re .compile , r".{%d}" % MAXREPEAT )
2690
+ self .assertRaises (OverflowError , re .compile , r".{,%d}" % MAXREPEAT )
2691
+ self .assertRaises (OverflowError , re .compile , r".{%d,}?" % MAXREPEAT )
2692
+
2693
+ @cpython_only
2694
+ def test_sre_template_invalid_group_index (self ):
2695
+ # see gh-106524
2696
+ import _sre
2697
+ with self .assertRaises (TypeError ) as cm :
2698
+ _sre .template ("" , ["" , - 1 , "" ])
2699
+ self .assertIn ("invalid template" , str (cm .exception ))
2700
+ with self .assertRaises (TypeError ) as cm :
2701
+ _sre .template ("" , ["" , (), "" ])
2702
+ self .assertIn ("an integer is required" , str (cm .exception ))
2703
+
2704
+
2702
2705
class ExternalTests (unittest .TestCase ):
2703
2706
2704
2707
def test_re_benchmarks (self ):
0 commit comments