Skip to content

Commit

Permalink
fix: use distinct cache for test assets
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Nov 2, 2023
1 parent bf4632f commit c52d3f9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dist
.idea
robotoff.egg-info
ml/data/*
cache
datasets
*.joblib
.ipynb_checkpoints
Expand Down Expand Up @@ -41,5 +42,4 @@ coverage.xml
site/
gh_pages/
doc/README.md
doc/references/cli.md
data/diskcache
doc/references/cli.md
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.9"
x-robotoff-base-volumes:
&robotoff-base-volumes
- ./data:/opt/robotoff/data
- ./cache:/opt/robotoff/cache
- ./datasets:/opt/robotoff/datasets
- ./tf_models:/opt/robotoff/tf_models
- ./models:/opt/robotoff/models
Expand Down
1 change: 1 addition & 0 deletions docker/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ x-robotoff-dev: &robotoff-dev
- ./i18n:/opt/robotoff/i18n
# make data available
- ./data:/opt/robotoff/data
- ./cache:/opt/robotoff/cache
# make migration files available
- ./migrations:/opt/robotoff/migrations
# make doc generation available
Expand Down
8 changes: 6 additions & 2 deletions robotoff/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def event_api() -> str:

PROJECT_DIR = Path(__file__).parent.parent
DATA_DIR = PROJECT_DIR / "data"
CACHE_DIR = PROJECT_DIR / "cache"
DATASET_DIR = PROJECT_DIR / "datasets"
DATASET_DIR.mkdir(exist_ok=True)
I18N_DIR = PROJECT_DIR / "i18n"
Expand Down Expand Up @@ -338,5 +339,8 @@ def get_package_version() -> str:
MIGRATE_DIR = PROJECT_DIR / "migrations"


# Path of the local disk cache, see robotoff.cache for more information
DISKCACHE_DIR = DATA_DIR / "diskcache"
# Path of the main local disk cache, see robotoff.cache for more information
DISKCACHE_DIR = CACHE_DIR / "diskcache"

# Path of the local disk cache used for tests
TESTS_DISKCACHE_DIR = CACHE_DIR / "diskcache_tests_assets"
8 changes: 7 additions & 1 deletion tests/unit/pytest_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import json

from diskcache import Cache
from openfoodfacts import OCRResult

from robotoff import settings
from robotoff.utils.download import cache_asset_from_url

test_cache = Cache(settings.TESTS_DISKCACHE_DIR)


def get_asset(asset_path: str) -> bytes | None:
"""Get an asset from the test-data repository.
Expand All @@ -15,7 +19,9 @@ def get_asset(asset_path: str) -> bytes | None:
fetched
"""
asset_url = f"https://raw.githubusercontent.com/openfoodfacts/test-data{asset_path}"
return cache_asset_from_url(key=asset_url, tag="test", asset_url=asset_url)
return cache_asset_from_url(
key=asset_url, cache=test_cache, tag="test", asset_url=asset_url
)


def get_ocr_result_asset(asset_path: str) -> OCRResult | None:
Expand Down

0 comments on commit c52d3f9

Please sign in to comment.