MCPcopy Index your code
hub / github.com/RustPython/RustPython / find_dependent_tests_tree

Function find_dependent_tests_tree

scripts/update_lib/deps.py:1599–1704  ·  view source on GitHub ↗

Find dependent tests in a tree structure. Args: module_name: Module to search for (e.g., "ftplib") lib_prefix: RustPython Lib directory max_depth: Maximum depth to recurse (default 1 = show direct + 1 level of Lib deps) Returns: Dict with structure:

(
    module_name: str,
    lib_prefix: str,
    max_depth: int = 1,
    _depth: int = 0,
    _visited_tests: set[str] | None = None,
    _visited_modules: set[str] | None = None,
)

Source from the content-addressed store, hash-verified

1597
1598
1599def find_dependent_tests_tree(
1600 module_name: str,
1601 lib_prefix: str,
1602 max_depth: int = 1,
1603 _depth: int = 0,
1604 _visited_tests: set[str] | None = None,
1605 _visited_modules: set[str] | None = None,
1606) -> dict:
1607 """Find dependent tests in a tree structure.
1608
1609 Args:
1610 module_name: Module to search for (e.g., "ftplib")
1611 lib_prefix: RustPython Lib directory
1612 max_depth: Maximum depth to recurse (default 1 = show direct + 1 level of Lib deps)
1613
1614 Returns:
1615 Dict with structure:
1616 {
1617 "module": "ftplib",
1618 "tests": ["test_ftplib", "test_urllib2"], # Direct importers
1619 "children": [
1620 {"module": "urllib.request", "tests": [...], "children": []},
1621 ...
1622 ]
1623 }
1624 """
1625 lib_dir = pathlib.Path(lib_prefix)
1626 test_dir = lib_dir / "test"
1627
1628 if _visited_tests is None:
1629 _visited_tests = set()
1630 if _visited_modules is None:
1631 _visited_modules = set()
1632
1633 # Build graphs
1634 test_import_graph, test_lib_imports = _build_test_import_graph(test_dir)
1635 lib_import_graph = _build_lib_import_graph(lib_prefix)
1636
1637 # Find tests that directly import this module
1638 target_top = module_name.split(".")[0]
1639 direct_tests: set[str] = set()
1640 for file_key, imports in test_lib_imports.items():
1641 if file_key in _visited_tests:
1642 continue
1643 # Match exact module OR any child submodule
1644 # e.g., "xml" matches imports of "xml", "xml.parsers", "xml.etree.ElementTree"
1645 # but "collections._defaultdict" only matches "collections._defaultdict" (no children)
1646 matches = any(
1647 imp == module_name or imp.startswith(module_name + ".") for imp in imports
1648 )
1649 if matches:
1650 # Check if it's a test file
1651 if pathlib.Path(file_key).name.startswith("test_"):
1652 direct_tests.add(file_key)
1653 _visited_tests.add(file_key)
1654
1655 # Consolidate test names (test_sqlite3/test_dbapi -> test_sqlite3)
1656 consolidated_tests = {_consolidate_file_key(t) for t in direct_tests}

Callers 1

format_depsFunction · 0.90

Calls 13

setFunction · 0.85
_build_test_import_graphFunction · 0.85
_build_lib_import_graphFunction · 0.85
_consolidate_file_keyFunction · 0.85
_consolidate_submodulesFunction · 0.85
sortedFunction · 0.85
anyFunction · 0.50
splitMethod · 0.45
itemsMethod · 0.45
startswithMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected