def _mutate_assignment(mutate_dict: dict, source_file: SolidityFile, project_directory: Path): interesting_locs = source_file.get_assignments() for original_operator, src in interesting_locs: if original_operator not in mutate_dict.keys(): continue yield Mutation(src, source_file, mutate_dict[original_operator], project_directory)
def _mutate_binary_op(mutate_dict: dict, source_file: SolidityFile, project_directory: Path): interesting_locs = list(source_file.get_binary_op_locations()) for original_operator, src in interesting_locs: if original_operator not in mutate_dict.keys(): continue yield Mutation(src, source_file, mutate_dict[original_operator], project_directory)
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_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_create_mutation(tmp_path: Path): # Arrange location = (1, 1, 0) source = None value = "replacement" project_directory = tmp_path # Act mutation = Mutation(location, source, value, project_directory) # Assert assert location == mutation.location assert source == mutation.source assert value == mutation.value assert project_directory == mutation.project_directory assert mutation.result is None assert mutation.crime_scenes == []
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"
def mutate_modifier(source_file: SolidityFile, project_directory: Path): modifier_invocations = list(source_file.get_modifier_invocations()) for _, src in modifier_invocations: yield Mutation(src, source_file, "", project_directory)
def mutate_voids(source_file: SolidityFile, project_directory: Path): void_calls = list(source_file.get_void_calls()) for _, src in void_calls: src[1] += 1 yield Mutation(src, source_file, "", project_directory)