Skip to content

Commit 4407cef

Browse files
committed
fixup! test(core.utils): regression tests for __dir__ and as_bytes TypeError propagation
1 parent e5f23e6 commit 4407cef

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

cuda_core/tests/test_program_cache.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,20 @@ def test_cuda_core_utils_memoryview_import_is_lightweight(tmp_path):
141141
subprocess.run([sys.executable, "-c", prog], check=True, cwd=str(tmp_path)) # noqa: S603
142142

143143

144+
def test_cuda_core_utils_dir_includes_lazy_and_module_attrs():
145+
"""``dir(cuda.core.utils)`` must surface BOTH the lazy public API AND
146+
the regular module attributes (``__file__``, ``__spec__``, ...). The
147+
package's ``__dir__`` is custom to coexist with the lazy ``__getattr__``
148+
shim and has regressed here before."""
149+
import cuda.core.utils as u
150+
151+
names = dir(u)
152+
assert "make_program_cache_key" in names
153+
assert "StridedMemoryView" in names
154+
assert "__file__" in names
155+
assert "__spec__" in names
156+
157+
144158
# ---------------------------------------------------------------------------
145159
# make_program_cache_key
146160
# ---------------------------------------------------------------------------
@@ -170,6 +184,20 @@ def test_make_program_cache_key_returns_bytes():
170184
assert len(key) == 32
171185

172186

187+
def test_make_program_cache_key_propagates_as_bytes_typeerror(monkeypatch):
188+
"""A ``TypeError`` out of ``ProgramOptions.as_bytes`` must propagate --
189+
regressing this to a silent retry/fallback would mint cache keys for
190+
inputs the real compile path rejects."""
191+
options = _opts()
192+
193+
def _boom(*args, **kwargs):
194+
raise TypeError("boom")
195+
196+
monkeypatch.setattr(options, "as_bytes", _boom)
197+
with pytest.raises(TypeError, match="boom"):
198+
_make_key(options=options)
199+
200+
173201
@pytest.mark.parametrize("code_type, code", [("c++", "void k(){}"), ("ptx", ".version 7.0")])
174202
def test_make_program_cache_key_is_deterministic(code_type, code):
175203
assert _make_key(code=code, code_type=code_type) == _make_key(code=code, code_type=code_type)

0 commit comments

Comments
 (0)