MCPcopy Index your code
hub / github.com/huggingface/diffusers / infer_tests_to_run

Function infer_tests_to_run

utils/tests_fetcher.py:909–996  ·  view source on GitHub ↗

The main function called by the test fetcher. Determines the tests to run from the diff. Args: output_file (`str`): The path where to store the summary of the test fetcher analysis. Other files will be stored in the same folder: - examples_test_

(
    output_file: str,
    diff_with_last_commit: bool = False,
    json_output_file: str | None = None,
)

Source from the content-addressed store, hash-verified

907
908
909def infer_tests_to_run(
910 output_file: str,
911 diff_with_last_commit: bool = False,
912 json_output_file: str | None = None,
913):
914 """
915 The main function called by the test fetcher. Determines the tests to run from the diff.
916
917 Args:
918 output_file (`str`):
919 The path where to store the summary of the test fetcher analysis. Other files will be stored in the same
920 folder:
921
922 - examples_test_list.txt: The list of examples tests to run.
923 - test_repo_utils.txt: Will indicate if the repo utils tests should be run or not.
924 - doctest_list.txt: The list of doctests to run.
925
926 diff_with_last_commit (`bool`, *optional*, defaults to `False`):
927 Whether to analyze the diff with the last commit (for use on the main branch after a PR is merged) or with
928 the branching point from main (for use on each PR).
929 filter_models (`bool`, *optional*, defaults to `True`):
930 Whether or not to filter the tests to core models only, when a file modified results in a lot of model
931 tests.
932 json_output_file (`str`, *optional*):
933 The path where to store the json file mapping categories of tests to tests to run (used for parallelism or
934 the slow tests).
935 """
936 modified_files = get_modified_python_files(diff_with_last_commit=diff_with_last_commit)
937 print(f"\n### MODIFIED FILES ###\n{_print_list(modified_files)}")
938 # Create the map that will give us all impacted modules.
939 reverse_map = create_reverse_dependency_map()
940 impacted_files = modified_files.copy()
941 for f in modified_files:
942 if f in reverse_map:
943 impacted_files.extend(reverse_map[f])
944
945 # Remove duplicates
946 impacted_files = sorted(set(impacted_files))
947 print(f"\n### IMPACTED FILES ###\n{_print_list(impacted_files)}")
948
949 # Grab the corresponding test files:
950 if any(x in modified_files for x in ["setup.py"]):
951 test_files_to_run = ["tests", "examples"]
952
953 # in order to trigger pipeline tests even if no code change at all
954 if "tests/utils/tiny_model_summary.json" in modified_files:
955 test_files_to_run = ["tests"]
956 any(f.split(os.path.sep)[0] == "utils" for f in modified_files)
957 else:
958 # All modified tests need to be run.
959 test_files_to_run = [
960 f for f in modified_files if f.startswith("tests") and f.split(os.path.sep)[-1].startswith("test")
961 ]
962 # Then we grab the corresponding test files.
963 test_map = create_module_to_test_map(reverse_map=reverse_map)
964 for f in modified_files:
965 if f in test_map:
966 test_files_to_run.extend(test_map[f])

Callers 1

tests_fetcher.pyFile · 0.85

Calls 8

_print_listFunction · 0.85
get_all_testsFunction · 0.85
create_json_mapFunction · 0.85
splitMethod · 0.80
existsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…