Skip to content

Commit

Permalink
Merge pull request #18889 from jmchilton/collection_type_check
Browse files Browse the repository at this point in the history
Improvements to Planemo test format based on feedback/discussions.
  • Loading branch information
mvdbeek authored Sep 27, 2024
2 parents 5e332f0 + 389f398 commit 6b6af37
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 8 deletions.
23 changes: 21 additions & 2 deletions lib/galaxy/tool_util/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
)

from pydantic import (
AfterValidator,
AnyUrl,
BaseModel,
ConfigDict,
Field,
RootModel,
)
from typing_extensions import (
Annotated,
Literal,
NotRequired,
TypedDict,
)
Expand Down Expand Up @@ -113,7 +117,7 @@ class BaseTestOutputModel(StrictModel):


class TestDataOutputAssertions(BaseTestOutputModel):
pass
class_: Optional[Literal["File"]] = Field("File", alias="class")


class TestCollectionCollectionElementAssertions(StrictModel):
Expand All @@ -131,14 +135,29 @@ class TestCollectionDatasetElementAssertions(BaseTestOutputModel):
TestCollectionCollectionElementAssertions.model_rebuild()


def _check_collection_type(v: str) -> str:
if len(v) == 0:
raise ValueError("Invalid empty collection_type specified.")
collection_levels = v.split(":")
for collection_level in collection_levels:
if collection_level not in ["list", "paired"]:
raise ValueError(f"Invalid collection_type specified [{v}]")
return v


CollectionType = Annotated[Optional[str], AfterValidator(_check_collection_type)]


class CollectionAttributes(StrictModel):
collection_type: Optional[str] = None
collection_type: CollectionType = None


class TestCollectionOutputAssertions(StrictModel):
class_: Optional[Literal["Collection"]] = Field("Collection", alias="class")
elements: Optional[Dict[str, TestCollectionElementAssertion]] = None
element_tests: Optional[Dict[str, "TestCollectionElementAssertion"]] = None
attributes: Optional[CollectionAttributes] = None
collection_type: CollectionType = None


TestOutputLiteral = Union[bool, int, float, str]
Expand Down
13 changes: 13 additions & 0 deletions lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,19 @@ def from_dict(as_dict):
element_tests=as_dict["element_tests"],
)

@staticmethod
def from_yaml_test_format(as_dict):
if "attributes" not in as_dict:
as_dict["attributes"] = {}
attributes = as_dict["attributes"]
# setup preferred name "elements" in accordance with work in https://github.com/galaxyproject/planemo/pull/1417
# TODO: test this works recursively...
if "elements" in as_dict and "element_tests" not in as_dict:
as_dict["element_tests"] = as_dict["elements"]
if "collection_type" in as_dict:
attributes["type"] = as_dict["collection_type"]
return TestCollectionOutputDef.from_dict(as_dict)

def to_dict(self):
return dict(name=self.name, attributes=self.attrib, element_tests=self.element_tests)

Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy_test/workflow/empty_collection_sort.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
filter_file: i1
outputs:
output:
class: Collection
collection_type: list
elements:
i1:
asserts:
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy_test/workflow/flatten_collection.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
job: {}
outputs:
out:
attributes: {collection_type: 'list'}
class: Collection
collection_type: list
elements:
'oe1-ie1':
asserts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
content: "0 mycoolline\n1 mysecondline\n"
outputs:
out:
class: Collection
collection_type: list
elements:
'samp1-0':
asserts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
type: raw
outputs:
output:
class: File
asserts:
- that: has_line
line: "parameter: 2"
3 changes: 2 additions & 1 deletion lib/galaxy_test/workflow/map_over_expression.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
content: B
outputs:
out1:
attributes: { collection_type: list }
class: Collection
collection_type: list
elements:
A:
asserts:
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy_test/workflow/multi_select_mapping.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ext: 'expression.json'
outputs:
output:
class: Collection
collection_type: list
elements:
the_example_2:
asserts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
type: raw
outputs:
output:
class: File
asserts:
- that: has_text
text: "col 1,2"
1 change: 1 addition & 0 deletions lib/galaxy_test/workflow/multiple_text.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
type: raw
outputs:
output:
class: File
asserts:
- that: has_line
line: '--ex1,ex2,--ex3'
2 changes: 2 additions & 0 deletions lib/galaxy_test/workflow/multiple_versions.gxwf-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
type: raw
outputs:
output_1:
class: File
asserts:
- that: has_text
text: 'Version 0.1'
- that: not_has_text
text: 'Version 0.2'
output_2:
class: File
asserts:
- that: has_text
text: 'Version 0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
type: File
outputs:
output:
class: File
metadata:
name: 'the_dataset_pair suffix'
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
replaceme: moocow
outputs:
out1:
class: File
metadata:
name: 'moocow name'
out2:
class: File
metadata:
name: 'moocow name 2'
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
type: raw
outputs:
out1:
class: File
metadata:
name: 'moocow name'
out2:
class: File
metadata:
name: 'moocow name 2'
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
type: raw
outputs:
out1:
class: File
metadata:
name: 'moocow name'
out2:
class: File
metadata:
name: 'moocow name 2'
5 changes: 1 addition & 4 deletions lib/galaxy_test/workflow/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ def verify_dataset(dataset: dict, test_properties: OutputChecks):
if is_collection_test:
assert isinstance(test_properties, dict)
test_properties["name"] = output_name
# setup preferred name "elements" in accordance with work in https://github.com/galaxyproject/planemo/pull/1417
test_properties["element_tests"] = test_properties["elements"]
output_def = TestCollectionOutputDef.from_dict(test_properties)

output_def = TestCollectionOutputDef.from_yaml_test_format(test_properties)
invocation_details = self.workflow_populator.get_invocation(run_summary.invocation_id, step_details=True)
assert output_name in invocation_details["output_collections"]
test_output = invocation_details["output_collections"][output_name]
Expand Down

0 comments on commit 6b6af37

Please sign in to comment.