Skip to content

Commit 3db45d5

Browse files
committed
strengthen tests for current DiskWorkspace's implementation of merge
Open-EO/openeo-geopyspark-driver#1111
1 parent d7de845 commit 3db45d5

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/test_workspace.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import datetime as dt
2+
import os
23
import shutil
34
import tempfile
45
from pathlib import Path
6+
from typing import Set
57

68
from pystac import Asset, Collection, Extent, Item, SpatialExtent, TemporalExtent, CatalogType, Link, RelType
79
import pytest
@@ -60,6 +62,14 @@ def test_merge_from_disk_new(tmp_path):
6062
workspace = DiskWorkspace(root_directory=tmp_path)
6163
imported_collection = workspace.merge(stac_resource=new_collection, target=target)
6264

65+
workspace_dir = (workspace.root_directory / target).parent
66+
67+
assert _paths_relative_to(workspace_dir) == {
68+
Path("collection.json"),
69+
Path("collection.json_items") / "asset.tif",
70+
Path("collection.json_items") / "asset.tif.json",
71+
}
72+
6373
assert isinstance(imported_collection, Collection)
6474
asset_workspace_uris = {
6575
asset_key: asset.extra_fields["alternate"]["file"]
@@ -71,7 +81,6 @@ def test_merge_from_disk_new(tmp_path):
7181
}
7282

7383
# load it again
74-
workspace_dir = (workspace.root_directory / target).parent
7584
exported_collection = Collection.from_file(str(workspace_dir / "collection.json"))
7685
assert exported_collection.validate_all() == 1
7786
assert _downloadable_assets(exported_collection) == 1
@@ -108,6 +117,15 @@ def test_merge_from_disk_into_existing(tmp_path):
108117
workspace.merge(stac_resource=existing_collection, target=target)
109118
imported_collection = workspace.merge(stac_resource=new_collection, target=target)
110119

120+
workspace_dir = (workspace.root_directory / target).parent
121+
assert _paths_relative_to(workspace_dir) == {
122+
Path("collection.json"),
123+
Path("collection.json_items") / "asset1.tif",
124+
Path("collection.json_items") / "asset1.tif.json",
125+
Path("collection.json_items") / "asset2.tif",
126+
Path("collection.json_items") / "asset2.tif.json",
127+
}
128+
111129
assert isinstance(imported_collection, Collection)
112130
asset_workspace_uris = {
113131
asset_key: asset.extra_fields["alternate"]["file"]
@@ -119,7 +137,6 @@ def test_merge_from_disk_into_existing(tmp_path):
119137
}
120138

121139
# load it again
122-
workspace_dir = (workspace.root_directory / target).parent
123140
exported_collection = Collection.from_file(str(workspace_dir / "collection.json"))
124141
assert exported_collection.validate_all() == 2
125142
assert _downloadable_assets(exported_collection) == 2
@@ -230,3 +247,11 @@ def _downloadable_assets(collection: Collection) -> int:
230247
shutil.copy(asset.get_absolute_href(), temp_file.name) # "download" the asset without altering its href
231248

232249
return len(assets)
250+
251+
252+
def _paths_relative_to(base: Path) -> Set[Path]:
253+
return {
254+
(Path(dirpath) / filename).relative_to(base)
255+
for dirpath, dirnames, filenames in os.walk(base)
256+
for filename in filenames
257+
}

0 commit comments

Comments
 (0)