From 7c4660b6b64789f46dae55364419228643456c33 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 9 Jan 2025 10:08:16 +0100 Subject: [PATCH] remove warning to `from_extensions` method --- CHANGES.md | 4 ++++ .../collection_search/collection_search.py | 21 ++++------------- .../tests/test_collection_search.py | 23 ++++++++++--------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 55cf7aa5f..d38cea40f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Removed + +* Remove `warnings` in `CollectionSearchExtension.from_extensions()` methods when passing `unknown` extensions + ## [3.0.4] - 2025-01-08 ### Removed diff --git a/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/collection_search.py b/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/collection_search.py index 2a5f7cf4d..2bd7ac285 100644 --- a/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/collection_search.py +++ b/stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/collection_search.py @@ -1,6 +1,5 @@ """Collection-Search extension.""" -import warnings from enum import Enum from typing import List, Optional, Union @@ -79,7 +78,7 @@ def from_extensions( schema_href: Optional[str] = None, ) -> "CollectionSearchExtension": """Create CollectionSearchExtension object from extensions.""" - supported_extensions = { + known_extension_conformances = { "FreeTextExtension": ConformanceClasses.FREETEXT, "FreeTextAdvancedExtension": ConformanceClasses.FREETEXT, "QueryExtension": ConformanceClasses.QUERY, @@ -92,13 +91,7 @@ def from_extensions( ConformanceClasses.BASIS, ] for ext in extensions: - conf = supported_extensions.get(ext.__class__.__name__, None) - if not conf: - warnings.warn( - f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501 - UserWarning, - ) - else: + if conf := known_extension_conformances.get(ext.__class__.__name__, None): conformance_classes.append(conf) get_request_model = create_request_model( @@ -187,7 +180,7 @@ def from_extensions( router: Optional[APIRouter] = None, ) -> "CollectionSearchPostExtension": """Create CollectionSearchPostExtension object from extensions.""" - supported_extensions = { + known_extension_conformances = { "FreeTextExtension": ConformanceClasses.FREETEXT, "FreeTextAdvancedExtension": ConformanceClasses.FREETEXT, "QueryExtension": ConformanceClasses.QUERY, @@ -200,13 +193,7 @@ def from_extensions( ConformanceClasses.BASIS, ] for ext in extensions: - conf = supported_extensions.get(ext.__class__.__name__, None) - if not conf: - warnings.warn( - f"Conformance class for `{ext.__class__.__name__}` extension not found.", # noqa: E501 - UserWarning, - ) - else: + if conf := known_extension_conformances.get(ext.__class__.__name__, None): conformance_classes.append(conf) get_request_model = create_request_model( diff --git a/stac_fastapi/extensions/tests/test_collection_search.py b/stac_fastapi/extensions/tests/test_collection_search.py index b23219956..8f54f1537 100644 --- a/stac_fastapi/extensions/tests/test_collection_search.py +++ b/stac_fastapi/extensions/tests/test_collection_search.py @@ -476,35 +476,36 @@ def test_from_extensions_methods(extensions): def test_from_extensions_methods_invalid(): - """Should raise warnings for invalid extensions.""" + """Should also work with unknown extensions.""" extensions = [ AggregationExtension(), ] - with pytest.warns((UserWarning)): - ext = CollectionSearchExtension.from_extensions( - extensions, - ) + ext = CollectionSearchExtension.from_extensions( + extensions, + ) + collection_search = ext.GET() assert collection_search.__class__.__name__ == "CollectionsGetRequest" assert hasattr(collection_search, "bbox") assert hasattr(collection_search, "datetime") assert hasattr(collection_search, "limit") + assert hasattr(collection_search, "aggregations") assert ext.conformance_classes == [ ConformanceClasses.COLLECTIONSEARCH, ConformanceClasses.BASIS, ] - with pytest.warns((UserWarning)): - ext = CollectionSearchPostExtension.from_extensions( - extensions, - client=DummyPostClient(), - settings=ApiSettings(), - ) + ext = CollectionSearchPostExtension.from_extensions( + extensions, + client=DummyPostClient(), + settings=ApiSettings(), + ) collection_search = ext.POST() assert collection_search.__class__.__name__ == "CollectionsPostRequest" assert hasattr(collection_search, "bbox") assert hasattr(collection_search, "datetime") assert hasattr(collection_search, "limit") + assert hasattr(collection_search, "aggregations") assert ext.conformance_classes == [ ConformanceClasses.COLLECTIONSEARCH, ConformanceClasses.BASIS,