diff --git a/src/mutahunter/core/controller.py b/src/mutahunter/core/controller.py index 393c2c1..9e1fa00 100644 --- a/src/mutahunter/core/controller.py +++ b/src/mutahunter/core/controller.py @@ -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 @@ -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[ @@ -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) diff --git a/src/mutahunter/core/io.py b/src/mutahunter/core/io.py index e89f90d..73ae16a 100644 --- a/src/mutahunter/core/io.py +++ b/src/mutahunter/core/io.py @@ -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: