Skip to content

Commit ec4c8ff

Browse files
committed
Fix missing StrEnum test
1 parent a4b84aa commit ec4c8ff

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

cuda_core/tests/test_enum_coverage.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
# mapping dicts at import time, so it runs on any CI host that has a
88
# compatible cuda.bindings version.
99

10-
import importlib
1110
import inspect
12-
import pkgutil
1311
import sys
1412
from typing import Any
1513

@@ -24,6 +22,8 @@
2422
else:
2523
from backports.strenum import StrEnum
2624

25+
_MODULES = [cuda.core.typing]
26+
2727
# Each entry is:
2828
# (cuda_binding_enum, str_enum, mapping_dict, binding_unmapped, str_enum_unmapped)
2929
#
@@ -51,6 +51,8 @@
5151
from cuda.bindings import nvml
5252
from cuda.core.system import _device, _system_events
5353

54+
_MODULES.append(system_typing)
55+
5456
_CASES.extend(
5557
[
5658
(
@@ -252,37 +254,27 @@ def test_wrapper_covers_all_binding_members(binding, str_enum, mapping, binding_
252254

253255

254256
@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):
256262
"""Every StrEnum subclass in cuda.core must appear in _CASES or _UNBOUND_STR_ENUMS.
257263
258264
This ensures that when a new StrEnum wrapper is added to cuda.core, the
259265
author is prompted to add a binding-coverage entry to _CASES (or explicitly
260266
declare it as unbound in _UNBOUND_STR_ENUMS).
261267
"""
262268

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)
283275

284276
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
286278
uncovered_names = sorted({c.__qualname__ for c in uncovered})
287279
assert not uncovered, (
288280
f"StrEnum subclasses in cuda.core not covered by _CASES: "

0 commit comments

Comments
 (0)