1from __future__ import annotations 2 3from typing import Any 4from warnings import warn 5 6from tools.testing.target_determination.heuristics.interface import ( 7 HeuristicInterface, 8 TestPrioritizations, 9) 10from tools.testing.target_determination.heuristics.utils import ( 11 python_test_file_to_test_name, 12 query_changed_files, 13) 14from tools.testing.test_run import TestRun 15 16 17class EditedByPR(HeuristicInterface): 18 def __init__(self, **kwargs: dict[str, Any]) -> None: 19 super().__init__(**kwargs) 20 21 def get_prediction_confidence(self, tests: list[str]) -> TestPrioritizations: 22 critical_tests = _get_modified_tests() 23 return TestPrioritizations( 24 tests, {TestRun(test): 1 for test in critical_tests if test in tests} 25 ) 26 27 28def _get_modified_tests() -> set[str]: 29 try: 30 changed_files = query_changed_files() 31 except Exception as e: 32 warn(f"Can't query changed test files due to {e}") 33 # If unable to get changed files from git, quit without doing any sorting 34 return set() 35 36 return python_test_file_to_test_name(set(changed_files)) 37