Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

favor "path" over "location" when testing #185

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions cwltest/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,38 +119,42 @@
expected: Dict[str, Any], actual: Dict[str, Any], skip_details: bool
) -> None:
if "path" in expected:
comp = "path"
expected_comp = "path"

Check warning on line 122 in cwltest/compare.py

View check run for this annotation

Codecov / codecov/patch

cwltest/compare.py#L122

Added line #L122 was not covered by tests
if "path" not in actual:
actual["path"] = actual["location"]
elif "location" in expected:
comp = "location"
expected_comp = "location"
else:
return
if "path" in actual:
actual_comp = "path"
else:
actual_comp = "location"
path = urllib.parse.urlparse(actual[actual_comp]).path
if actual.get("class") == "Directory":
actual[comp] = actual[comp].rstrip("/")
actual[actual_comp] = actual[actual_comp].rstrip("/")
exist_fun: Callable[[str], bool] = os.path.isdir
else:
exist_fun = os.path.isfile
if "path" in actual:
path = urllib.parse.urlparse(actual["path"]).path
else:
path = urllib.parse.urlparse(actual["location"]).path
if not exist_fun(path) and not skip_details:
raise CompareFail.format(
expected,
actual,
f"{actual[comp]} does not exist",
f"{actual[actual_comp]} does not exist",
)
if expected[comp] != "Any" and (
if expected[expected_comp] != "Any" and (
not (
actual[comp].endswith("/" + expected[comp])
or ("/" not in actual[comp] and expected[comp] == actual[comp])
actual[actual_comp].endswith("/" + expected[expected_comp])
or (
"/" not in actual[actual_comp]
and expected[expected_comp] == actual[actual_comp]
)
)
):
raise CompareFail.format(
expected,
actual,
f"{actual[comp]} does not end with {expected[comp]}",
f"{actual[actual_comp]} does not end with {expected[expected_comp]}",
)


Expand Down
28 changes: 23 additions & 5 deletions tests/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_compare_file_different_size(tmp_path: Path) -> None:
actual = {
"basename": "cores.txt",
"class": "File",
"location": str(path),
"location": path.as_uri(),
}
with pytest.raises(CompareFail):
_compare_file(expected, actual, False)
Expand All @@ -102,7 +102,7 @@ def test_compare_file_different_checksum(tmp_path: Path) -> None:
actual = {
"basename": "cores.txt",
"class": "File",
"location": str(path),
"location": path.as_uri(),
}
with pytest.raises(CompareFail):
_compare_file(expected, actual, False)
Expand All @@ -121,7 +121,7 @@ def test_compare_file_inconsistent_size(tmp_path: Path) -> None:
actual = {
"basename": "cores.txt",
"class": "File",
"location": str(path),
"location": path.as_uri(),
"size": 65535,
}
with pytest.raises(CompareFail):
Expand All @@ -142,7 +142,7 @@ def test_compare_file_inconsistent_checksum(tmp_path: Path) -> None:
"basename": "cores.txt",
"checksum": "inconsistent-checksum",
"class": "File",
"location": str(path),
"location": path.as_uri(),
}
with pytest.raises(CompareFail):
_compare_file(expected, actual, False)
Expand All @@ -160,7 +160,25 @@ def test_compare_directory(tmp_path: Path) -> None:

actual = {
"class": "Directory",
"location": str(path),
"location": path.as_uri(),
"listing": [],
}
_compare_directory(expected, actual, False)


def test_compare_directory_path(tmp_path: Path) -> None:
expected = {
"location": "dir",
"class": "Directory",
"listing": [],
}

path = tmp_path / "dir"
os.makedirs(path)

actual = {
"class": "Directory",
"path": str(path),
"listing": [],
}
_compare_directory(expected, actual, False)
Expand Down
Loading