@@ -1439,66 +1439,22 @@ def test_inline_flags(self):
14391439 self .assertTrue (re .match ('(?x) (?i) ' + upper_char , lower_char ))
14401440 self .assertTrue (re .match (' (?x) (?i) ' + upper_char , lower_char , re .X ))
14411441
1442- p = upper_char + '(?i)'
1443- with self .assertWarns (DeprecationWarning ) as warns :
1444- self .assertTrue (re .match (p , lower_char ))
1445- self .assertEqual (
1446- str (warns .warnings [0 ].message ),
1447- 'Flags not at the start of the expression %r'
1448- ' but at position 1' % p
1449- )
1450- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1451-
1452- p = upper_char + '(?i)%s' % ('.?' * 100 )
1453- with self .assertWarns (DeprecationWarning ) as warns :
1454- self .assertTrue (re .match (p , lower_char ))
1455- self .assertEqual (
1456- str (warns .warnings [0 ].message ),
1457- 'Flags not at the start of the expression %r (truncated)'
1458- ' but at position 1' % p [:20 ]
1459- )
1460- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1442+ msg = "global flags not at the start of the expression"
1443+ self .checkPatternError (upper_char + '(?i)' , msg , 1 )
14611444
14621445 # bpo-30605: Compiling a bytes instance regex was throwing a BytesWarning
14631446 with warnings .catch_warnings ():
14641447 warnings .simplefilter ('error' , BytesWarning )
1465- p = b'A(?i)'
1466- with self .assertWarns (DeprecationWarning ) as warns :
1467- self .assertTrue (re .match (p , b'a' ))
1468- self .assertEqual (
1469- str (warns .warnings [0 ].message ),
1470- 'Flags not at the start of the expression %r'
1471- ' but at position 1' % p
1472- )
1473- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1474-
1475- with self .assertWarns (DeprecationWarning ):
1476- self .assertTrue (re .match ('(?s).(?i)' + upper_char , '\n ' + lower_char ))
1477- with self .assertWarns (DeprecationWarning ):
1478- self .assertTrue (re .match ('(?i) ' + upper_char + ' (?x)' , lower_char ))
1479- with self .assertWarns (DeprecationWarning ):
1480- self .assertTrue (re .match (' (?x) (?i) ' + upper_char , lower_char ))
1481- with self .assertWarns (DeprecationWarning ):
1482- self .assertTrue (re .match ('^(?i)' + upper_char , lower_char ))
1483- with self .assertWarns (DeprecationWarning ):
1484- self .assertTrue (re .match ('$|(?i)' + upper_char , lower_char ))
1485- with self .assertWarns (DeprecationWarning ) as warns :
1486- self .assertTrue (re .match ('(?:(?i)' + upper_char + ')' , lower_char ))
1487- self .assertRegex (str (warns .warnings [0 ].message ),
1488- 'Flags not at the start' )
1489- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1490- with self .assertWarns (DeprecationWarning ) as warns :
1491- self .assertTrue (re .fullmatch ('(^)?(?(1)(?i)' + upper_char + ')' ,
1492- lower_char ))
1493- self .assertRegex (str (warns .warnings [0 ].message ),
1494- 'Flags not at the start' )
1495- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1496- with self .assertWarns (DeprecationWarning ) as warns :
1497- self .assertTrue (re .fullmatch ('($)?(?(1)|(?i)' + upper_char + ')' ,
1498- lower_char ))
1499- self .assertRegex (str (warns .warnings [0 ].message ),
1500- 'Flags not at the start' )
1501- self .assertEqual (warns .warnings [0 ].filename , __file__ )
1448+ self .checkPatternError (b'A(?i)' , msg , 1 )
1449+
1450+ self .checkPatternError ('(?s).(?i)' + upper_char , msg , 5 )
1451+ self .checkPatternError ('(?i) ' + upper_char + ' (?x)' , msg , 7 )
1452+ self .checkPatternError (' (?x) (?i) ' + upper_char , msg , 1 )
1453+ self .checkPatternError ('^(?i)' + upper_char , msg , 1 )
1454+ self .checkPatternError ('$|(?i)' + upper_char , msg , 2 )
1455+ self .checkPatternError ('(?:(?i)' + upper_char + ')' , msg , 3 )
1456+ self .checkPatternError ('(^)?(?(1)(?i)' + upper_char + ')' , msg , 9 )
1457+ self .checkPatternError ('($)?(?(1)|(?i)' + upper_char + ')' , msg , 10 )
15021458
15031459
15041460 def test_dollar_matches_twice (self ):
0 commit comments