11import os
22from itertools import chain
3+ from pathlib import Path
34from typing import Any , Dict , Iterable , Mapping , Tuple
45
56import httpx
67import pytest
78from pydantic import HttpUrl
89
9- from bioimageio .spec import InvalidDescr
10+ from bioimageio .spec import InvalidDescr , settings
1011from bioimageio .spec .common import Sha256
1112from 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 ()))
161174def 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