Skip to content

Commit 16c5006

Browse files
committed
Issue #699 bands_from_stac_collection test coverage
1 parent 63ac783 commit 16c5006

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

openeo/testing/stac.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def collection(
6565
extent: Optional[dict] = None,
6666
cube_dimensions: Optional[dict] = None,
6767
summaries: Optional[dict] = None,
68+
links: Optional[List[dict]] = None,
6869
) -> dict:
6970
"""Create a STAC Collection represented as dictionary."""
7071
if extent is None:
@@ -77,7 +78,7 @@ def collection(
7778
"description": description,
7879
"license": license,
7980
"extent": extent,
80-
"links": [],
81+
"links": links or [],
8182
}
8283
if cube_dimensions is not None:
8384
d["cube:dimensions"] = cube_dimensions

tests/test_metadata.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,112 @@ def test_bands_from_stac_collection(self, data, expected):
13021302
collection = pystac.Collection.from_dict(data)
13031303
assert _StacMetadataParser().bands_from_stac_collection(collection=collection) == expected
13041304

1305+
@pytest.mark.parametrize(
1306+
["entities", "kwargs", "expected"],
1307+
[
1308+
(
1309+
{
1310+
"collection.json": StacDummyBuilder.collection(
1311+
stac_version="1.0.0",
1312+
links=[
1313+
{"rel": "item", "href": "item.json"},
1314+
],
1315+
),
1316+
"item.json": StacDummyBuilder.item(
1317+
stac_version="1.0.0",
1318+
stac_extensions=["https://stac-extensions.github.io/eo/v1.1.0/schema.json"],
1319+
properties={
1320+
"eo:bands": [{"name": "B02"}, {"name": "B03"}],
1321+
},
1322+
),
1323+
},
1324+
{},
1325+
[Band("B02"), Band("B03")],
1326+
),
1327+
(
1328+
{
1329+
"collection.json": StacDummyBuilder.collection(
1330+
stac_version="1.0.0",
1331+
links=[
1332+
{"rel": "item", "href": "item1.json"},
1333+
{"rel": "item", "href": "item2.json"},
1334+
],
1335+
),
1336+
"item1.json": StacDummyBuilder.item(
1337+
stac_version="1.0.0",
1338+
stac_extensions=["https://stac-extensions.github.io/eo/v1.1.0/schema.json"],
1339+
properties={
1340+
"eo:bands": [{"name": "B02"}],
1341+
},
1342+
),
1343+
"item2.json": StacDummyBuilder.item(
1344+
stac_version="1.0.0",
1345+
stac_extensions=["https://stac-extensions.github.io/eo/v1.1.0/schema.json"],
1346+
properties={
1347+
"eo:bands": [{"name": "B03"}],
1348+
},
1349+
),
1350+
},
1351+
{},
1352+
[Band("B02"), Band("B03")],
1353+
),
1354+
(
1355+
{
1356+
"collection.json": StacDummyBuilder.collection(
1357+
stac_version="1.0.0",
1358+
links=[
1359+
{"rel": "item", "href": "item10.json"},
1360+
{"rel": "item", "href": "item11.json"},
1361+
],
1362+
),
1363+
"item10.json": StacDummyBuilder.item(
1364+
stac_version="1.0.0",
1365+
stac_extensions=["https://stac-extensions.github.io/eo/v1.1.0/schema.json"],
1366+
properties={
1367+
"eo:bands": [{"name": "B02"}],
1368+
},
1369+
),
1370+
"item11.json": StacDummyBuilder.item(
1371+
stac_version="1.1.0",
1372+
properties={
1373+
"bands": [{"name": "B03"}],
1374+
},
1375+
),
1376+
},
1377+
{},
1378+
[Band("B02"), Band("B03")],
1379+
),
1380+
(
1381+
{
1382+
"collection.json": StacDummyBuilder.collection(
1383+
stac_version="1.0.0",
1384+
links=[
1385+
{"rel": "item", "href": "item.json"},
1386+
],
1387+
),
1388+
"item.json": StacDummyBuilder.item(
1389+
stac_version="1.0.0",
1390+
stac_extensions=["https://stac-extensions.github.io/eo/v1.1.0/schema.json"],
1391+
assets={
1392+
"asset1": {
1393+
"href": "https://stac.test/asset.tif",
1394+
"roles": ["data"],
1395+
"eo:bands": [{"name": "B02"}],
1396+
}
1397+
},
1398+
),
1399+
},
1400+
{},
1401+
[Band("B02")],
1402+
),
1403+
],
1404+
)
1405+
def test_bands_from_stac_collection_consult_items(self, tmp_path, entities, kwargs, expected):
1406+
for name, content in entities.items():
1407+
(tmp_path / name).write_text(json.dumps(content))
1408+
collection = pystac.Collection.from_file(tmp_path / "collection.json")
1409+
assert _StacMetadataParser().bands_from_stac_collection(collection=collection) == expected
1410+
13051411
@pytest.mark.parametrize(
13061412
["data", "expected"],
13071413
[

0 commit comments

Comments
 (0)