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

Function lib_to_test_path

scripts/update_lib/file_utils.py:87–121  ·  view source on GitHub ↗

Convert library path to test path. Examples: cpython/Lib/dataclasses.py -> cpython/Lib/test/test_dataclasses/ cpython/Lib/json/__init__.py -> cpython/Lib/test/test_json/

(src_path: pathlib.Path)

Source from the content-addressed store, hash-verified

85
86
87def lib_to_test_path(src_path: pathlib.Path) -> pathlib.Path:
88 """
89 Convert library path to test path.
90
91 Examples:
92 cpython/Lib/dataclasses.py -> cpython/Lib/test/test_dataclasses/
93 cpython/Lib/json/__init__.py -> cpython/Lib/test/test_json/
94 """
95 path_str = str(src_path).replace("\\", "/")
96 lib_marker = "/Lib/"
97
98 if lib_marker in path_str:
99 lib_path = parse_lib_path(src_path)
100 lib_name = lib_path.stem if lib_path.suffix == ".py" else lib_path.name
101 if lib_name == "__init__":
102 lib_name = lib_path.parent.name
103 prefix = path_str[: path_str.index(lib_marker)]
104 dir_path = pathlib.Path(f"{prefix}/Lib/test/test_{lib_name}/")
105 if dir_path.exists():
106 return dir_path
107 file_path = pathlib.Path(f"{prefix}/Lib/test/test_{lib_name}.py")
108 if file_path.exists():
109 return file_path
110 return dir_path
111 else:
112 lib_name = src_path.stem if src_path.suffix == ".py" else src_path.name
113 if lib_name == "__init__":
114 lib_name = src_path.parent.name
115 dir_path = pathlib.Path(f"Lib/test/test_{lib_name}/")
116 if dir_path.exists():
117 return dir_path
118 file_path = pathlib.Path(f"Lib/test/test_{lib_name}.py")
119 if file_path.exists():
120 return file_path
121 return dir_path
122
123
124def get_test_files(path: pathlib.Path) -> list[pathlib.Path]:

Calls 5

existsMethod · 0.95
strFunction · 0.85
parse_lib_pathFunction · 0.85
replaceMethod · 0.45
indexMethod · 0.45