@@ -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" )
@@ -1770,20 +1743,6 @@ def test_bug_6509(self):
1770
1743
pat = re .compile (b'..' )
1771
1744
self .assertEqual (pat .sub (lambda m : b'bytes' , b'a5' ), b'bytes' )
1772
1745
1773
- def test_dealloc (self ):
1774
- # issue 3299: check for segfault in debug build
1775
- import _sre
1776
- # the overflow limit is different on wide and narrow builds and it
1777
- # depends on the definition of SRE_CODE (see sre.h).
1778
- # 2**128 should be big enough to overflow on both. For smaller values
1779
- # a RuntimeError is raised instead of OverflowError.
1780
- long_overflow = 2 ** 128
1781
- self .assertRaises (TypeError , re .finditer , "a" , {})
1782
- with self .assertRaises (OverflowError ):
1783
- _sre .compile ("abc" , 0 , [long_overflow ], 0 , {}, ())
1784
- with self .assertRaises (TypeError ):
1785
- _sre .compile ({}, 0 , [], 0 , [], [])
1786
-
1787
1746
def test_search_dot_unicode (self ):
1788
1747
self .assertTrue (re .search ("123.*-" , '123abc-' ))
1789
1748
self .assertTrue (re .search ("123.*-" , '123\xe9 -' ))
@@ -1841,21 +1800,6 @@ def test_repeat_minmax_overflow(self):
1841
1800
self .assertRaises (OverflowError , re .compile , r".{%d,}?" % 2 ** 128 )
1842
1801
self .assertRaises (OverflowError , re .compile , r".{%d,%d}" % (2 ** 129 , 2 ** 128 ))
1843
1802
1844
- @cpython_only
1845
- def test_repeat_minmax_overflow_maxrepeat (self ):
1846
- try :
1847
- from _sre import MAXREPEAT
1848
- except ImportError :
1849
- self .skipTest ('requires _sre.MAXREPEAT constant' )
1850
- string = "x" * 100000
1851
- self .assertIsNone (re .match (r".{%d}" % (MAXREPEAT - 1 ), string ))
1852
- self .assertEqual (re .match (r".{,%d}" % (MAXREPEAT - 1 ), string ).span (),
1853
- (0 , 100000 ))
1854
- self .assertIsNone (re .match (r".{%d,}?" % (MAXREPEAT - 1 ), string ))
1855
- self .assertRaises (OverflowError , re .compile , r".{%d}" % MAXREPEAT )
1856
- self .assertRaises (OverflowError , re .compile , r".{,%d}" % MAXREPEAT )
1857
- self .assertRaises (OverflowError , re .compile , r".{%d,}?" % MAXREPEAT )
1858
-
1859
1803
def test_backref_group_name_in_exception (self ):
1860
1804
# Issue 17341: Poor error message when compiling invalid regex
1861
1805
self .checkPatternError ('(?P=<foo>)' ,
@@ -2418,16 +2362,6 @@ def test_regression_gh94675(self):
2418
2362
p .terminate ()
2419
2363
p .join ()
2420
2364
2421
- def test_sre_template_invalid_group_index (self ):
2422
- # see gh-106524
2423
- import _sre
2424
- with self .assertRaises (TypeError ) as cm :
2425
- _sre .template ("" , ["" , - 1 , "" ])
2426
- self .assertIn ("invalid template" , str (cm .exception ))
2427
- with self .assertRaises (TypeError ) as cm :
2428
- _sre .template ("" , ["" , (), "" ])
2429
- self .assertIn ("an integer is required" , str (cm .exception ))
2430
-
2431
2365
2432
2366
def get_debug_out (pat ):
2433
2367
with captured_stdout () as out :
@@ -2676,6 +2610,75 @@ def test_deprecated_modules(self):
2676
2610
self .assertTrue (hasattr (mod , attr ))
2677
2611
del sys .modules [name ]
2678
2612
2613
+ @cpython_only
2614
+ def test_case_helpers (self ):
2615
+ import _sre
2616
+ for i in range (128 ):
2617
+ c = chr (i )
2618
+ lo = ord (c .lower ())
2619
+ self .assertEqual (_sre .ascii_tolower (i ), lo )
2620
+ self .assertEqual (_sre .unicode_tolower (i ), lo )
2621
+ iscased = c in string .ascii_letters
2622
+ self .assertEqual (_sre .ascii_iscased (i ), iscased )
2623
+ self .assertEqual (_sre .unicode_iscased (i ), iscased )
2624
+
2625
+ for i in list (range (128 , 0x1000 )) + [0x10400 , 0x10428 ]:
2626
+ c = chr (i )
2627
+ self .assertEqual (_sre .ascii_tolower (i ), i )
2628
+ if i != 0x0130 :
2629
+ self .assertEqual (_sre .unicode_tolower (i ), ord (c .lower ()))
2630
+ iscased = c != c .lower () or c != c .upper ()
2631
+ self .assertFalse (_sre .ascii_iscased (i ))
2632
+ self .assertEqual (_sre .unicode_iscased (i ),
2633
+ c != c .lower () or c != c .upper ())
2634
+
2635
+ self .assertEqual (_sre .ascii_tolower (0x0130 ), 0x0130 )
2636
+ self .assertEqual (_sre .unicode_tolower (0x0130 ), ord ('i' ))
2637
+ self .assertFalse (_sre .ascii_iscased (0x0130 ))
2638
+ self .assertTrue (_sre .unicode_iscased (0x0130 ))
2639
+
2640
+ @cpython_only
2641
+ def test_dealloc (self ):
2642
+ # issue 3299: check for segfault in debug build
2643
+ import _sre
2644
+ # the overflow limit is different on wide and narrow builds and it
2645
+ # depends on the definition of SRE_CODE (see sre.h).
2646
+ # 2**128 should be big enough to overflow on both. For smaller values
2647
+ # a RuntimeError is raised instead of OverflowError.
2648
+ long_overflow = 2 ** 128
2649
+ self .assertRaises (TypeError , re .finditer , "a" , {})
2650
+ with self .assertRaises (OverflowError ):
2651
+ _sre .compile ("abc" , 0 , [long_overflow ], 0 , {}, ())
2652
+ with self .assertRaises (TypeError ):
2653
+ _sre .compile ({}, 0 , [], 0 , [], [])
2654
+
2655
+ @cpython_only
2656
+ def test_repeat_minmax_overflow_maxrepeat (self ):
2657
+ try :
2658
+ from _sre import MAXREPEAT
2659
+ except ImportError :
2660
+ self .skipTest ('requires _sre.MAXREPEAT constant' )
2661
+ string = "x" * 100000
2662
+ self .assertIsNone (re .match (r".{%d}" % (MAXREPEAT - 1 ), string ))
2663
+ self .assertEqual (re .match (r".{,%d}" % (MAXREPEAT - 1 ), string ).span (),
2664
+ (0 , 100000 ))
2665
+ self .assertIsNone (re .match (r".{%d,}?" % (MAXREPEAT - 1 ), string ))
2666
+ self .assertRaises (OverflowError , re .compile , r".{%d}" % MAXREPEAT )
2667
+ self .assertRaises (OverflowError , re .compile , r".{,%d}" % MAXREPEAT )
2668
+ self .assertRaises (OverflowError , re .compile , r".{%d,}?" % MAXREPEAT )
2669
+
2670
+ @cpython_only
2671
+ def test_sre_template_invalid_group_index (self ):
2672
+ # see gh-106524
2673
+ import _sre
2674
+ with self .assertRaises (TypeError ) as cm :
2675
+ _sre .template ("" , ["" , - 1 , "" ])
2676
+ self .assertIn ("invalid template" , str (cm .exception ))
2677
+ with self .assertRaises (TypeError ) as cm :
2678
+ _sre .template ("" , ["" , (), "" ])
2679
+ self .assertIn ("an integer is required" , str (cm .exception ))
2680
+
2681
+
2679
2682
class ExternalTests (unittest .TestCase ):
2680
2683
2681
2684
def test_re_benchmarks (self ):
0 commit comments