Skip to content

Commit

Permalink
Make tests and code agree on missing version behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Jan 17, 2025
1 parent e620d72 commit e3e6414
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/toil/lib/trs.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def find_workflow(workflow: str, supported_languages: Optional[set[str]] = None)
TODO: Needs to handle multi-workflow files if Dockstore can.
:raises FileNotFoundError: if the workflow or version doesn't exist.
:raises ValueError: if the version is not specified but cannot be
automatically determined.
"""

if supported_languages is not None and len(supported_languages) == 0:
Expand Down Expand Up @@ -172,6 +174,7 @@ def find_workflow(workflow: str, supported_languages: Optional[set[str]] = None)
problem_type: type[Exception] = RuntimeError
if trs_version is None:
problems.append(f"Workflow {workflow} does not specify a version")
problem_type = ValueError
elif trs_version not in workflow_versions:
problems.append(f"Workflow version {trs_version} from {workflow} does not exist")
problem_type = FileNotFoundError
Expand Down
18 changes: 15 additions & 3 deletions src/toil/test/lib/test_trs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,26 @@ def test_lookup_from_page_url(self) -> None:
self.assertEqual(trs_version, "master")
self.assertEqual(language, "WDL")

def test_lookup_from_trs(self) -> None:
def test_lookup_from_trs_with_version(self) -> None:
TRS_ID = "#workflow/github.com/dockstore-testing/md5sum-checker"
trs_id, trs_version, language = find_workflow(TRS_ID)
TRS_VERSION = "master"
trs_id, trs_version, language = find_workflow(f"{TRS_ID}:{TRS_VERSION}")

self.assertEqual(trs_id, TRS_ID)
self.assertEqual(trs_version, "master")
self.assertEqual(trs_version, TRS_VERSION)
self.assertEqual(language, "CWL")

def test_lookup_from_trs_no_version(self) -> None:
TRS_ID = "#workflow/github.com/dockstore-testing/md5sum-checker"
with pytest.raises(ValueError):
# We don't yet have a way to read Dockstore's default version info,
# so it's not safe to apply any default version when multiple
# versions exist.
trs_id, trs_version, language = find_workflow(TRS_ID)

# TODO: Add a test with a workflow that we know has and will only ever
# have one version, to test version auto-detection in that case.

def test_get(self) -> None:
TRS_ID = "#workflow/github.com/dockstore-testing/md5sum-checker"
TRS_VERSION = "master"
Expand Down

0 comments on commit e3e6414

Please sign in to comment.