@@ -732,23 +732,25 @@ def run_re_tests():
732732 else :
733733 print ('=== Failed incorrectly' , t )
734734
735- # Try the match on a unicode string, and check that it
736- # still succeeds.
735+ # Try the match with both pattern and string converted to
736+ # bytes, and check that it still succeeds.
737737 try :
738- result = obj .search (str (s , "latin-1" ))
739- if result is None :
740- print ('=== Fails on unicode match' , t )
741- except NameError :
742- continue # 1.5.2
743- except TypeError :
744- continue # unicode test case
745-
746- # Try the match on a unicode pattern, and check that it
747- # still succeeds.
748- obj = re .compile (str (pattern , "latin-1" ))
749- result = obj .search (s )
750- if result is None :
751- print ('=== Fails on unicode pattern match' , t )
738+ bpat = bytes (pattern , "ascii" )
739+ bs = bytes (s , "ascii" )
740+ except UnicodeEncodeError :
741+ # skip non-ascii tests
742+ pass
743+ else :
744+ try :
745+ bpat = re .compile (bpat )
746+ except Exception :
747+ print ('=== Fails on bytes pattern compile' , t )
748+ if verbose :
749+ traceback .print_exc (file = sys .stdout )
750+ else :
751+ bytes_result = bpat .search (bs )
752+ if bytes_result is None :
753+ print ('=== Fails on bytes pattern match' , t )
752754
753755 # Try the match with the search area limited to the extent
754756 # of the match and see if it still succeeds. \B will
@@ -771,10 +773,11 @@ def run_re_tests():
771773
772774 # Try the match with LOCALE enabled, and check that it
773775 # still succeeds.
774- obj = re .compile (pattern , re .LOCALE )
775- result = obj .search (s )
776- if result is None :
777- print ('=== Fails on locale-sensitive match' , t )
776+ if '(?u)' not in pattern :
777+ obj = re .compile (pattern , re .LOCALE )
778+ result = obj .search (s )
779+ if result is None :
780+ print ('=== Fails on locale-sensitive match' , t )
778781
779782 # Try the match with UNICODE locale enabled, and check
780783 # that it still succeeds.
0 commit comments