def assert_mutation(self, original, mutants, lines=None, operator=None, with_coverage=False, with_exec=False): original_ast = utils.create_ast(original) if with_coverage: coverage_injector = coverage.CoverageInjector() coverage_injector.inject(original_ast) else: coverage_injector = None if not operator: operator = self.__class__.op if isinstance(mutants, str): mutants = [mutants] mutants = list(map(codegen.remove_extra_lines, mutants)) module = None if with_exec: module = utils.create_module(original_ast) for mutation, mutatnt in operator.mutate(original_ast, coverage_injector=coverage_injector, module=module): mutant_code = codegen.remove_extra_lines(codegen.to_source(mutatnt)) msg = '\n\nMutant:\n\n' + mutant_code + '\n\nNot found in:' for other_mutant in mutants: msg += '\n\n----------\n\n' + other_mutant self.assertIn(mutant_code, mutants, msg) mutants.remove(mutant_code) self.assert_location(mutatnt) if not lines is None: self.assert_mutation_lineo(mutation.node.lineno, lines) self.assertListEqual(mutants, [], 'did not generate all mutants')
def test_remove_extra_lines(self): code = EOL + INDENT + EOL + INDENT + 'pass' + EOL + INDENT + EOL + INDENT + 'pass' + EOL + EOL reduced = codegen.remove_extra_lines(code) self.assertEqual(reduced, INDENT + 'pass' + EOL + INDENT + 'pass')