|
7 | 7 | # mapping dicts at import time, so it runs on any CI host that has a |
8 | 8 | # compatible cuda.bindings version. |
9 | 9 |
|
10 | | -import importlib |
11 | 10 | import inspect |
12 | | -import pkgutil |
13 | 11 | import sys |
14 | 12 | from typing import Any |
15 | 13 |
|
|
24 | 22 | else: |
25 | 23 | from backports.strenum import StrEnum |
26 | 24 |
|
| 25 | +_MODULES = [cuda.core.typing] |
| 26 | + |
27 | 27 | # Each entry is: |
28 | 28 | # (cuda_binding_enum, str_enum, mapping_dict, binding_unmapped, str_enum_unmapped) |
29 | 29 | # |
|
51 | 51 | from cuda.bindings import nvml |
52 | 52 | from cuda.core.system import _device, _system_events |
53 | 53 |
|
| 54 | + _MODULES.append(system_typing) |
| 55 | + |
54 | 56 | _CASES.extend( |
55 | 57 | [ |
56 | 58 | ( |
@@ -252,37 +254,27 @@ def test_wrapper_covers_all_binding_members(binding, str_enum, mapping, binding_ |
252 | 254 |
|
253 | 255 |
|
254 | 256 | @pytest.mark.skipif(sys.version_info < (3, 11), reason="Requires Python 3.11+ for StrEnum") |
255 | | -def test_all_str_enums_in_cases(): |
| 257 | +@pytest.mark.parametrize( |
| 258 | + "module", |
| 259 | + _MODULES, |
| 260 | +) |
| 261 | +def test_all_str_enums_in_cases(module): |
256 | 262 | """Every StrEnum subclass in cuda.core must appear in _CASES or _UNBOUND_STR_ENUMS. |
257 | 263 |
|
258 | 264 | This ensures that when a new StrEnum wrapper is added to cuda.core, the |
259 | 265 | author is prompted to add a binding-coverage entry to _CASES (or explicitly |
260 | 266 | declare it as unbound in _UNBOUND_STR_ENUMS). |
261 | 267 | """ |
262 | 268 |
|
263 | | - def discover_str_enums() -> set[type]: |
264 | | - """Walk all submodules of cuda.core and return every StrEnum subclass found.""" |
265 | | - found: set[type] = set() |
266 | | - for _, modname, _ in pkgutil.walk_packages( |
267 | | - path=cuda.core.__path__, |
268 | | - prefix=cuda.core.__name__ + ".", |
269 | | - onerror=lambda _: None, |
270 | | - ): |
271 | | - try: |
272 | | - mod = importlib.import_module(modname) |
273 | | - except Exception: # noqa |
274 | | - continue |
275 | | - try: |
276 | | - members = inspect.getmembers(mod, inspect.isclass) |
277 | | - except Exception: # noqa |
278 | | - continue |
279 | | - for _, obj in members: |
280 | | - if obj is not StrEnum and issubclass(obj, StrEnum): |
281 | | - found.add(obj) |
282 | | - return found |
| 269 | + found = set() |
| 270 | + |
| 271 | + members = inspect.getmembers(module, inspect.isclass) |
| 272 | + for _, obj in members: |
| 273 | + if obj is not StrEnum and issubclass(obj, StrEnum): |
| 274 | + found.add(obj) |
283 | 275 |
|
284 | 276 | covered = {x[1] for x in _CASES if x[1] is not None} |
285 | | - uncovered = discover_str_enums() - covered - _UNBOUND_STR_ENUMS |
| 277 | + uncovered = found - covered - _UNBOUND_STR_ENUMS |
286 | 278 | uncovered_names = sorted({c.__qualname__ for c in uncovered}) |
287 | 279 | assert not uncovered, ( |
288 | 280 | f"StrEnum subclasses in cuda.core not covered by _CASES: " |
|
0 commit comments