Skip to content

Commit

Permalink
Fix tests for badgedir
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed Jun 23, 2024
1 parent 27370db commit dd4896e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 81 deletions.
12 changes: 6 additions & 6 deletions tests/test-data/badgedir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
tool: return-0.cwl
id: success_w_job
doc: Successful test with a job file
tags: [ required ]
tags: [ command_line_tool ]

- output: {}
tool: return-0.cwl
id: success_wo_job
doc: Successful test without a job file
tags: [ required ]
tags: [ command_line_tool ]

- output: {}
job: empty.yml
tool: return-1.cwl
id: failure_w_job
doc: Failed test with a job file
tags: [ required ]
tags: [ command_line_tool ]

- output: {}
tool: return-1.cwl
id: failure_wo_job
doc: Failed test without a job file
tags: [ required ]
tags: [ command_line_tool ]

- output: {}
job: empty.yml
tool: return-unsupported.cwl
id: unsupported_w_job
doc: Unsupported test with a job file
tags: [ required ]
tags: [ command_line_tool ]

- output: {}
tool: return-unsupported.cwl
id: unsupported_wo_job
doc: Unsupported test without a job file
tags: [ required ]
tags: [ command_line_tool ]
2 changes: 1 addition & 1 deletion tests/test-data/mock_cwl_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("processfile")
parser.add_argument("jobfile")
parser.add_argument("jobfile", nargs='?', default=None)
parser.add_argument("--version", action="version", version="%(prog)s 1.0")
parser.add_argument("--outdir")
parser.add_argument("--quiet", action="store_true")
Expand Down
99 changes: 25 additions & 74 deletions tests/test_badgedir.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
from os import linesep as n
from pathlib import Path
from textwrap import dedent

import schema_salad.ref_resolver

Expand Down Expand Up @@ -54,79 +55,18 @@ def test_badgedir(tmp_path: Path) -> None:
assert (badgedir / "command_line_tool.md").exists()


def test_badgedir_with_baseuri(tmp_path: Path) -> None:
def test_badgedir_report_with_baseuri(tmp_path: Path) -> None:
badgedir = tmp_path / "badgedir"

args = [
"--test",
schema_salad.ref_resolver.file_uri(
get_data("tests/test-data/conformance_test_v1.2.cwltest.yaml")
),
"--badgedir",
str(badgedir),
"--baseuri",
"https://example.com/specified/uri/",
]
cwd = os.getcwd()
try:
os.chdir(get_data("tests/test-data/"))
error_code, stdout, stderr = run_with_mock_cwl_runner(args)
finally:
os.chdir(cwd)

assert error_code == 1
required_json = badgedir / "required.json"
assert required_json.exists()
with open(required_json) as file:
obj = json.load(file)
assert obj.get("subject", "") == "required"
assert obj.get("status", "") == "0%"
assert obj.get("color", "") == "red"

required_md = badgedir / "required.md"
assert required_md.exists()
with open(required_md) as file:
assert (
f"# `required` tests{n}"
f"## List of passed tests{n}"
f"## List of failed tests{n}"
f"- [cl_optional_inputs_missing](https://example.com/specified/uri/conformance_test_v1.2.cwltest.yaml#L0) ([tool](https://example.com/specified/uri/v1.0/cat1-testcli.cwl), [job](https://example.com/specified/uri/v1.0/cat-job.json)){n}" # NOQA
f"## List of unsupported tests{n}"
) == file.read()

clt_json = badgedir / "command_line_tool.json"
assert clt_json.exists()
with open(clt_json) as file:
obj = json.load(file)
assert obj.get("subject", "") == "command_line_tool"
assert obj.get("status", "") == "0%"
assert obj.get("color", "") == "yellow"

clt_md = badgedir / "command_line_tool.md"
assert clt_md.exists()
with open(clt_md) as file:
assert (
f"# `command_line_tool` tests{n}"
f"## List of passed tests{n}"
f"## List of failed tests{n}"
f"- [cl_optional_inputs_missing](https://example.com/specified/uri/conformance_test_v1.2.cwltest.yaml#L0) ([tool](https://example.com/specified/uri/v1.0/cat1-testcli.cwl), [job](https://example.com/specified/uri/v1.0/cat-job.json)){n}" # NOQA
f"- [cl_optional_bindings_provided](https://example.com/specified/uri/conformance_test_v1.2.cwltest.yaml#L8) ([tool](https://example.com/specified/uri/v1.0/cat1-testcli.cwl), [job](https://example.com/specified/uri/v1.0/cat-n-job.json)){n}" # NOQA
f"## List of unsupported tests{n}"
) == file.read()


def test_badgedir_with_baseuri_without_trailing_slash(tmp_path: Path) -> None:
badgedir = tmp_path / "badgedir"
baseuri = "https://example.com/specified/uri/"

args = [
"--test",
schema_salad.ref_resolver.file_uri(
get_data("tests/test-data/badgedir.yaml")
),
schema_salad.ref_resolver.file_uri(get_data("tests/test-data/badgedir.yaml")),
"--badgedir",
str(badgedir),
"--baseuri",
"https://example.com/specified/uri",
baseuri,
]
cwd = os.getcwd()
try:
Expand All @@ -135,14 +75,25 @@ def test_badgedir_with_baseuri_without_trailing_slash(tmp_path: Path) -> None:
finally:
os.chdir(cwd)

assert error_code == 1
required_md = badgedir / "required.md"
required_md = badgedir / "command_line_tool.md"
assert required_md.exists()
with open(required_md) as file:
assert (
f"# `required` tests{n}"
f"## List of passed tests{n}"
f"## List of failed tests{n}"
f"- [cl_optional_inputs_missing](https://example.com/specified/uri/conformance_test_v1.2.cwltest.yaml#L0) ([tool](https://example.com/specified/uri/v1.0/cat1-testcli.cwl), [job](https://example.com/specified/uri/v1.0/cat-job.json)){n}" # NOQA
f"## List of unsupported tests{n}"
) == file.read()
contents = file.read()
assert contents == markdown_report_with(baseuri)


def markdown_report_with(baseuri: str) -> str:
return dedent(
f"""
# `command_line_tool` tests
## List of passed tests
- [success_w_job]({baseuri}badgedir.yaml#L0) ([tool]({baseuri}return-0.cwl), [job]({baseuri}empty.yml))
- [success_wo_job]({baseuri}badgedir.yaml#L7) ([tool]({baseuri}return-0.cwl))
## List of failed tests
- [failure_w_job]({baseuri}badgedir.yaml#L13) ([tool]({baseuri}return-1.cwl), [job]({baseuri}empty.yml))
- [failure_wo_job]({baseuri}badgedir.yaml#L20) ([tool]({baseuri}return-1.cwl))
## List of unsupported tests
- [unsupported_w_job]({baseuri}badgedir.yaml#L26) ([tool]({baseuri}return-unsupported.cwl), [job]({baseuri}empty.yml))
- [unsupported_wo_job]({baseuri}badgedir.yaml#L33) ([tool]({baseuri}return-unsupported.cwl))
"""
)[1:]

0 comments on commit dd4896e

Please sign in to comment.