Skip to content

Commit f08a728

Browse files
committed
skip cache population if size limit hit
1 parent 0dbe380 commit f08a728

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test_bioimageio_collection.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
from itertools import chain
3+
from pathlib import Path
34
from typing import Any, Dict, Iterable, Mapping, Tuple
45

56
import httpx
67
import pytest
78
from pydantic import HttpUrl
89

9-
from bioimageio.spec import InvalidDescr
10+
from bioimageio.spec import InvalidDescr, settings
1011
from bioimageio.spec.common import Sha256
1112
from tests.utils import ParameterSet, expensive_test
1213

@@ -157,6 +158,18 @@ def yield_bioimageio_yaml_urls() -> Iterable[ParameterSet]:
157158
}
158159

159160

161+
def get_directory_size(path: Path):
162+
total_size = 0
163+
for dirpath, _, filenames in os.walk(path):
164+
for f in filenames:
165+
fp = os.path.join(dirpath, f)
166+
# skip if it is symbolic link
167+
if not os.path.islink(fp):
168+
total_size += os.path.getsize(fp)
169+
170+
return total_size
171+
172+
160173
@pytest.mark.parametrize("descr_url,sha,key", list(yield_bioimageio_yaml_urls()))
161174
def test_rdf_format_to_populate_cache(
162175
descr_url: HttpUrl,
@@ -170,6 +183,9 @@ def test_rdf_format_to_populate_cache(
170183
if key in KNOWN_INVALID:
171184
pytest.skip(KNOWN_INVALID[key])
172185

186+
if (cache_size := get_directory_size(settings.cache_path)) > 8e9:
187+
pytest.skip(f"reached 8GB cache size limit ({cache_size / 1e9:.2f} GB)")
188+
173189
from bioimageio.core import load_description
174190

175191
_ = load_description(descr_url, sha256=sha, perform_io_checks=True)

0 commit comments

Comments
 (0)