Skip to content

Verify empty observation direction property #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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