funkycache 1.0.5__tar.gz → 1.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funkycache
3
- Version: 1.0.5
3
+ Version: 1.0.6
4
4
  Summary: A SQLite-backed function cache that tracks file dependencies
5
5
  Author-email: Alex Chan <alex@alexwlchan.net>
6
6
  Maintainer-email: Alex Chan <alex@alexwlchan.net>
@@ -347,6 +347,16 @@ class LazyCacheStorage[V](CacheStorage[V]):
347
347
  self._underlying = self._create_underlying()
348
348
  return self._underlying.get(key)
349
349
 
350
+ def close(self) -> None:
351
+ """
352
+ Close the underlying storage.
353
+ """
354
+ if self._underlying is None:
355
+ pass
356
+ if not hasattr(self._underlying, "close"):
357
+ return
358
+ self._underlying.close() # type: ignore
359
+
350
360
 
351
361
  def _encode_key_as_json(key: dict[str, Any]) -> str:
352
362
  """
@@ -2,4 +2,4 @@
2
2
  The FunkyCache version.
3
3
  """
4
4
 
5
- __version__ = "1.0.5"
5
+ __version__ = "1.0.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funkycache
3
- Version: 1.0.5
3
+ Version: 1.0.6
4
4
  Summary: A SQLite-backed function cache that tracks file dependencies
5
5
  Author-email: Alex Chan <alex@alexwlchan.net>
6
6
  Maintainer-email: Alex Chan <alex@alexwlchan.net>
@@ -709,6 +709,34 @@ class TestFunkyCache:
709
709
  assert greet("Alex") == "Bonjour Alex!"
710
710
  assert calls == {"Alex": 2}
711
711
 
712
+ def test_lazy_sqlite_cache(self, tmp_path: Path) -> None:
713
+ """
714
+ If you cache a function with SQLite but never call it, the underlying
715
+ database is never created.
716
+
717
+ This is a regression test for a bug in v1.0.5 where closing the
718
+ storage would create the database.
719
+ """
720
+ p = tmp_path / "example.py"
721
+
722
+ p.write_text(
723
+ textwrap.dedent("""
724
+ from funkycache import FunkyCache
725
+
726
+ GREETING = "hello world"
727
+
728
+ cache = FunkyCache(storage="sqlite", root=".cache")
729
+
730
+ @cache.register
731
+ def greet() -> str:
732
+ return GREETING
733
+ """)
734
+ )
735
+
736
+ subprocess.check_call(["python3", str(p)], cwd=tmp_path)
737
+
738
+ assert not (tmp_path / ".cache").exists()
739
+
712
740
 
713
741
  class TestMemoryFunkyCache(FunkyCacheTestSuite):
714
742
  """
@@ -289,8 +289,9 @@ class LazyCacheStorageTestSuite(CacheStorageTestSuite):
289
289
  assert isinstance(storage, LazyCacheStorage)
290
290
  assert storage._underlying is None
291
291
 
292
- with pytest.raises(AttributeError):
293
- getattr(storage, "does_not_exist")
292
+ for name in ("does_not_exist1", "does_not_exist2", "does_not_exist3"):
293
+ with pytest.raises(AttributeError):
294
+ getattr(storage, name)
294
295
 
295
296
  assert storage._underlying is not None
296
297
 
File without changes
File without changes
File without changes
File without changes