|
1 | 1 | import asyncio
|
2 | 2 | import atexit
|
3 |
| -import importlib |
4 | 3 | import os
|
5 | 4 | import platform
|
6 | 5 | import sys
|
7 | 6 | import tempfile
|
8 |
| -from collections.abc import Callable, Generator |
9 |
| -from dataclasses import dataclass |
| 7 | +from collections.abc import Generator |
10 | 8 | from pathlib import Path
|
11 |
| -from types import ModuleType |
12 | 9 |
|
13 | 10 | os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
14 | 11 |
|
@@ -86,67 +83,3 @@ async def protoc(
|
86 | 83 | )
|
87 | 84 | stdout, stderr = await proc.communicate()
|
88 | 85 | return stdout, stderr, proc.returncode
|
89 |
| - |
90 |
| - |
91 |
| -@dataclass |
92 |
| -class TestCaseJsonFile: |
93 |
| - json: str |
94 |
| - test_name: str |
95 |
| - file_name: str |
96 |
| - |
97 |
| - def belongs_to(self, non_symmetrical_json: dict[str, tuple[str, ...]]) -> bool: |
98 |
| - return self.file_name in non_symmetrical_json.get(self.test_name, ()) |
99 |
| - |
100 |
| - |
101 |
| -def get_test_case_json_data(test_case_name: str, *json_file_names: str) -> list[TestCaseJsonFile]: |
102 |
| - """ |
103 |
| - :return: |
104 |
| - A list of all files found in "{inputs_path}/test_case_name" with names matching |
105 |
| - f"{test_case_name}.json" or f"{test_case_name}_*.json", OR given by |
106 |
| - json_file_names |
107 |
| - """ |
108 |
| - test_case_dir = inputs_path.joinpath(test_case_name) |
109 |
| - possible_file_paths = [ |
110 |
| - *(test_case_dir.joinpath(json_file_name) for json_file_name in json_file_names), |
111 |
| - test_case_dir.joinpath(f"{test_case_name}.json"), |
112 |
| - *test_case_dir.glob(f"{test_case_name}_*.json"), |
113 |
| - ] |
114 |
| - |
115 |
| - result = [] |
116 |
| - for test_data_file_path in possible_file_paths: |
117 |
| - if not test_data_file_path.exists(): |
118 |
| - continue |
119 |
| - with test_data_file_path.open("r") as fh: |
120 |
| - result.append(TestCaseJsonFile(fh.read(), test_case_name, test_data_file_path.name.split(".")[0])) |
121 |
| - |
122 |
| - return result |
123 |
| - |
124 |
| - |
125 |
| -def find_module(module: ModuleType, predicate: Callable[[ModuleType], bool]) -> ModuleType | None: |
126 |
| - """ |
127 |
| - Recursively search module tree for a module that matches the search predicate. |
128 |
| - Assumes that the submodules are directories containing __init__.py. |
129 |
| -
|
130 |
| - Example: |
131 |
| -
|
132 |
| - # find module inside foo that contains Test |
133 |
| - import foo |
134 |
| - test_module = find_module(foo, lambda m: hasattr(m, 'Test')) |
135 |
| - """ |
136 |
| - if predicate(module): |
137 |
| - return module |
138 |
| - |
139 |
| - module_path = Path(*module.__path__) |
140 |
| - |
141 |
| - for sub in [sub.parent for sub in module_path.glob("**/__init__.py")]: |
142 |
| - if sub == module_path: |
143 |
| - continue |
144 |
| - sub_module_path = sub.relative_to(module_path) |
145 |
| - sub_module_name = ".".join(sub_module_path.parts) |
146 |
| - |
147 |
| - sub_module = importlib.import_module(f".{sub_module_name}", module.__name__) |
148 |
| - |
149 |
| - if predicate(sub_module): |
150 |
| - return sub_module |
151 |
| - |
152 |
| - return None |
0 commit comments