77
88import 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
1120def 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
243253def 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
255266def 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
271283def 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
282295def 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
295309def 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
306321def 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
316332def 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
337354def 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
344362def 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
355374def 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
367387def 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
383404def 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
402424def 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
439461def 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
480502def test_filestream_cache_atomic_no_half_written_file (tmp_path , monkeypatch ):
0 commit comments