Skip to content

Commit 3e45410

Browse files
committed
WIP: test case stuff...
1 parent 71de93b commit 3e45410

6 files changed

Lines changed: 41 additions & 20 deletions

File tree

lib/galaxy/tool_util/parameters/case.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ def test_case_state(
5757
if input_name not in by_name:
5858
raise Exception(f"Cannot find tool parameter for {input_name}")
5959
tool_parameter_model = by_name[input_name]
60-
input_value = input["value"]
61-
input_value = legacy_from_string(tool_parameter_model, input_value, warnings, profile)
62-
if isinstance(tool_parameter_model, (DataParameterModel,)):
63-
pass
64-
elif isinstance(tool_parameter_model, (DataCollectionParameterModel,)):
65-
pass
60+
if isinstance(tool_parameter_model, (DataCollectionParameterModel,)):
61+
input_value = input.get("attributes", {}).get("collection")
62+
else:
63+
input_value = input["value"]
64+
input_value = legacy_from_string(tool_parameter_model, input_value, warnings, profile)
6665

6766
state[input_name] = input_value
6867

lib/galaxy/tool_util/parameters/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
)
3838

3939
from galaxy.exceptions import RequestParameterInvalidException
40+
from galaxy.tool_util.parser.interface import TestCollectionDict
4041
from ._types import (
4142
cast_as_type,
4243
is_optional,
@@ -368,6 +369,8 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
368369
return dynamic_model_information_from_py_type(self, type(None), requires_value=False)
369370
elif state_representation == "workflow_step_linked":
370371
return dynamic_model_information_from_py_type(self, ConnectedValue)
372+
elif state_representation == "test_case_xml":
373+
return dynamic_model_information_from_py_type(self, TestCollectionDict)
371374
else:
372375
raise NotImplementedError(f"Have not implemented data collection parameter models for state representation {state_representation}")
373376

lib/galaxy/tool_util/parser/interface.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import packaging.version
2020
from pydantic import BaseModel
2121
from typing_extensions import (
22+
Literal,
2223
NotRequired,
2324
TypedDict,
2425
)
@@ -376,7 +377,7 @@ def paths_and_modtimes(self):
376377
paths_and_modtimes[self.source_path] = os.path.getmtime(self.source_path)
377378
return paths_and_modtimes
378379

379-
def parse_tests_to_dict(self) -> ToolSourceTests:
380+
def parse_tests_to_dict(self, for_json: bool = False) -> ToolSourceTests:
380381
return {"tests": []}
381382

382383
def __str__(self):
@@ -525,6 +526,23 @@ def parse_input_sources(self) -> List[InputSource]:
525526
"""Return a list of InputSource objects."""
526527

527528

529+
TestCollectionAttributeDict = Dict[str, Any]
530+
CollectionType = str
531+
532+
533+
class TestCollectionDictElement(TypedDict):
534+
element_identifier: str
535+
element_definition: Union["TestCollectionDict", "ToolSourceTestInput"]
536+
537+
538+
class TestCollectionDict(TypedDict):
539+
model_class: Literal["TestCollectionDef"] = "TestCollectionDef"
540+
attributes: TestCollectionAttributeDict
541+
collection_type: CollectionType
542+
elements: List[TestCollectionDictElement]
543+
name: str
544+
545+
528546
class TestCollectionDef:
529547
__test__ = False # Prevent pytest from discovering this class (issue #12071)
530548

lib/galaxy/tool_util/parser/xml.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,15 @@ def macro_paths(self):
650650
def source_path(self):
651651
return self._source_path
652652

653-
def parse_tests_to_dict(self) -> ToolSourceTests:
653+
def parse_tests_to_dict(self, for_json: bool = False) -> ToolSourceTests:
654654
tests_elem = self.root.find("tests")
655655
tests: List[ToolSourceTest] = []
656656
rval: ToolSourceTests = dict(tests=tests)
657657

658658
if tests_elem is not None:
659659
for i, test_elem in enumerate(tests_elem.findall("test")):
660660
profile = self.parse_profile()
661-
tests.append(_test_elem_to_dict(test_elem, i, profile))
661+
tests.append(_test_elem_to_dict(test_elem, i, profile, for_json=for_json))
662662

663663
return rval
664664

@@ -715,11 +715,11 @@ def parse_creator(self):
715715
return creators
716716

717717

718-
def _test_elem_to_dict(test_elem, i, profile=None) -> ToolSourceTest:
718+
def _test_elem_to_dict(test_elem, i, profile=None, for_json=False) -> ToolSourceTest:
719719
rval: ToolSourceTest = dict(
720720
outputs=__parse_output_elems(test_elem),
721721
output_collections=__parse_output_collection_elems(test_elem, profile=profile),
722-
inputs=__parse_input_elems(test_elem, i),
722+
inputs=__parse_input_elems(test_elem, i, for_json=for_json),
723723
expect_num_outputs=test_elem.get("expect_num_outputs"),
724724
command=__parse_assert_list_from_elem(test_elem.find("assert_command")),
725725
command_version=__parse_assert_list_from_elem(test_elem.find("assert_command_version")),
@@ -734,9 +734,9 @@ def _test_elem_to_dict(test_elem, i, profile=None) -> ToolSourceTest:
734734
return rval
735735

736736

737-
def __parse_input_elems(test_elem, i) -> ToolSourceTestInputs:
737+
def __parse_input_elems(test_elem, i, for_json=False) -> ToolSourceTestInputs:
738738
__expand_input_elems(test_elem)
739-
return __parse_inputs_elems(test_elem, i)
739+
return __parse_inputs_elems(test_elem, i, for_json=for_json)
740740

741741

742742
def __parse_output_elems(test_elem) -> ToolSourceTestOutputs:
@@ -982,15 +982,15 @@ def _copy_to_dict_if_present(elem, rval, attributes):
982982
return rval
983983

984984

985-
def __parse_inputs_elems(test_elem, i) -> ToolSourceTestInputs:
985+
def __parse_inputs_elems(test_elem, i, for_json=False) -> ToolSourceTestInputs:
986986
raw_inputs: ToolSourceTestInputs = []
987987
for param_elem in test_elem.findall("param"):
988-
raw_inputs.append(__parse_param_elem(param_elem, i))
988+
raw_inputs.append(__parse_param_elem(param_elem, i, for_json=for_json))
989989

990990
return raw_inputs
991991

992992

993-
def __parse_param_elem(param_elem, i=0) -> ToolSourceTestInput:
993+
def __parse_param_elem(param_elem, i=0, for_json=False) -> ToolSourceTestInput:
994994
attrib: ToolSourceTestInputAttributes = dict(param_elem.attrib)
995995
if "values" in attrib:
996996
value = attrib["values"].split(",")
@@ -1028,7 +1028,8 @@ def __parse_param_elem(param_elem, i=0) -> ToolSourceTestInput:
10281028
elif child.tag == "edit_attributes":
10291029
attrib["edit_attributes"].append(child)
10301030
elif child.tag == "collection":
1031-
attrib["collection"] = TestCollectionDef.from_xml(child, __parse_param_elem)
1031+
collection = TestCollectionDef.from_xml(child, lambda elem: __parse_param_elem(elem, for_json=for_json))
1032+
attrib["collection"] = collection if not for_json else collection.to_dict()
10321033
if composite_data_name:
10331034
# Composite datasets need implicit renaming;
10341035
# inserted at front of list so explicit declarations

lib/galaxy/tool_util/parser/yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def _parse_output_collection(self, tool, name, output_dict):
189189
)
190190
return output_collection
191191

192-
def parse_tests_to_dict(self) -> ToolSourceTests:
192+
def parse_tests_to_dict(self, for_json: bool = False) -> ToolSourceTests:
193193
tests: List[ToolSourceTest] = []
194194
rval: ToolSourceTests = dict(tests=tests)
195195

test/unit/tool_util/test_parameter_test_cases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_validate_framework_test_tools():
3535
tool_source = get_tool_source(tool_path)
3636
parsed_tool = parse_tool(tool_source)
3737
profile = tool_source.parse_profile()
38-
test_cases: List[ToolSourceTest] = tool_source.parse_tests_to_dict()["tests"]
38+
test_cases: List[ToolSourceTest] = tool_source.parse_tests_to_dict(for_json=True)["tests"]
3939
for test_case in test_cases:
4040
test_case_state_and_warnings = case_state(test_case, parsed_tool.inputs, profile)
4141
tool_state = test_case_state_and_warnings.tool_state
@@ -47,7 +47,7 @@ def validate_test_cases_for(tool_name: str) -> List[List[str]]:
4747
tool_parameter_bundle = parameter_bundle_for_file(tool_name)
4848
tool_source = parameter_tool_source(tool_name)
4949
profile = tool_source.parse_profile()
50-
test_cases: List[ToolSourceTest] = tool_source.parse_tests_to_dict()["tests"]
50+
test_cases: List[ToolSourceTest] = tool_source.parse_tests_to_dict(for_json=True)["tests"]
5151
warnings_by_test = []
5252
for test_case in test_cases:
5353
test_case_state_and_warnings = case_state(test_case, tool_parameter_bundle, profile)

0 commit comments

Comments
 (0)