@@ -100,11 +100,14 @@ def test_basic_re_sub(self):
100100 self .assertEqual (re .sub ('(?P<unk>x)' , '\g<unk>\g<unk>' , 'xx' ), 'xxxx' )
101101 self .assertEqual (re .sub ('(?P<unk>x)' , '\g<1>\g<1>' , 'xx' ), 'xxxx' )
102102
103- self .assertEqual (re .sub ('a' ,r'\t\n\v\r\f\a\b\B\Z\a\A\w\W\s\S\d\D' ,'a' ),
104- '\t \n \v \r \f \a \b \\ B\\ Z\a \\ A\\ w\\ W\\ s\\ S\\ d\\ D' )
105- self .assertEqual (re .sub ('a' , '\t \n \v \r \f \a ' , 'a' ), '\t \n \v \r \f \a ' )
106- self .assertEqual (re .sub ('a' , '\t \n \v \r \f \a ' , 'a' ),
107- (chr (9 )+ chr (10 )+ chr (11 )+ chr (13 )+ chr (12 )+ chr (7 )))
103+ self .assertEqual (re .sub ('a' , r'\t\n\v\r\f\a\b' , 'a' ), '\t \n \v \r \f \a \b ' )
104+ self .assertEqual (re .sub ('a' , '\t \n \v \r \f \a \b ' , 'a' ), '\t \n \v \r \f \a \b ' )
105+ self .assertEqual (re .sub ('a' , '\t \n \v \r \f \a \b ' , 'a' ),
106+ (chr (9 )+ chr (10 )+ chr (11 )+ chr (13 )+ chr (12 )+ chr (7 )+ chr (8 )))
107+ for c in 'cdehijklmopqsuwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' :
108+ with self .subTest (c ):
109+ with self .assertWarns (DeprecationWarning ):
110+ self .assertEqual (re .sub ('a' , '\\ ' + c , 'a' ), '\\ ' + c )
108111
109112 self .assertEqual (re .sub ('^\s*' , 'X' , 'test' ), 'Xtest' )
110113
@@ -551,14 +554,23 @@ def test_other_escapes(self):
551554 self .assertEqual (re .match (r"\(" , '(' ).group (), '(' )
552555 self .assertIsNone (re .match (r"\(" , ')' ))
553556 self .assertEqual (re .match (r"\\" , '\\ ' ).group (), '\\ ' )
554- self .assertEqual (re .match (r"\y" , 'y' ).group (), 'y' )
555- self .assertIsNone (re .match (r"\y" , 'z' ))
556557 self .assertEqual (re .match (r"[\]]" , ']' ).group (), ']' )
557558 self .assertIsNone (re .match (r"[\]]" , '[' ))
558559 self .assertEqual (re .match (r"[a\-c]" , '-' ).group (), '-' )
559560 self .assertIsNone (re .match (r"[a\-c]" , 'b' ))
560561 self .assertEqual (re .match (r"[\^a]+" , 'a^' ).group (), 'a^' )
561562 self .assertIsNone (re .match (r"[\^a]+" , 'b' ))
563+ re .purge () # for warnings
564+ for c in 'ceghijklmopqyzCEFGHIJKLMNOPQRTVXY' :
565+ with self .subTest (c ):
566+ with self .assertWarns (DeprecationWarning ):
567+ self .assertEqual (re .fullmatch ('\\ %c' % c , c ).group (), c )
568+ self .assertIsNone (re .match ('\\ %c' % c , 'a' ))
569+ for c in 'ceghijklmopqyzABCEFGHIJKLMNOPQRTVXYZ' :
570+ with self .subTest (c ):
571+ with self .assertWarns (DeprecationWarning ):
572+ self .assertEqual (re .fullmatch ('[\\ %c]' % c , c ).group (), c )
573+ self .assertIsNone (re .match ('[\\ %c]' % c , 'a' ))
562574
563575 def test_string_boundaries (self ):
564576 # See http://bugs.python.org/issue10713
@@ -907,8 +919,10 @@ def test_sre_byte_literals(self):
907919 self .assertTrue (re .match ((r"\x%02x" % i ).encode (), bytes ([i ])))
908920 self .assertTrue (re .match ((r"\x%02x0" % i ).encode (), bytes ([i ])+ b"0" ))
909921 self .assertTrue (re .match ((r"\x%02xz" % i ).encode (), bytes ([i ])+ b"z" ))
910- self .assertTrue (re .match (br"\u" , b'u' ))
911- self .assertTrue (re .match (br"\U" , b'U' ))
922+ with self .assertWarns (DeprecationWarning ):
923+ self .assertTrue (re .match (br"\u1234" , b'u1234' ))
924+ with self .assertWarns (DeprecationWarning ):
925+ self .assertTrue (re .match (br"\U00012345" , b'U00012345' ))
912926 self .assertTrue (re .match (br"\0" , b"\000 " ))
913927 self .assertTrue (re .match (br"\08" , b"\000 8" ))
914928 self .assertTrue (re .match (br"\01" , b"\001 " ))
@@ -928,8 +942,10 @@ def test_sre_byte_class_literals(self):
928942 self .assertTrue (re .match ((r"[\x%02x]" % i ).encode (), bytes ([i ])))
929943 self .assertTrue (re .match ((r"[\x%02x0]" % i ).encode (), bytes ([i ])))
930944 self .assertTrue (re .match ((r"[\x%02xz]" % i ).encode (), bytes ([i ])))
931- self .assertTrue (re .match (br"[\u]" , b'u' ))
932- self .assertTrue (re .match (br"[\U]" , b'U' ))
945+ with self .assertWarns (DeprecationWarning ):
946+ self .assertTrue (re .match (br"[\u1234]" , b'u' ))
947+ with self .assertWarns (DeprecationWarning ):
948+ self .assertTrue (re .match (br"[\U00012345]" , b'U' ))
933949 self .assertRaises (re .error , re .match , br"[\567]" , b"" )
934950 self .assertRaises (re .error , re .match , br"[\911]" , b"" )
935951 self .assertRaises (re .error , re .match , br"[\x1z]" , b"" )
@@ -1304,8 +1320,9 @@ def test_compile(self):
13041320 def test_bug_13899 (self ):
13051321 # Issue #13899: re pattern r"[\A]" should work like "A" but matches
13061322 # nothing. Ditto B and Z.
1307- self .assertEqual (re .findall (r'[\A\B\b\C\Z]' , 'AB\b CZ' ),
1308- ['A' , 'B' , '\b ' , 'C' , 'Z' ])
1323+ with self .assertWarns (DeprecationWarning ):
1324+ self .assertEqual (re .findall (r'[\A\B\b\C\Z]' , 'AB\b CZ' ),
1325+ ['A' , 'B' , '\b ' , 'C' , 'Z' ])
13091326
13101327 @bigmemtest (size = _2G , memuse = 1 )
13111328 def test_large_search (self , size ):
0 commit comments