-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Properly cache svg files in
svg_path
(#5)
* properly cache in svg_path * style(pre-commit.ci): auto fixes [...] * fix typo * style(pre-commit.ci): auto fixes [...] * add test * style(pre-commit.ci): auto fixes [...] * update docs and test --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Talley Lambert <[email protected]>
- Loading branch information
1 parent
548bc81
commit 5a9f864
Showing
4 changed files
with
77 additions
and
13 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
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
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 |
---|---|---|
@@ -1,13 +1,21 @@ | ||
from pathlib import Path | ||
from typing import Iterator | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from pyconify import _cache, api | ||
from pyconify import get_cache_directory | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def no_cache(tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]: | ||
tmp = tmp_path_factory.mktemp("pyconify") | ||
TEST_CACHE = _cache._SVGCache(directory=tmp) | ||
with patch.object(api, "svg_cache", lambda: TEST_CACHE): | ||
def ensure_no_cache() -> Iterator[None]: | ||
"""Ensure that tests don't modify the user cache.""" | ||
cache_dir = Path(get_cache_directory()) | ||
exists = cache_dir.exists() | ||
if exists: | ||
# get hash of cache directory | ||
cache_hash = hash(tuple(cache_dir.rglob("*"))) | ||
try: | ||
yield | ||
finally: | ||
assert cache_dir.exists() == exists, "Cache directory was created or deleted" | ||
if exists and cache_hash != hash(tuple(cache_dir.rglob("*"))): | ||
raise AssertionError("User Cache directory was modified") |
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