File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -237,8 +237,8 @@ def transform(self, v: Optional[List[float]]) -> None:
237
237
def get_schema_uri (cls ) -> str :
238
238
return SCHEMA_URI
239
239
240
- @staticmethod
241
- def ext (obj : T ) -> "ProjectionExtension[T]" :
240
+ @classmethod
241
+ def ext (cls , obj : T ) -> "ProjectionExtension[T]" :
242
242
"""Extends the given STAC Object with properties from the :stac-ext:`Projection
243
243
Extension <projection>`.
244
244
@@ -250,12 +250,14 @@ def ext(obj: T) -> "ProjectionExtension[T]":
250
250
pystac.ExtensionTypeError : If an invalid object type is passed.
251
251
"""
252
252
if isinstance (obj , pystac .Item ):
253
+ cls .validate_has_extension (obj )
253
254
return cast (ProjectionExtension [T ], ItemProjectionExtension (obj ))
254
255
elif isinstance (obj , pystac .Asset ):
256
+ cls .validate_has_extension (obj )
255
257
return cast (ProjectionExtension [T ], AssetProjectionExtension (obj ))
256
258
else :
257
259
raise pystac .ExtensionTypeError (
258
- f"File extension does not apply to type { type (obj )} "
260
+ f"Projection extension does not apply to type { type (obj )} "
259
261
)
260
262
261
263
@staticmethod
Original file line number Diff line number Diff line change @@ -406,6 +406,24 @@ def test_transform(self) -> None:
406
406
# Validate
407
407
proj_item .validate ()
408
408
409
+ def test_extension_not_implemented (self ) -> None :
410
+ # Should raise exception if Item does not include extension URI
411
+ item = pystac .Item .from_file (self .example_uri )
412
+ item .stac_extensions .remove (ProjectionExtension .get_schema_uri ())
413
+
414
+ with self .assertRaises (pystac .ExtensionNotImplemented ):
415
+ _ = ProjectionExtension .ext (item )
416
+
417
+ # Should raise exception if owning Item does not include extension URI
418
+ asset = item .assets ["B8" ]
419
+
420
+ with self .assertRaises (pystac .ExtensionNotImplemented ):
421
+ _ = ProjectionExtension .ext (asset )
422
+
423
+ # Should succeed if Asset has no owner
424
+ ownerless_asset = pystac .Asset .from_dict (asset .to_dict ())
425
+ _ = ProjectionExtension .ext (ownerless_asset )
426
+
409
427
410
428
class ProjectionSummariesTest (unittest .TestCase ):
411
429
def setUp (self ) -> None :
You can’t perform that action at this time.
0 commit comments