Skip to content

Commit cc5ef54

Browse files
authored
Merge pull request #185 from common-workflow-language/compare_prefer_path
favor "path" over "location" when testing
2 parents 774a8c4 + 952d951 commit cc5ef54

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

cwltest/compare.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,42 @@ def _compare_location(
119119
expected: Dict[str, Any], actual: Dict[str, Any], skip_details: bool
120120
) -> None:
121121
if "path" in expected:
122-
comp = "path"
122+
expected_comp = "path"
123123
if "path" not in actual:
124124
actual["path"] = actual["location"]
125125
elif "location" in expected:
126-
comp = "location"
126+
expected_comp = "location"
127127
else:
128128
return
129+
if "path" in actual:
130+
actual_comp = "path"
131+
else:
132+
actual_comp = "location"
133+
path = urllib.parse.urlparse(actual[actual_comp]).path
129134
if actual.get("class") == "Directory":
130-
actual[comp] = actual[comp].rstrip("/")
135+
actual[actual_comp] = actual[actual_comp].rstrip("/")
131136
exist_fun: Callable[[str], bool] = os.path.isdir
132137
else:
133138
exist_fun = os.path.isfile
134-
if "path" in actual:
135-
path = urllib.parse.urlparse(actual["path"]).path
136-
else:
137-
path = urllib.parse.urlparse(actual["location"]).path
138139
if not exist_fun(path) and not skip_details:
139140
raise CompareFail.format(
140141
expected,
141142
actual,
142-
f"{actual[comp]} does not exist",
143+
f"{actual[actual_comp]} does not exist",
143144
)
144-
if expected[comp] != "Any" and (
145+
if expected[expected_comp] != "Any" and (
145146
not (
146-
actual[comp].endswith("/" + expected[comp])
147-
or ("/" not in actual[comp] and expected[comp] == actual[comp])
147+
actual[actual_comp].endswith("/" + expected[expected_comp])
148+
or (
149+
"/" not in actual[actual_comp]
150+
and expected[expected_comp] == actual[actual_comp]
151+
)
148152
)
149153
):
150154
raise CompareFail.format(
151155
expected,
152156
actual,
153-
f"{actual[comp]} does not end with {expected[comp]}",
157+
f"{actual[actual_comp]} does not end with {expected[expected_comp]}",
154158
)
155159

156160

tests/test_compare.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_compare_file_different_size(tmp_path: Path) -> None:
8282
actual = {
8383
"basename": "cores.txt",
8484
"class": "File",
85-
"location": str(path),
85+
"location": path.as_uri(),
8686
}
8787
with pytest.raises(CompareFail):
8888
_compare_file(expected, actual, False)
@@ -102,7 +102,7 @@ def test_compare_file_different_checksum(tmp_path: Path) -> None:
102102
actual = {
103103
"basename": "cores.txt",
104104
"class": "File",
105-
"location": str(path),
105+
"location": path.as_uri(),
106106
}
107107
with pytest.raises(CompareFail):
108108
_compare_file(expected, actual, False)
@@ -121,7 +121,7 @@ def test_compare_file_inconsistent_size(tmp_path: Path) -> None:
121121
actual = {
122122
"basename": "cores.txt",
123123
"class": "File",
124-
"location": str(path),
124+
"location": path.as_uri(),
125125
"size": 65535,
126126
}
127127
with pytest.raises(CompareFail):
@@ -142,7 +142,7 @@ def test_compare_file_inconsistent_checksum(tmp_path: Path) -> None:
142142
"basename": "cores.txt",
143143
"checksum": "inconsistent-checksum",
144144
"class": "File",
145-
"location": str(path),
145+
"location": path.as_uri(),
146146
}
147147
with pytest.raises(CompareFail):
148148
_compare_file(expected, actual, False)
@@ -160,7 +160,25 @@ def test_compare_directory(tmp_path: Path) -> None:
160160

161161
actual = {
162162
"class": "Directory",
163-
"location": str(path),
163+
"location": path.as_uri(),
164+
"listing": [],
165+
}
166+
_compare_directory(expected, actual, False)
167+
168+
169+
def test_compare_directory_path(tmp_path: Path) -> None:
170+
expected = {
171+
"location": "dir",
172+
"class": "Directory",
173+
"listing": [],
174+
}
175+
176+
path = tmp_path / "dir"
177+
os.makedirs(path)
178+
179+
actual = {
180+
"class": "Directory",
181+
"path": str(path),
164182
"listing": [],
165183
}
166184
_compare_directory(expected, actual, False)

0 commit comments

Comments
 (0)