Skip to content

Commit

Permalink
Make function name explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
avbentem committed Jul 7, 2024
1 parent b7f22c3 commit 03f0873
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions stac_pydantic/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@lru_cache(maxsize=128)
def _fetch_schema(url: str) -> dict:
def _fetch_and_cache_schema(url: str) -> dict:
"""Fetch the remote JSON schema, if not already cached."""
req = requests.get(url)
return req.json()
Expand All @@ -35,7 +35,7 @@ def validate_extensions(
try:
if stac_dict["stac_extensions"]:
for ext in stac_dict["stac_extensions"]:
schema = _fetch_schema(ext)
schema = _fetch_and_cache_schema(ext)
jsonschema.validate(instance=stac_dict, schema=schema)
except Exception:
if reraise_exception:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from shapely.geometry import shape

from stac_pydantic import Collection, Item, ItemProperties
from stac_pydantic.extensions import _fetch_schema, validate_extensions
from stac_pydantic.extensions import _fetch_and_cache_schema, validate_extensions
from stac_pydantic.links import Link, Links
from stac_pydantic.shared import MimeTypes, StacCommonMetadata

Expand Down Expand Up @@ -120,16 +120,16 @@ def test_extension_validation_schema_cache() -> None:
# Defines 3 extensions, but one is a non-existing URL
test_item = request(EO_EXTENSION)

_fetch_schema.cache_clear()
_fetch_and_cache_schema.cache_clear()

assert not validate_extensions(test_item)
assert _fetch_schema.cache_info().hits == 0
assert _fetch_schema.cache_info().misses == 3
assert _fetch_and_cache_schema.cache_info().hits == 0
assert _fetch_and_cache_schema.cache_info().misses == 3

assert not validate_extensions(test_item)
assert _fetch_schema.cache_info().hits == 2
assert _fetch_and_cache_schema.cache_info().hits == 2
# The non-existing URL will have failed, hence retried
assert _fetch_schema.cache_info().misses == 4
assert _fetch_and_cache_schema.cache_info().misses == 4


@pytest.mark.parametrize(
Expand Down

0 comments on commit 03f0873

Please sign in to comment.