File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -645,7 +645,13 @@ def ext(cls, obj: pystac.Item) -> "LabelExtension":
645
645
646
646
This extension can be applied to instances of :class:`~pystac.Item`.
647
647
"""
648
- return cls (obj )
648
+ if isinstance (obj , pystac .Item ):
649
+ cls .validate_has_extension (obj )
650
+ return cls (obj )
651
+ else :
652
+ raise pystac .ExtensionTypeError (
653
+ f"Label extension does not apply to type { type (obj )} "
654
+ )
649
655
650
656
651
657
class LabelExtensionHooks (ExtensionHooks ):
Original file line number Diff line number Diff line change @@ -361,3 +361,18 @@ def test_merge_label_overviews_error(self) -> None:
361
361
362
362
with self .assertRaises (AssertionError ):
363
363
_ = overview_1 .merge_counts (overview_2 )
364
+
365
+ def test_extension_type_error (self ) -> None :
366
+ collection = pystac .Collection .from_file (
367
+ TestCases .get_path ("data-files/collections/with-assets.json" )
368
+ )
369
+ with self .assertRaises (pystac .ExtensionTypeError ):
370
+ _ = LabelExtension .ext (collection ) # type: ignore
371
+
372
+ def test_extension_not_implemented (self ) -> None :
373
+ # Should raise exception if Item does not include extension URI
374
+ item = pystac .Item .from_file (self .label_example_1_uri )
375
+ item .stac_extensions .remove (LabelExtension .get_schema_uri ())
376
+
377
+ with self .assertRaises (pystac .ExtensionNotImplemented ):
378
+ _ = LabelExtension .ext (item )
You can’t perform that action at this time.
0 commit comments