Skip to content

Commit

Permalink
Merge pull request #488 from l0b0/verify-empty-observation_direction-…
Browse files Browse the repository at this point in the history
…property

Verify empty observation direction property
  • Loading branch information
Jon Duckworth authored Jun 29, 2021
2 parents 164a990 + 431b5a7 commit 365aa60
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pystac/extensions/sar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__}'"
)


Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions tests/extensions/test_sar.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
12 changes: 12 additions & 0 deletions tests/extensions/test_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json

from pystac import ExtensionTypeError
from pystac.collection import Collection
import unittest

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 365aa60

Please sign in to comment.