diff --git a/pystac/extensions/sar.py b/pystac/extensions/sar.py index 0f07213ea..9fd18ba28 100644 --- a/pystac/extensions/sar.py +++ b/pystac/extensions/sar.py @@ -318,7 +318,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "SarExtension[T]": return cast(SarExtension[T], AssetSarExtension(obj)) else: raise pystac.ExtensionTypeError( - f"SAR extension does not apply to type {type(obj)}" + f"SAR extension does not apply to type '{type(obj).__name__}'" ) diff --git a/pystac/extensions/view.py b/pystac/extensions/view.py index 6438a2cb0..47a6333d3 100644 --- a/pystac/extensions/view.py +++ b/pystac/extensions/view.py @@ -167,7 +167,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "ViewExtension[T]": return cast(ViewExtension[T], AssetViewExtension(obj)) else: raise pystac.ExtensionTypeError( - f"View extension does not apply to type {type(obj)}" + f"View extension does not apply to type '{type(obj).__name__}'" ) @staticmethod diff --git a/tests/extensions/test_sar.py b/tests/extensions/test_sar.py index 23311bced..38ae253eb 100644 --- a/tests/extensions/test_sar.py +++ b/tests/extensions/test_sar.py @@ -1,10 +1,14 @@ """Tests for pystac.extensions.sar.""" import datetime +from random import choice from typing import List import unittest +from string import ascii_letters + import pystac +from pystac import ExtensionTypeError from pystac.extensions import sar from pystac.extensions.sar import SarExtension from tests.utils import TestCases @@ -180,6 +184,26 @@ def test_asset_ext_add_to(self) -> None: self.assertIn(SarExtension.get_schema_uri(), item.stac_extensions) + def test_should_return_none_when_observation_direction_is_not_set(self) -> None: + extension = SarExtension.ext(self.item) + extension.apply( + choice(ascii_letters), + choice(list(sar.FrequencyBand)), + [], + choice(ascii_letters), + ) + self.assertIsNone(extension.observation_direction) + + def test_should_raise_exception_when_passing_invalid_extension_object( + self, + ) -> None: + self.assertRaisesRegex( + ExtensionTypeError, + r"^SAR extension does not apply to type 'object'$", + SarExtension.ext, + object(), + ) + if __name__ == "__main__": unittest.main() diff --git a/tests/extensions/test_view.py b/tests/extensions/test_view.py index ac6f10a5d..c24ef8222 100644 --- a/tests/extensions/test_view.py +++ b/tests/extensions/test_view.py @@ -1,4 +1,6 @@ import json + +from pystac import ExtensionTypeError from pystac.collection import Collection import unittest @@ -257,6 +259,16 @@ def test_asset_ext_add_to(self) -> None: self.assertIn(ViewExtension.get_schema_uri(), item.stac_extensions) + def test_should_raise_exception_when_passing_invalid_extension_object( + self, + ) -> None: + self.assertRaisesRegex( + ExtensionTypeError, + r"^View extension does not apply to type 'object'$", + ViewExtension.ext, + object(), + ) + class ViewSummariestest(unittest.TestCase): def setUp(self) -> None: