Skip to content

Commit

Permalink
remove warning to from_extensions method (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Jan 9, 2025
1 parent 362741e commit 1863ea0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Removed

* Remove `warnings` in `CollectionSearchExtension.from_extensions()` methods when passing `unknown` extensions

## [3.0.4] - 2025-01-08

### Removed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Collection-Search extension."""

import warnings
from enum import Enum
from typing import List, Optional, Union

Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down
23 changes: 12 additions & 11 deletions stac_fastapi/extensions/tests/test_collection_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1863ea0

Please sign in to comment.