Skip to content

Commit cd10cc9

Browse files
cpcloudclaude
andcommitted
Fix test failures: use public API + skip sqlite when unavailable
- Replace private Cython attrs (_module/_name/_code_type) with public properties (code/name/code_type) — cdef attrs not accessible from Python - Add @needs_sqlite3 skip decorator for sqlite tests when libsqlite3 is missing from CI containers Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4fffc19 commit cd10cc9

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

cuda_core/tests/test_program_cache.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
import pytest
99

10+
try:
11+
import sqlite3 # noqa: F401
12+
13+
_has_sqlite3 = True
14+
except ImportError:
15+
_has_sqlite3 = False
16+
17+
needs_sqlite3 = pytest.mark.skipif(not _has_sqlite3, reason="libsqlite3 not available")
18+
1019

1120
def test_program_cache_resource_is_abstract():
1221
from cuda.core.utils import ProgramCacheResource
@@ -240,6 +249,7 @@ def _fake_object_code(payload: bytes = b"fake-cubin", name: str = "unit"):
240249
return ObjectCode._init(payload, "cubin", name=name)
241250

242251

252+
@needs_sqlite3
243253
def test_sqlite_cache_empty_on_create(tmp_path):
244254
from cuda.core.utils import SQLiteProgramCache
245255

@@ -252,6 +262,7 @@ def test_sqlite_cache_empty_on_create(tmp_path):
252262
assert cache.get(b"nope") is None
253263

254264

265+
@needs_sqlite3
255266
def test_sqlite_cache_set_get_roundtrip(tmp_path):
256267
from cuda.core.utils import SQLiteProgramCache
257268

@@ -263,11 +274,12 @@ def test_sqlite_cache_set_get_roundtrip(tmp_path):
263274
assert key in cache
264275
assert len(cache) == 1
265276
got = cache[key]
266-
assert bytes(got._module) == b"bytes-1"
267-
assert got._name == "a"
268-
assert got._code_type == "cubin"
277+
assert bytes(got.code) == b"bytes-1"
278+
assert got.name == "a"
279+
assert got.code_type == "cubin"
269280

270281

282+
@needs_sqlite3
271283
def test_sqlite_cache_overwrite_same_key(tmp_path):
272284
from cuda.core.utils import SQLiteProgramCache
273285

@@ -276,9 +288,10 @@ def test_sqlite_cache_overwrite_same_key(tmp_path):
276288
cache[b"k"] = _fake_object_code(b"v1")
277289
cache[b"k"] = _fake_object_code(b"v2")
278290
assert len(cache) == 1
279-
assert bytes(cache[b"k"]._module) == b"v2"
291+
assert bytes(cache[b"k"].code) == b"v2"
280292

281293

294+
@needs_sqlite3
282295
def test_sqlite_cache_delete(tmp_path):
283296
from cuda.core.utils import SQLiteProgramCache
284297

@@ -292,6 +305,7 @@ def test_sqlite_cache_delete(tmp_path):
292305
del cache[b"k"]
293306

294307

308+
@needs_sqlite3
295309
def test_sqlite_cache_clear(tmp_path):
296310
from cuda.core.utils import SQLiteProgramCache
297311

@@ -303,16 +317,18 @@ def test_sqlite_cache_clear(tmp_path):
303317
assert len(cache) == 0
304318

305319

320+
@needs_sqlite3
306321
def test_sqlite_cache_persists_across_open(tmp_path):
307322
from cuda.core.utils import SQLiteProgramCache
308323

309324
db = tmp_path / "cache.db"
310325
with SQLiteProgramCache(db) as cache:
311326
cache[b"k"] = _fake_object_code(b"persisted")
312327
with SQLiteProgramCache(db) as cache:
313-
assert bytes(cache[b"k"]._module) == b"persisted"
328+
assert bytes(cache[b"k"].code) == b"persisted"
314329

315330

