The test examples do not import from the examples (which are just scripts, not modules) so we need some extra care initializing the dependency map, which is the goal of this function. It initializes the dependency map for example files by linking each example to the example test file fo
()
| 691 | |
| 692 | |
| 693 | def init_test_examples_dependencies() -> Tuple[Dict[str, List[str]], List[str]]: |
| 694 | """ |
| 695 | The test examples do not import from the examples (which are just scripts, not modules) so we need some extra |
| 696 | care initializing the dependency map, which is the goal of this function. It initializes the dependency map for |
| 697 | example files by linking each example to the example test file for the example framework. |
| 698 | |
| 699 | Returns: |
| 700 | `Tuple[Dict[str, List[str]], List[str]]`: A tuple with two elements: the initialized dependency map which is a |
| 701 | dict test example file to list of example files potentially tested by that test file, and the list of all |
| 702 | example files (to avoid recomputing it later). |
| 703 | """ |
| 704 | test_example_deps = {} |
| 705 | all_examples = [] |
| 706 | for framework in ["flax", "pytorch", "tensorflow"]: |
| 707 | test_files = list((PATH_TO_EXAMPLES / framework).glob("test_*.py")) |
| 708 | all_examples.extend(test_files) |
| 709 | # Remove the files at the root of examples/framework since they are not proper examples (they are either utils |
| 710 | # or example test files). |
| 711 | examples = [ |
| 712 | f for f in (PATH_TO_EXAMPLES / framework).glob("**/*.py") if f.parent != PATH_TO_EXAMPLES / framework |
| 713 | ] |
| 714 | all_examples.extend(examples) |
| 715 | for test_file in test_files: |
| 716 | with open(test_file, "r", encoding="utf-8") as f: |
| 717 | content = f.read() |
| 718 | # Map all examples to the test files found in examples/framework. |
| 719 | test_example_deps[str(test_file.relative_to(PATH_TO_REPO))] = [ |
| 720 | str(e.relative_to(PATH_TO_REPO)) for e in examples if e.name in content |
| 721 | ] |
| 722 | # Also map the test files to themselves. |
| 723 | test_example_deps[str(test_file.relative_to(PATH_TO_REPO))].append( |
| 724 | str(test_file.relative_to(PATH_TO_REPO)) |
| 725 | ) |
| 726 | return test_example_deps, all_examples |
| 727 | |
| 728 | |
| 729 | def create_reverse_dependency_map() -> dict[str, List[str]]: |
no outgoing calls
no test coverage detected
searching dependent graphs…