Skip to content

Commit 822ec33

Browse files
Added more unit tests for STAC catalogs and items for metadata_from_stac Open-EO#527
1 parent ea41eaf commit 822ec33

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

tests/test_metadata.py

+43-18
Original file line numberDiff line numberDiff line change
@@ -786,23 +786,48 @@ def filter_bbox(self, bbox):
786786
assert new.bbox == (1, 2, 3, 4)
787787

788788

789-
def test_metadata_from_stac(tmp_path):
790-
collection_json = {
791-
"type": "Collection",
792-
"id": "test-collection",
793-
"stac_version": "1.0.0",
794-
"description": "Test collection",
795-
"links": [],
796-
"title": "Test Collection",
797-
"extent": {
798-
"spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]},
799-
"temporal": {"interval": [["2020-01-01T00:00:00Z", "2020-01-10T00:00:00Z"]]},
800-
},
801-
"license": "proprietary",
802-
"summaries": {"eo:bands": [{"name": "B01"}, {"name": "B02"}]},
803-
}
789+
collection_json = {
790+
"type": "Collection",
791+
"id": "test-collection",
792+
"stac_version": "1.0.0",
793+
"description": "Test collection",
794+
"links": [],
795+
"title": "Test Collection",
796+
"extent": {
797+
"spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]},
798+
"temporal": {"interval": [["2020-01-01T00:00:00Z", "2020-01-10T00:00:00Z"]]},
799+
},
800+
"license": "proprietary",
801+
"summaries": {"eo:bands": [{"name": "B01"}, {"name": "B02"}]},
802+
}
803+
804+
catalog_json = {
805+
"type": "Catalog",
806+
"id": "test-catalog",
807+
"stac_version": "1.0.0",
808+
"description": "Test Catalog",
809+
"links": [],
810+
}
811+
812+
item_json = {
813+
"type": "Feature",
814+
"stac_version": "1.0.0",
815+
"id": "test-item",
816+
"properties": {"datetime": "2020-05-22T00:00:00Z", "eo:bands": [{"name": "SCL"}, {"name": "B08"}]},
817+
"geometry": {"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], "type": "Polygon"},
818+
"links": [],
819+
"assets": {},
820+
"bbox": [0, 1, 0, 1],
821+
"stac_extensions": [],
822+
}
823+
824+
825+
@pytest.mark.parametrize(
826+
"test_stac, expected", [(collection_json, ["B01", "B02"]), (catalog_json, []), (item_json, ["SCL", "B08"])]
827+
)
828+
def test_metadata_from_stac(tmp_path, test_stac, expected):
804829

805-
path = tmp_path / "collection.json"
806-
path.write_text(json.dumps(collection_json))
830+
path = tmp_path / "stac.json"
831+
path.write_text(json.dumps(test_stac))
807832
metadata = metadata_from_stac(path)
808-
assert metadata.band_names == ["B01", "B02"]
833+
assert metadata.band_names == expected

0 commit comments

Comments
 (0)