Skip to content

Commit

Permalink
Added more unit tests for STAC catalogs and items for metadata_from_s…
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVerelst committed Mar 12, 2024
1 parent ea41eaf commit 822ec33
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 822ec33

Please sign in to comment.