331+
@needs_sqlite3
316332
def test_sqlite_cache_corruption_is_reported_as_miss(tmp_path):
317333
import sqlite3
318334

@@ -334,13 +350,15 @@ def test_sqlite_cache_corruption_is_reported_as_miss(tmp_path):
334350
assert b"k" not in cache # corrupt entry was pruned
335351

336352

353+
@needs_sqlite3
337354
def test_sqlite_cache_rejects_non_object_code(tmp_path):
338355
from cuda.core.utils import SQLiteProgramCache
339356

340357
with SQLiteProgramCache(tmp_path / "cache.db") as cache, pytest.raises(TypeError, match="ObjectCode"):
341358
cache[b"k"] = b"not an ObjectCode"
342359

343360

361+
@needs_sqlite3
344362
def test_sqlite_cache_accepts_str_keys(tmp_path):
345363
from cuda.core.utils import SQLiteProgramCache
346364

@@ -352,6 +370,7 @@ def test_sqlite_cache_accepts_str_keys(tmp_path):
352370
assert b"str-key" in cache
353371

354372

373+
@needs_sqlite3
355374
def test_sqlite_cache_rejects_negative_size_cap(tmp_path):
356375
from cuda.core.utils import SQLiteProgramCache
357376

@@ -364,6 +383,7 @@ def test_sqlite_cache_rejects_negative_size_cap(tmp_path):
364383
# ---------------------------------------------------------------------------
365384

366385

386+
@needs_sqlite3
367387
def test_sqlite_cache_evicts_under_size_cap(tmp_path):
368388
from cuda.core.utils import SQLiteProgramCache
369389

@@ -380,6 +400,7 @@ def test_sqlite_cache_evicts_under_size_cap(tmp_path):
380400
assert b"c" in cache
381401

382402

403+
@needs_sqlite3
383404
def test_sqlite_cache_lru_order_respects_reads(tmp_path):
384405
from cuda.core.utils import SQLiteProgramCache
385406

@@ -399,6 +420,7 @@ def test_sqlite_cache_lru_order_respects_reads(tmp_path):
399420
assert b"c" in cache
400421

401422

423+
@needs_sqlite3
402424
def test_sqlite_cache_unbounded_by_default(tmp_path):
403425
from cuda.core.utils import SQLiteProgramCache
404426

@@ -431,9 +453,9 @@ def test_filestream_cache_roundtrip(tmp_path):
431453
cache[b"k1"] = _fake_object_code(b"v1", name="x")
432454
assert b"k1" in cache
433455
got = cache[b"k1"]
434-
assert bytes(got._module) == b"v1"
435-
assert got._name == "x"
436-
assert got._code_type == "cubin"
456+
assert bytes(got.code) == b"v1"
457+
assert got.name == "x"
458+
assert got.code_type == "cubin"
437459

438460

439461
def test_filestream_cache_delete(tmp_path):
@@ -474,7 +496,7 @@ def test_filestream_cache_persists_across_reopen(tmp_path):
474496
with FileStreamProgramCache(root) as cache:
475497
cache[b"k"] = _fake_object_code(b"persisted")
476498
with FileStreamProgramCache(root) as cache:
477-
assert bytes(cache[b"k"]._module) == b"persisted"
499+
assert bytes(cache[b"k"].code) == b"persisted"
478500

479501

480502
def test_filestream_cache_atomic_no_half_written_file(tmp_path, monkeypatch):

cuda_core/tests/test_program_cache_multiprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_concurrent_writers_same_key_no_corruption(tmp_path):
6262

6363
with FileStreamProgramCache(root) as cache:
6464
got = cache[b"shared"] # must not raise; payload is one of the writers'
65-
assert bytes(got._module).startswith(b"v")
65+
assert bytes(got.code).startswith(b"v")
6666

6767

6868
def test_concurrent_writers_distinct_keys_all_survive(tmp_path):

0 commit comments

Comments
 (0)