|
43 | 43 | ) |
44 | 44 |
|
45 | 45 | import click |
46 | | -from parso import parse |
| 46 | +from parso import ( |
| 47 | + parse, |
| 48 | + ParserSyntaxError, |
| 49 | +) |
47 | 50 | from setproctitle import setproctitle |
48 | 51 |
|
49 | 52 | import mutmut |
@@ -181,10 +184,10 @@ def _mutmut_trampoline(orig, mutants, *args, **kwargs): |
181 | 184 | import os |
182 | 185 | mutant_under_test = os.environ['MUTANT_UNDER_TEST'] |
183 | 186 | if mutant_under_test == 'fail': |
184 | | - from __main__ import MutmutProgrammaticFailException |
| 187 | + from mutmut.__main__ import MutmutProgrammaticFailException |
185 | 188 | raise MutmutProgrammaticFailException('Failed programmatically') |
186 | 189 | elif mutant_under_test == 'stats': |
187 | | - from __main__ import record_trampoline_hit |
| 190 | + from mutmut.__main__ import record_trampoline_hit |
188 | 191 | record_trampoline_hit(orig.__module__ + '.' + orig.__name__) |
189 | 192 | return orig(*args, **kwargs) |
190 | 193 | prefix = orig.__module__ + '.' + orig.__name__ + '__mutmut_' |
@@ -239,7 +242,7 @@ def create_mutants_for_file(filename, output_path): |
239 | 242 | source = f.read() |
240 | 243 |
|
241 | 244 | with open(output_path, 'w') as out: |
242 | | - mutant_names, hash_by_function_name = write_all_mutants_to_file(out=out, source=source) |
| 245 | + mutant_names, hash_by_function_name = write_all_mutants_to_file(out=out, source=source, filename=filename) |
243 | 246 |
|
244 | 247 | # validate no syntax errors of mutants |
245 | 248 | with open(output_path) as f: |
@@ -269,13 +272,20 @@ def ensure_ends_with_newline(source): |
269 | 272 | return source |
270 | 273 |
|
271 | 274 |
|
272 | | -def write_all_mutants_to_file(*, out, source): |
| 275 | +def write_all_mutants_to_file(*, out, source, filename): |
273 | 276 | no_mutate_lines = pragma_no_mutate_lines(source) |
274 | 277 |
|
275 | 278 | hash_by_function_name = {} |
276 | 279 | mutant_names = [] |
277 | 280 |
|
278 | | - for type_, x, name_and_hash, mutant_name in yield_mutants_for_module(parse(ensure_ends_with_newline(source), error_recovery=False), no_mutate_lines): |
| 281 | + try: |
| 282 | + ast = parse(ensure_ends_with_newline(source), error_recovery=False) |
| 283 | + except ParserSyntaxError: |
| 284 | + print(f'Warning: unsupported syntax in {filename}, skipping') |
| 285 | + out.write(source) |
| 286 | + return [], {} |
| 287 | + |
| 288 | + for type_, x, name_and_hash, mutant_name in yield_mutants_for_module(ast, no_mutate_lines): |
279 | 289 | out.write(x) |
280 | 290 | if mutant_name: |
281 | 291 | mutant_names.append(mutant_name) |
|
0 commit comments