"vscode:/vscode.git/clone" did not exist on "acbfaf69ccca28efbde397ec55ce9f2c4ee8b509"
Unverified Commit e8eb699e authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Properly get tests deps in test_fetcher (#17870)

* Properly get tests deps in test_fetcher

* Remove print
parent b03be78a
...@@ -226,20 +226,17 @@ def get_test_dependencies(test_fname): ...@@ -226,20 +226,17 @@ def get_test_dependencies(test_fname):
relative_imports = re.findall(r"from\s+(\.\S+)\s+import\s+([^\n]+)\n", content) relative_imports = re.findall(r"from\s+(\.\S+)\s+import\s+([^\n]+)\n", content)
relative_imports = [test for test, imp in relative_imports if "# tests_ignore" not in imp] relative_imports = [test for test, imp in relative_imports if "# tests_ignore" not in imp]
# Removes the double trailing '..' for parent imports, and creates an absolute path from the root dir with def _convert_relative_import_to_file(relative_import):
# `tests` as a prefix. level = 0
parent_imports = [imp.strip(".") for imp in relative_imports if ".." in imp] while relative_import.startswith("."):
parent_imports = [os.path.join("tests", f"{test.replace('.', os.path.sep)}.py") for test in parent_imports] level += 1
relative_import = relative_import[1:]
# Removes the single trailing '.' for current dir imports, and creates an absolute path from the root dir with
# tests/{module_name} as a prefix. directory = os.path.sep.join(test_fname.split(os.path.sep)[:-level])
current_dir_imports = [imp.strip(".") for imp in relative_imports if ".." not in imp] return os.path.join(directory, f"{relative_import.replace('.', os.path.sep)}.py")
directory = os.path.sep.join(test_fname.split(os.path.sep)[:-1])
current_dir_imports = [
os.path.join(directory, f"{test.replace('.', os.path.sep)}.py") for test in current_dir_imports
]
return [f for f in [*parent_imports, *current_dir_imports] if os.path.isfile(f)] dependencies = [_convert_relative_import_to_file(relative_import) for relative_import in relative_imports]
return [f for f in dependencies if os.path.isfile(os.path.join(PATH_TO_TRANFORMERS, f))]
def create_reverse_dependency_tree(): def create_reverse_dependency_tree():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment