Skip to content

Commit

Permalink
fix: fix cache tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gventuri committed Jun 5, 2023
1 parent 7a7c5f1 commit 7d2cb97
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ pandasai.egg-info
.idea

# cache
cache.db

# cache
cache.db
cache_*.db
7 changes: 7 additions & 0 deletions pandasai/helpers/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Cache module for caching queries."""

import os
import shelve


Expand Down Expand Up @@ -55,3 +56,9 @@ def clear(self) -> None:
"""Clean the cache."""

self.cache.clear()

def destroy(self) -> None:
"""Destroy the cache."""

self.cache.close()
os.remove(self.filename + ".db")
7 changes: 6 additions & 1 deletion tests/helpers/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import uuid

from pandasai.helpers.cache import Cache


class TestCache:
def test_cache(self):
cache = Cache()
cache_filename = f"cache_{uuid.uuid4().hex}"
cache = Cache(filename=cache_filename)
cache.set("key", "value")
assert cache.get("key") == "value"

cache.delete("key")
print(cache.get("key"))
assert cache.get("key") is None

cache.destroy()

0 comments on commit 7d2cb97

Please sign in to comment.