| 1148 | self.assertFileContents(expected, read_file(actual), tofile=actual) |
| 1149 | |
| 1150 | def assertContained(self, values, string, additional_info='', regex=False): |
| 1151 | if callable(string): |
| 1152 | string = string() |
| 1153 | |
| 1154 | if regex: |
| 1155 | if type(values) is str: |
| 1156 | self.assertTrue(re.search(values, string, re.DOTALL), 'Expected regex "%s" to match on:\n%s' % (values, limit_size(string))) |
| 1157 | else: |
| 1158 | match_any = any(re.search(o, string, re.DOTALL) for o in values) |
| 1159 | self.assertTrue(match_any, 'Expected at least one of "%s" to match on:\n%s' % (values, limit_size(string))) |
| 1160 | return |
| 1161 | |
| 1162 | if type(values) not in {list, tuple}: |
| 1163 | values = [values] |
| 1164 | |
| 1165 | if not any(v in string for v in values): |
| 1166 | diff = difflib.unified_diff(values[0].split('\n'), string.split('\n'), fromfile='expected', tofile='actual') |
| 1167 | diff = ''.join(a.rstrip() + '\n' for a in diff) |
| 1168 | self.fail("Expected to find '%s' in '%s', diff:\n\n%s\n%s" % ( |
| 1169 | limit_size(values[0]), limit_size(string), limit_size(diff), |
| 1170 | additional_info, |
| 1171 | )) |
| 1172 | |
| 1173 | def assertNotContained(self, value, string, regex=False): |
| 1174 | if callable(value): |