From e90b945c3dc11144586d8b3992ee8432bdbac486 Mon Sep 17 00:00:00 2001 From: Julia Signell Date: Fri, 17 Jan 2025 22:55:28 +0100 Subject: [PATCH] Access scientific extension on item using .ext (#1496) * Access scientific extension on item using .ext * Update changelog - delinquent --- CHANGELOG.md | 4 ++++ pystac/extensions/ext.py | 4 ++++ tests/extensions/test_scientific.py | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9149839d..ceb817db2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,10 +12,14 @@ - Use [uv](https://github.com/astral-sh/uv) for development dependencies and docs ([#1439](https://github.com/stac-utils/pystac/pull/1439)) - Correctly detect absolute file path ref on windows, reflecting change in python 3.13 ([#1475](https://github.com/stac-utils/pystac/pull/14750)) (only effects python 3.13) - Deprecated `ItemAssetExtension` ([#1476](https://github.com/stac-utils/pystac/pull/1476)) +- Update Projection Extension to version 2 - proj:epsg -> proj:code ([#1287](https://github.com/stac-utils/pystac/pull/1287)) +- Update migrate code to handle license changes in STAC spec 1.1.0 ([#1491](https://github.com/stac-utils/pystac/pull/1491)) +- Allow links to have `file://` prefix - but don't write them that way by default ([#1489](https://github.com/stac-utils/pystac/pull/1489)) ### Fixed - Use `application/geo+json` for `item` links ([#1495](https://github.com/stac-utils/pystac/pull/1495)) +- Includes the scientific extension in Item's ext interface ([#1496](https://github.com/stac-utils/pystac/pull/1496)) ## [v1.11.0] - 2024-09-26 diff --git a/pystac/extensions/ext.py b/pystac/extensions/ext.py index 581886c10..e86e9d0aa 100644 --- a/pystac/extensions/ext.py +++ b/pystac/extensions/ext.py @@ -180,6 +180,10 @@ def sar(self) -> SarExtension[Item]: def sat(self) -> SatExtension[Item]: return SatExtension.ext(self.stac_object) + @property + def sci(self) -> ScientificExtension[Item]: + return ScientificExtension.ext(self.stac_object) + @property def storage(self) -> StorageExtension[Item]: return StorageExtension.ext(self.stac_object) diff --git a/tests/extensions/test_scientific.py b/tests/extensions/test_scientific.py index 0dee2edf5..9e6bcf008 100644 --- a/tests/extensions/test_scientific.py +++ b/tests/extensions/test_scientific.py @@ -7,6 +7,7 @@ import pystac from pystac import ExtensionTypeError +from pystac.errors import ExtensionNotImplemented from pystac.extensions import scientific from pystac.extensions.scientific import ( Publication, @@ -494,3 +495,26 @@ def test_summaries_adds_uri(self) -> None: self.assertNotIn( ScientificExtension.get_schema_uri(), collection.stac_extensions ) + + +@pytest.fixture +def ext_item() -> pystac.Item: + path = TestCases.get_path("data-files/scientific/item.json") + return pystac.Item.from_file(path) + + +def test_ext_syntax(ext_item: pystac.Item) -> None: + assert ext_item.ext.sci.doi == "10.5061/dryad.s2v81.2/27.2" + + +def test_ext_syntax_remove(ext_item: pystac.Item) -> None: + ext_item.ext.remove("sci") + assert ext_item.ext.has("sci") is False + with pytest.raises(ExtensionNotImplemented): + ext_item.ext.sci + + +def test_ext_syntax_add(item: pystac.Item) -> None: + item.ext.add("sci") + assert item.ext.has("sci") is True + assert isinstance(item.ext.sci, ScientificExtension)