Skip to content

Commit 365aa60

Browse files
author
Jon Duckworth
authored
Merge pull request #488 from l0b0/verify-empty-observation_direction-property
Verify empty observation direction property
2 parents 164a990 + 431b5a7 commit 365aa60

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

pystac/extensions/sar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "SarExtension[T]":
318318
return cast(SarExtension[T], AssetSarExtension(obj))
319319
else:
320320
raise pystac.ExtensionTypeError(
321-
f"SAR extension does not apply to type {type(obj)}"
321+
f"SAR extension does not apply to type '{type(obj).__name__}'"
322322
)
323323

324324

pystac/extensions/view.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "ViewExtension[T]":
167167
return cast(ViewExtension[T], AssetViewExtension(obj))
168168
else:
169169
raise pystac.ExtensionTypeError(
170-
f"View extension does not apply to type {type(obj)}"
170+
f"View extension does not apply to type '{type(obj).__name__}'"
171171
)
172172

173173
@staticmethod

tests/extensions/test_sar.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""Tests for pystac.extensions.sar."""
22

33
import datetime
4+
from random import choice
45
from typing import List
56
import unittest
67

8+
from string import ascii_letters
9+
710
import pystac
11+
from pystac import ExtensionTypeError
812
from pystac.extensions import sar
913
from pystac.extensions.sar import SarExtension
1014
from tests.utils import TestCases
@@ -180,6 +184,26 @@ def test_asset_ext_add_to(self) -> None:
180184

181185
self.assertIn(SarExtension.get_schema_uri(), item.stac_extensions)
182186

187+
def test_should_return_none_when_observation_direction_is_not_set(self) -> None:
188+
extension = SarExtension.ext(self.item)
189+
extension.apply(
190+
choice(ascii_letters),
191+
choice(list(sar.FrequencyBand)),
192+
[],
193+
choice(ascii_letters),
194+
)
195+
self.assertIsNone(extension.observation_direction)
196+
197+
def test_should_raise_exception_when_passing_invalid_extension_object(
198+
self,
199+
) -> None:
200+
self.assertRaisesRegex(
201+
ExtensionTypeError,
202+
r"^SAR extension does not apply to type 'object'$",
203+
SarExtension.ext,
204+
object(),
205+
)
206+
183207

184208
if __name__ == "__main__":
185209
unittest.main()

tests/extensions/test_view.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
3+
from pystac import ExtensionTypeError
24
from pystac.collection import Collection
35
import unittest
46

@@ -257,6 +259,16 @@ def test_asset_ext_add_to(self) -> None:
257259

258260
self.assertIn(ViewExtension.get_schema_uri(), item.stac_extensions)
259261

262+
def test_should_raise_exception_when_passing_invalid_extension_object(
263+
self,
264+
) -> None:
265+
self.assertRaisesRegex(
266+
ExtensionTypeError,
267+
r"^View extension does not apply to type 'object'$",
268+
ViewExtension.ext,
269+
object(),
270+
)
271+
260272

261273
class ViewSummariesTest(unittest.TestCase):
262274
def setUp(self) -> None:

0 commit comments

Comments
 (0)