Skip to content

Commit

Permalink
fix: Update cache response retrieval to include name parameter and ad…
Browse files Browse the repository at this point in the history
…just CI environment
  • Loading branch information
jjjermiah committed Dec 10, 2024
1 parent 49d0eac commit e1b5577
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, macos-14] # , windows-latest removed for now
env: ["py310", "py311", "py312"]
env: ["py311", "py312"]

steps:
- uses: actions/checkout@v4
Expand Down
12 changes: 6 additions & 6 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_cache_file_creation(cache_instance, cache_dir, sample_data):
def test_get_cached_response_valid(cache_instance, sample_data):
"""Test that a valid cache is returned."""
cache_instance.cache_response(sample_data)
response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response == sample_data, "Cached response does not match the expected data."

def test_get_cached_response_outdated(cache_instance, cache_file, sample_data):
Expand All @@ -49,12 +49,12 @@ def test_get_cached_response_outdated(cache_instance, cache_file, sample_data):
with cache_file.open("w") as f:
json.dump({"date": outdated_date, "data": sample_data}, f)

response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response is None, "Outdated cache should return None."

def test_get_cached_response_missing_file(cache_instance):
"""Test that a missing cache file returns None."""
response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response is None, "Missing cache file should return None."

def test_get_cached_response_invalid_json(cache_instance, cache_file):
Expand All @@ -63,7 +63,7 @@ def test_get_cached_response_invalid_json(cache_instance, cache_file):
with cache_file.open("w") as f:
f.write("{invalid_json}")

response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response is None, "Invalid JSON in the cache should return None."

def test_cache_file_outdated_handling(cache_instance, cache_file, sample_data, caplog):
Expand All @@ -74,7 +74,7 @@ def test_cache_file_outdated_handling(cache_instance, cache_file, sample_data, c
with cache_file.open("w") as f:
json.dump({"date": outdated_date, "data": sample_data}, f)

response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response is None, "Outdated cache should return None."

assert any("Cache is outdated" in record.message for record in caplog.records), \
Expand All @@ -84,7 +84,7 @@ def test_cache_file_logging(cache_instance, sample_data, caplog):
"""Test that logging occurs when using a valid cache."""
caplog.set_level("INFO")
cache_instance.cache_response(sample_data)
response = cache_instance.get_cached_response()
response = cache_instance.get_cached_response(name="Test")
assert response == sample_data, "Cached response does not match the expected data."

assert any("Using cached response" in record.message for record in caplog.records), \
Expand Down

0 comments on commit e1b5577

Please sign in to comment.