From c52d3f9ec3569eca432ee7df3ec90a2a39a45469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bournhonesque?= Date: Tue, 31 Oct 2023 17:49:05 +0100 Subject: [PATCH] fix: use distinct cache for test assets --- .gitignore | 4 ++-- docker-compose.yml | 1 + docker/dev.yml | 1 + robotoff/settings.py | 8 ++++++-- tests/unit/pytest_utils.py | 8 +++++++- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3817e9033f..f64adb53a4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ dist .idea robotoff.egg-info ml/data/* +cache datasets *.joblib .ipynb_checkpoints @@ -41,5 +42,4 @@ coverage.xml site/ gh_pages/ doc/README.md -doc/references/cli.md -data/diskcache \ No newline at end of file +doc/references/cli.md diff --git a/docker-compose.yml b/docker-compose.yml index 19de964b07..f8f22bfcd1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/docker/dev.yml b/docker/dev.yml index 12e1836320..e90de3fa1e 100644 --- a/docker/dev.yml +++ b/docker/dev.yml @@ -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 diff --git a/robotoff/settings.py b/robotoff/settings.py index b44471cd07..3282b69403 100644 --- a/robotoff/settings.py +++ b/robotoff/settings.py @@ -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" @@ -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" diff --git a/tests/unit/pytest_utils.py b/tests/unit/pytest_utils.py index 42fa746303..8885f0190b 100644 --- a/tests/unit/pytest_utils.py +++ b/tests/unit/pytest_utils.py @@ -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. @@ -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: