Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions openavmkit/utilities/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ def clear_cache(filename: str, filetype: str) -> None:
path = f"cache/{filename}"
if os.path.exists(f"{path}.{ext}"):
os.remove(f"{path}.{ext}")
if os.path.exists(f"{path}.cols{ext}"):
os.remove(f"{path}..cols.{ext}")
if os.path.exists(f"{path}.rows{ext}"):
os.remove(f"{path}.rows{ext}")
if os.path.exists(f"{path}.cols.{ext}"):
os.remove(f"{path}.cols.{ext}")
if os.path.exists(f"{path}.rows.{ext}"):
os.remove(f"{path}.rows.{ext}")
if os.path.exists(f"{path}.signature.json"):
os.remove(f"{path}.signature.json")
if os.path.exists(f"{path}.cols.signature.json"):
Expand Down
32 changes: 32 additions & 0 deletions tests/test_clear_cache_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os

from openavmkit.utilities.cache import clear_cache


def test_clear_cache_removes_cols_and_rows(tmp_path, monkeypatch):
"""clear_cache must remove the .cols / .rows fragments and their signatures.

Regression test: the path templates for the .cols/.rows data fragments were
malformed (missing dot in the existence check, double dot in the removal),
so clear_cache silently left the large .cols.parquet column-diff caches on
disk. Recreate every artifact a "df" cache entry produces and assert a clean
sweep.
"""
monkeypatch.chdir(tmp_path)
os.makedirs("cache", exist_ok=True)

artifacts = [
"foo.parquet",
"foo.cols.parquet",
"foo.rows.parquet",
"foo.signature.json",
"foo.cols.signature.json",
"foo.rows.signature.json",
]
for name in artifacts:
open(os.path.join("cache", name), "w").close()

clear_cache("foo", "df")

for name in artifacts:
assert not os.path.exists(os.path.join("cache", name)), f"{name} was not removed"
Loading