-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: 💍 add a test about the cache reports
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from datasets_preview_backend.cache_reports import get_kwargs_report | ||
from datasets_preview_backend.config import CACHE_DIRECTORY, CACHE_PERSIST | ||
from datasets_preview_backend.responses import get_cached_response | ||
|
||
|
||
def test_cache_directory() -> None: | ||
# ensure the cache directory is empty, so that this file gets an empty cache | ||
assert CACHE_DIRECTORY is None | ||
assert not CACHE_PERSIST | ||
# note that the same cache is used all over this file. We might want to call | ||
# http://www.grantjenks.com/docs/diskcache/api.html#diskcache.Cache.clear | ||
# at the beginning of every test to start with an empty cache | ||
|
||
|
||
def test_get_kwargs_report_error() -> None: | ||
endpoint = "/configs" | ||
kwargs = {"dataset": "doesnotexist"} | ||
|
||
report = get_kwargs_report(endpoint, kwargs) | ||
assert report["status"] == "cache_miss" | ||
|
||
# warm the cache | ||
get_cached_response(endpoint, **kwargs) | ||
report = get_kwargs_report(endpoint, kwargs) | ||
assert report["status"] == "error" | ||
|
||
report = get_kwargs_report(endpoint, kwargs) | ||
assert report["status"] == "error" |