File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 26
26
- ` EOExtension.get_bands ` returns ` None ` for asset without EO bands ([ #406 ] ( https://github.com/stac-utils/pystac/pull/406 ) )
27
27
- ` identify_stac_object_type ` returns ` None ` and ` identify_stac_object ` raises ` STACTypeError ` for non-STAC objects
28
28
([ #402 ] ( https://github.com/stac-utils/pystac/pull/402 ) )
29
+ - ` ExtensionManagementMixin.add_to ` is now idempotent (only adds schema URI to
30
+ ` stac_extensions ` once per ` Item ` regardless of the number of calls) ([ #419 ] ( https://github.com/stac-utils/pystac/pull/419 ) )
29
31
30
32
### Removed
31
33
Original file line number Diff line number Diff line change @@ -100,10 +100,11 @@ def get_schema_uri(cls) -> str:
100
100
@classmethod
101
101
def add_to (cls , obj : S ) -> None :
102
102
"""Add the schema URI for this extension to the
103
- :attr:`pystac.STACObject.stac_extensions` list for the given object."""
103
+ :attr:`~pystac.STACObject.stac_extensions` list for the given object, if it is
104
+ not already present."""
104
105
if obj .stac_extensions is None :
105
106
obj .stac_extensions = [cls .get_schema_uri ()]
106
- else :
107
+ elif cls . get_schema_uri () not in obj . stac_extensions :
107
108
obj .stac_extensions .append (cls .get_schema_uri ())
108
109
109
110
@classmethod
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ class EOTest(unittest.TestCase):
43
43
)
44
44
EO_COLLECTION_URI = TestCases .get_path ("data-files/eo/eo-collection.json" )
45
45
S2_ITEM_URI = TestCases .get_path ("data-files/eo/eo-sentinel2-item.json" )
46
+ PLAIN_ITEM = TestCases .get_path ("data-files/item/sample-item.json" )
46
47
47
48
def setUp (self ) -> None :
48
49
self .maxDiff = None
@@ -52,6 +53,24 @@ def test_to_from_dict(self) -> None:
52
53
item_dict = json .load (f )
53
54
assert_to_from_dict (self , Item , item_dict )
54
55
56
+ def test_add_to (self ) -> None :
57
+ item = Item .from_file (self .PLAIN_ITEM )
58
+ self .assertNotIn (EOExtension .get_schema_uri (), item .stac_extensions )
59
+
60
+ # Check that the URI gets added to stac_extensions
61
+ EOExtension .add_to (item )
62
+ self .assertIn (EOExtension .get_schema_uri (), item .stac_extensions )
63
+
64
+ # Check that the URI only gets added once, regardless of how many times add_to
65
+ # is called.
66
+ EOExtension .add_to (item )
67
+ EOExtension .add_to (item )
68
+
69
+ eo_uris = [
70
+ uri for uri in item .stac_extensions if uri == EOExtension .get_schema_uri ()
71
+ ]
72
+ self .assertEqual (len (eo_uris ), 1 )
73
+
55
74
def test_validate_eo (self ) -> None :
56
75
item = pystac .Item .from_file (self .LANDSAT_EXAMPLE_URI )
57
76
item2 = pystac .Item .from_file (self .BANDS_IN_ITEM_URI )
You can’t perform that action at this time.
0 commit comments