Skip to content

Commit 817ac78

Browse files
committed
added tests
1 parent 9002c87 commit 817ac78

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/extensions/test_mlm.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,92 @@ def test_migration_1_0_to_1_1_item_assets(
11401140
assert bool(re.match(pattern, data["item_assets"]["asset1"]["mlm:framework"]))
11411141

11421142

1143+
@pytest.mark.parametrize(
1144+
"bands_obj_name, bands_obj",
1145+
(
1146+
("raster:bands", {"raster:bands": []}),
1147+
("raster:bands", {"raster:bands": [{"name": "B01"}, {"name": "B02"}]}),
1148+
("eo:bands", {"eo:bands": []}),
1149+
("eo:bands", {"eo:bands": [{"name": "B01"}, {"name": "B02"}]}),
1150+
),
1151+
)
1152+
def test_migration_1_0_to_1_1_asset_bands_item(
1153+
bands_obj_name: str, bands_obj: dict[str, Any]
1154+
) -> None:
1155+
data: dict[str, Any] = {
1156+
"type": "Feature",
1157+
"properties": {"mlm:input": [{"bands": []}]},
1158+
"assets": {
1159+
"asset1": {"href": "https://example.com", "roles": ["analytic"]},
1160+
"asset2": {
1161+
"href": "https://example.com",
1162+
"roles": ["analytic"],
1163+
**bands_obj,
1164+
},
1165+
"asset3": {
1166+
"href": "https://example.com",
1167+
"roles": ["mlm:model"],
1168+
**bands_obj,
1169+
},
1170+
},
1171+
}
1172+
1173+
with pytest.warns(SyntaxWarning):
1174+
MLMExtensionHooks._migrate_1_0_to_1_1(data)
1175+
1176+
if bands_obj[bands_obj_name]:
1177+
assert bands_obj_name in data["assets"]["asset2"]
1178+
assert bands_obj_name not in data["assets"]["asset3"]
1179+
assert bands_obj_name in data["properties"]
1180+
else:
1181+
assert bands_obj_name in data["assets"]["asset2"]
1182+
assert bands_obj_name not in data["assets"]["asset3"]
1183+
assert bands_obj_name not in data["properties"]
1184+
1185+
1186+
@pytest.mark.parametrize(
1187+
"bands_obj_name, bands_obj",
1188+
(
1189+
("raster:bands", {"raster:bands": []}),
1190+
("raster:bands", {"raster:bands": [{"name": "B01"}, {"name": "B02"}]}),
1191+
("eo:bands", {"eo:bands": []}),
1192+
("eo:bands", {"eo:bands": [{"name": "B01"}, {"name": "B02"}]}),
1193+
),
1194+
)
1195+
def test_migration_1_0_to_1_1_asset_bands_collection(
1196+
bands_obj_name: str, bands_obj: dict[str, Any]
1197+
) -> None:
1198+
data: dict[str, Any] = {
1199+
"type": "Collection",
1200+
"mlm:input": [{"bands": []}],
1201+
"assets": {
1202+
"asset1": {"href": "https://example.com", "roles": ["analytic"]},
1203+
"asset2": {
1204+
"href": "https://example.com",
1205+
"roles": ["analytic"],
1206+
**bands_obj,
1207+
},
1208+
"asset3": {
1209+
"href": "https://example.com",
1210+
"roles": ["mlm:model"],
1211+
**bands_obj,
1212+
},
1213+
},
1214+
}
1215+
1216+
with pytest.warns(SyntaxWarning):
1217+
MLMExtensionHooks._migrate_1_0_to_1_1(data)
1218+
1219+
if bands_obj[bands_obj_name]:
1220+
assert bands_obj_name in data["assets"]["asset2"]
1221+
assert bands_obj_name not in data["assets"]["asset3"]
1222+
assert bands_obj_name in data
1223+
else:
1224+
assert bands_obj_name in data["assets"]["asset2"]
1225+
assert bands_obj_name not in data["assets"]["asset3"]
1226+
assert bands_obj_name not in data
1227+
1228+
11431229
@pytest.mark.parametrize("asset_type", ("assets", "item_assets"))
11441230
def test_migration_1_1_to_1_2(asset_type: str) -> None:
11451231
data: dict[str, Any] = {}

0 commit comments

Comments
 (0)