Skip to content

Commit bb2556a

Browse files
committed
Implement #370 for Pointcloud extension
1 parent 83196bb commit bb2556a

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

pystac/extensions/pointcloud.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,17 @@ def statistics(self, v: Optional[List[PointcloudStatistic]]) -> None:
522522
def get_schema_uri(cls) -> str:
523523
return SCHEMA_URI
524524

525-
@staticmethod
526-
def ext(obj: T) -> "PointcloudExtension[T]":
525+
@classmethod
526+
def ext(cls, obj: T) -> "PointcloudExtension[T]":
527527
if isinstance(obj, pystac.Item):
528+
cls.validate_has_extension(obj)
528529
return cast(PointcloudExtension[T], ItemPointcloudExtension(obj))
529530
elif isinstance(obj, pystac.Asset):
531+
cls.validate_has_extension(obj)
530532
return cast(PointcloudExtension[T], AssetPointcloudExtension(obj))
531533
else:
532534
raise pystac.ExtensionTypeError(
533-
f"File extension does not apply to type {type(obj)}"
535+
f"Pointcloud extension does not apply to type {type(obj)}"
534536
)
535537

536538

tests/extensions/test_pointcloud.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,21 @@ class RandomObject:
293293

294294
with self.assertRaises(ExtensionTypeError):
295295
PointcloudExtension.ext(RandomObject()) # type: ignore
296+
297+
def test_extension_not_implemented(self) -> None:
298+
# Should raise exception if Item does not include extension URI
299+
plain_item_uri = TestCases.get_path("data-files/item/sample-item.json")
300+
item = pystac.Item.from_file(plain_item_uri)
301+
302+
with self.assertRaises(pystac.ExtensionNotImplemented):
303+
_ = PointcloudExtension.ext(item)
304+
305+
# Should raise exception if owning Item does not include extension URI
306+
asset = item.assets["thumbnail"]
307+
308+
with self.assertRaises(pystac.ExtensionNotImplemented):
309+
_ = PointcloudExtension.ext(asset)
310+
311+
# Should succeed if Asset has no owner
312+
ownerless_asset = pystac.Asset.from_dict(asset.to_dict())
313+
_ = PointcloudExtension.ext(ownerless_asset)

0 commit comments

Comments
 (0)