def test_truffle_runner_run_test_with_mutation(tmp_path): # Arrange file_path = tmp_path / "mutator.sol" # type: Path file_path.touch() source_file = SourceFile(file_path) src_field = (1, 1, 0) mutation = Mutation(location=src_field, source=source_file, value="value", project_directory=tmp_path) truffle_js = tmp_path / "truffle.js" # type: Path truffle_js.touch() expected_test_result = {"test_result": True} truffle_tester = TruffleTester(str(truffle_js), str(tmp_path), TruffleCompiler(str(truffle_js))) truffle_tester.run_test_command = MagicMock( return_value=expected_test_result) # Act test_result = truffle_tester.run_tests(mutation=mutation) # Assert assert expected_test_result == test_result
def test_get_mutated_line(tmp_path): # Arrange file = tmp_path / "sf.txt" file.write_text("yeah\ngood", encoding="utf-8") sf = SourceFile(file) mutation = Mutation(None, None, None, None) # Act mutated_line = mutation._get_mutated_line(6, sf.file.read_text(encoding="utf-8")) # Assert assert mutated_line == (1, "good")
def test_apply_mutation(tmp_path): # Arrange file_path = tmp_path / "mutator.sol" # type: Path file_path.touch() source_file = SourceFile(file_path) src_field = (1, 1, 0) mutation = Mutation(location=src_field, source=source_file, value="value", project_directory=tmp_path) # Act _apply_mutation(mutation, str(tmp_path)) # Assert assert "value" == file_path.read_text("utf-8")
def test_relative_path(tmp_path): # Arrange (tmp_path / "testdir").mkdir() sf_file: Path = tmp_path / "testdir" / "sf.txt" sf_file.write_text("some text", encoding="utf-8") sf = SourceFile(sf_file) mutation = Mutation(None, sf, None, tmp_path) # Act relative_path = mutation.relative_path # Assert assert "testdir/sf.txt" == relative_path
def test_repr(tmp_path): # Arrange file = tmp_path / "sf.txt" file.write_text("yeah\ngood", encoding="utf-8") sf = SourceFile(file) mutation = Mutation((6, 1, 0), sf, "b", tmp_path) mutation.result = MutationResult.LIVED # Act repr_ = str(mutation) print(repr_) # Assert assert repr_ == \ "Mutation:\n"\ " File: " + str(file) + "\n" \ " Line nr: 1\n" \ " Result: Lived\n" \ " Original line:\n" \ " good\n" \ " Mutated line:\n" \ " gbod"