From 822ec334d28cab1ac7146ef4d13ab89454c96651 Mon Sep 17 00:00:00 2001 From: Vincent Verelst Date: Tue, 12 Mar 2024 17:07:19 +0100 Subject: [PATCH] Added more unit tests for STAC catalogs and items for metadata_from_stac #527 --- tests/test_metadata.py | 61 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index ef144dc68..04db4fd3b 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -786,23 +786,48 @@ def filter_bbox(self, bbox): assert new.bbox == (1, 2, 3, 4) -def test_metadata_from_stac(tmp_path): - collection_json = { - "type": "Collection", - "id": "test-collection", - "stac_version": "1.0.0", - "description": "Test collection", - "links": [], - "title": "Test Collection", - "extent": { - "spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]}, - "temporal": {"interval": [["2020-01-01T00:00:00Z", "2020-01-10T00:00:00Z"]]}, - }, - "license": "proprietary", - "summaries": {"eo:bands": [{"name": "B01"}, {"name": "B02"}]}, - } +collection_json = { + "type": "Collection", + "id": "test-collection", + "stac_version": "1.0.0", + "description": "Test collection", + "links": [], + "title": "Test Collection", + "extent": { + "spatial": {"bbox": [[-180.0, -90.0, 180.0, 90.0]]}, + "temporal": {"interval": [["2020-01-01T00:00:00Z", "2020-01-10T00:00:00Z"]]}, + }, + "license": "proprietary", + "summaries": {"eo:bands": [{"name": "B01"}, {"name": "B02"}]}, +} + +catalog_json = { + "type": "Catalog", + "id": "test-catalog", + "stac_version": "1.0.0", + "description": "Test Catalog", + "links": [], +} + +item_json = { + "type": "Feature", + "stac_version": "1.0.0", + "id": "test-item", + "properties": {"datetime": "2020-05-22T00:00:00Z", "eo:bands": [{"name": "SCL"}, {"name": "B08"}]}, + "geometry": {"coordinates": [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], "type": "Polygon"}, + "links": [], + "assets": {}, + "bbox": [0, 1, 0, 1], + "stac_extensions": [], +} + + +@pytest.mark.parametrize( + "test_stac, expected", [(collection_json, ["B01", "B02"]), (catalog_json, []), (item_json, ["SCL", "B08"])] +) +def test_metadata_from_stac(tmp_path, test_stac, expected): - path = tmp_path / "collection.json" - path.write_text(json.dumps(collection_json)) + path = tmp_path / "stac.json" + path.write_text(json.dumps(test_stac)) metadata = metadata_from_stac(path) - assert metadata.band_names == ["B01", "B02"] + assert metadata.band_names == expected