@@ -1169,12 +1169,21 @@ def assertFileContents(self, filename, contents):
1169
1169
self .assertTextDataIdentical (expected_content , contents , message ,
1170
1170
filename , filename + '.new' )
1171
1171
1172
- def assertContained (self , values , string , additional_info = '' ):
1173
- if type (values ) not in [list , tuple ]:
1174
- values = [values ]
1172
+ def assertContained (self , values , string , additional_info = '' , regex = False ):
1175
1173
if callable (string ):
1176
1174
string = string ()
1177
1175
1176
+ if regex :
1177
+ if type (values ) == str :
1178
+ self .assertTrue (re .search (values , string ), 'Expected regex "%s" to match on:\n %s' % (values , string ))
1179
+ else :
1180
+ match_any = any (re .search (o , string ) for o in values )
1181
+ self .assertTrue (match_any , 'Expected at least one of "%s" to match on:\n %s' % (values , string ))
1182
+ return
1183
+
1184
+ if type (values ) not in [list , tuple ]:
1185
+ values = [values ]
1186
+
1178
1187
if not any (v in string for v in values ):
1179
1188
diff = difflib .unified_diff (values [0 ].split ('\n ' ), string .split ('\n ' ), fromfile = 'expected' , tofile = 'actual' )
1180
1189
diff = '' .join (a .rstrip () + '\n ' for a in diff )
@@ -1507,16 +1516,9 @@ def _build_and_run(self, filename, expected_output, args=None, output_nicerizer=
1507
1516
self .assertIdentical (expected_output , js_output )
1508
1517
elif assert_all or len (expected_output ) == 1 :
1509
1518
for o in expected_output :
1510
- if regex :
1511
- self .assertTrue (re .search (o , js_output ), 'Expected regex "%s" to match on:\n %s' % (o , js_output ))
1512
- else :
1513
- self .assertContained (o , js_output )
1519
+ self .assertContained (o , js_output , regex = regex )
1514
1520
else :
1515
- if regex :
1516
- match_any = any (re .search (o , js_output ) for o in expected_output )
1517
- self .assertTrue (match_any , 'Expected at least one of "%s" to match on:\n %s' % (expected_output , js_output ))
1518
- else :
1519
- self .assertContained (expected_output , js_output )
1521
+ self .assertContained (expected_output , js_output , regex = regex )
1520
1522
if assert_returncode == 0 and check_for_error :
1521
1523
self .assertNotContained ('ERROR' , js_output )
1522
1524
except Exception :
0 commit comments