|
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,43 +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 find_module(module: ModuleType, predicate: Callable[[ModuleType], bool]) -> ModuleType | None: |
102 |
| - """ |
103 |
| - Recursively search module tree for a module that matches the search predicate. |
104 |
| - Assumes that the submodules are directories containing __init__.py. |
105 |
| -
|
106 |
| - Example: |
107 |
| -
|
108 |
| - # find module inside foo that contains Test |
109 |
| - import foo |
110 |
| - test_module = find_module(foo, lambda m: hasattr(m, 'Test')) |
111 |
| - """ |
112 |
| - if predicate(module): |
113 |
| - return module |
114 |
| - |
115 |
| - module_path = Path(*module.__path__) |
116 |
| - |
117 |
| - for sub in [sub.parent for sub in module_path.glob("**/__init__.py")]: |
118 |
| - if sub == module_path: |
119 |
| - continue |
120 |
| - sub_module_path = sub.relative_to(module_path) |
121 |
| - sub_module_name = ".".join(sub_module_path.parts) |
122 |
| - |
123 |
| - sub_module = importlib.import_module(f".{sub_module_name}", module.__name__) |
124 |
| - |
125 |
| - if predicate(sub_module): |
126 |
| - return sub_module |
127 |
| - |
128 |
| - return None |
0 commit comments