Skip to content

Commit

Permalink
fix: only_mutate_file_paths option not working
Browse files Browse the repository at this point in the history
  • Loading branch information
jungs1 committed Jul 29, 2024
1 parent 4ddefa2 commit 65f8ae7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
21 changes: 14 additions & 7 deletions src/mutahunter/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
from mutahunter.core.db import MutationDatabase
from mutahunter.core.entities.config import MutationTestControllerConfig
from mutahunter.core.error_parser import extract_error_message
from mutahunter.core.exceptions import (CoverageAnalysisError,
MutantKilledError, MutantSurvivedError,
MutationTestingError,
ReportGenerationError,
UnexpectedTestResultError)
from mutahunter.core.exceptions import (
CoverageAnalysisError,
MutantKilledError,
MutantSurvivedError,
MutationTestingError,
ReportGenerationError,
UnexpectedTestResultError,
)
from mutahunter.core.git_handler import GitHandler
from mutahunter.core.io import FileOperationHandler
from mutahunter.core.llm_mutation_engine import LLMMutationEngine
Expand Down Expand Up @@ -93,7 +96,9 @@ def run_mutation_testing_all(self) -> None:
all_covered_files = self.coverage_processor.file_lines_executed.keys()
for covered_file_path in tqdm(all_covered_files):
if FileOperationHandler.should_skip_file(
covered_file_path, self.config.exclude_files
covered_file_path,
exclude_files=self.config.exclude_files,
only_mutate_file_paths=self.config.only_mutate_file_paths,
):
continue
executed_lines = self.coverage_processor.file_lines_executed[
Expand All @@ -114,7 +119,9 @@ def run_mutation_testing_diff(self) -> None:
)
for file_path in tqdm(modified_files):
if FileOperationHandler.should_skip_file(
file_path, self.config.exclude_files
file_path,
exclude_files=self.config.exclude_files,
only_mutate_file_paths=self.config.only_mutate_file_paths,
):
continue
modified_lines = GitHandler.get_modified_lines(file_path)
Expand Down
14 changes: 8 additions & 6 deletions src/mutahunter/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ def prepare_mutant_file(
return mutant_path

@staticmethod
def should_skip_file(filename: str, exclude_files: List[str]) -> bool:
for file_path in exclude_files:
if not os.path.exists(file_path):
raise FileNotFoundError(f"File {file_path} does not exist.")
return all(file_path != filename for file_path in exclude_files)
def should_skip_file(
filename: str, exclude_files: List[str], only_mutate_file_paths: List[str]
) -> bool:
if only_mutate_file_paths:
for file_path in only_mutate_file_paths:
if not os.path.exists(file_path):
raise FileNotFoundError(f"File {file_path} does not exist.")
return all(file_path != filename for file_path in only_mutate_file_paths)
if filename in exclude_files:
return True
return any(keyword in filename for keyword in TEST_FILE_PATTERNS)

@staticmethod
def check_syntax(source_file_path: str, source_code: str) -> bool:
Expand Down

0 comments on commit 65f8ae7

Please sign in to comment.