Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit b5a4314

Browse files
Simplify the tests compilation (#60)
* Remove useless function * Remove useless code
1 parent a2ce5a2 commit b5a4314

File tree

1 file changed

+1
-68
lines changed

1 file changed

+1
-68
lines changed

tests/util.py

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import asyncio
22
import atexit
3-
import importlib
43
import os
54
import platform
65
import sys
76
import tempfile
8-
from collections.abc import Callable, Generator
9-
from dataclasses import dataclass
7+
from collections.abc import Generator
108
from pathlib import Path
11-
from types import ModuleType
129

1310
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
1411

@@ -86,67 +83,3 @@ async def protoc(
8683
)
8784
stdout, stderr = await proc.communicate()
8885
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

Comments
 (0)