Skip to content

Commit b835d2c

Browse files
committed
make dir-loading test os-independant for os.walk
1 parent 8eee4b1 commit b835d2c

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tests/test_directory_loader.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ def test_directory_loader_populator_runner(prune_option: bool):
6666
assert request_mock.calls[1].request.path_url == "/stac/collections"
6767
assert request_mock.calls[1].request.body == file_contents["collection.json"]
6868

69-
assert request_mock.calls[2].request.path_url == f"/stac/collections/{base_col}/items"
70-
assert request_mock.calls[2].request.body == file_contents["item-0.json"]
69+
# NOTE:
70+
# Because directory crawler users 'os.walk', loading order is OS-dependant.
71+
# Since the order does not actually matter, consider item indices interchangeably.
72+
req0_json = json.loads(request_mock.calls[2].request.body.decode())
73+
req0_item = req0_json["id"]
74+
item0_idx, item1_idx = (2, 3) if "sample-0" in req0_item else (3, 2)
7175

72-
assert request_mock.calls[3].request.path_url == f"/stac/collections/{base_col}/items"
73-
assert request_mock.calls[3].request.body == file_contents["item-1.json"]
76+
assert request_mock.calls[item0_idx].request.path_url == f"/stac/collections/{base_col}/items"
77+
assert request_mock.calls[item0_idx].request.body == file_contents["item-0.json"]
78+
79+
assert request_mock.calls[item1_idx].request.path_url == f"/stac/collections/{base_col}/items"
80+
assert request_mock.calls[item1_idx].request.body == file_contents["item-1.json"]
7481

7582
if not prune_option:
7683
assert request_mock.calls[4].request.url == stac_host
@@ -79,8 +86,15 @@ def test_directory_loader_populator_runner(prune_option: bool):
7986
assert request_mock.calls[5].request.path_url == "/stac/collections"
8087
assert request_mock.calls[5].request.body == file_contents["nested/collection.json"]
8188

82-
assert request_mock.calls[6].request.path_url == f"/stac/collections/{nested_col}/items"
83-
assert request_mock.calls[6].request.body == file_contents["nested/item-0.json"]
89+
# NOTE:
90+
# Because directory crawler users 'os.walk', loading order is OS-dependant.
91+
# Since the order does not actually matter, consider item indices interchangeably.
92+
req0_json = json.loads(request_mock.calls[6].request.body.decode())
93+
req0_item = req0_json["id"]
94+
item0_idx, item1_idx = (6, 7) if "sample-0" in req0_item else (7, 6)
95+
96+
assert request_mock.calls[item0_idx].request.path_url == f"/stac/collections/{nested_col}/items"
97+
assert request_mock.calls[item0_idx].request.body == file_contents["nested/item-0.json"]
8498

85-
assert request_mock.calls[7].request.path_url == f"/stac/collections/{nested_col}/items"
86-
assert request_mock.calls[7].request.body == file_contents["nested/item-1.json"]
99+
assert request_mock.calls[item1_idx].request.path_url == f"/stac/collections/{nested_col}/items"
100+
assert request_mock.calls[item1_idx].request.body == file_contents["nested/item-1.json"]

0 commit comments

Comments
 (0)