3737)
3838
3939from galaxy .exceptions import RequestParameterInvalidException
40+ from galaxy .tool_util .parser .interface import TestCollectionDict
4041from ._types import (
4142 cast_as_type ,
4243 is_optional ,
5758# + request_internal: This is a pydantic model to validate what Galaxy expects to find in the database,
5859# in particular dataset and collection references should be decoded integers.
5960StateRepresentationT = Literal [
60- "request" , "request_internal" , "job_internal" , "test_case " , "workflow_step" , "workflow_step_linked"
61+ "request" , "request_internal" , "job_internal" , "test_case_xml " , "workflow_step" , "workflow_step_linked"
6162]
6263
6364
@@ -310,9 +311,9 @@ def py_type_internal(self) -> Type:
310311 def py_type_test_case (self ) -> Type :
311312 base_model : Type
312313 if self .multiple :
313- base_model = MultiDataRequestInternal
314+ base_model = str
314315 else :
315- base_model = DataTestCaseValue
316+ base_model = str
316317 return optional_if_needed (base_model , self .optional )
317318
318319 def pydantic_template (self , state_representation : StateRepresentationT ) -> DynamicModelInformation :
@@ -324,7 +325,7 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
324325 )
325326 elif state_representation == "job_internal" :
326327 return dynamic_model_information_from_py_type (self , self .py_type_internal )
327- elif state_representation == "test_case " :
328+ elif state_representation == "test_case_xml " :
328329 return dynamic_model_information_from_py_type (self , self .py_type_test_case )
329330 elif state_representation == "workflow_step" :
330331 return dynamic_model_information_from_py_type (self , type (None ), requires_value = False )
@@ -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 (
373376 f"Have not implemented data collection parameter models for state representation { state_representation } "
@@ -528,17 +531,23 @@ class SelectParameterModel(BaseGalaxyToolParameterModelDefinition):
528531 options : Optional [List [LabelValue ]] = None
529532 multiple : bool
530533
531- def py_type_if_required (self , allow_connections = False ) -> Type :
534+ def py_type_if_required (self , allow_connections : bool = False , expect_list : bool = True ) -> Type :
532535 if self .options is not None :
533536 literal_options : List [Type ] = [cast_as_type (Literal [o .value ]) for o in self .options ]
534537 py_type = union_type (literal_options )
535538 else :
536539 py_type = StrictStr
537540 if self .multiple :
538541 if allow_connections :
539- py_type = list_type (allow_connected_value (py_type ))
542+ if expect_list :
543+ py_type = list_type (allow_connected_value (py_type ))
544+ else :
545+ py_type = allow_connected_value (py_type )
540546 else :
541- py_type = list_type (py_type )
547+ if expect_list :
548+ py_type = list_type (py_type )
549+ else :
550+ py_type = py_type
542551 elif allow_connections :
543552 py_type = allow_connected_value (py_type )
544553 return py_type
@@ -558,6 +567,10 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
558567 elif state_representation == "workflow_step_linked" :
559568 py_type = self .py_type_if_required (allow_connections = True )
560569 return dynamic_model_information_from_py_type (self , optional_if_needed (py_type , self .optional ))
570+ elif state_representation == "test_case_xml" :
571+ # in a YAML test case representation this can be string, in XML we are still expecting a comma separated string
572+ py_type = self .py_type_if_required (allow_connections = False , expect_list = False )
573+ return dynamic_model_information_from_py_type (self , optional_if_needed (py_type , self .optional ))
561574 else :
562575 return dynamic_model_information_from_py_type (self , self .py_type )
563576
@@ -963,9 +976,13 @@ class ToolParameterBundleModel(BaseModel):
963976 input_models : List [ToolParameterT ]
964977
965978
966- def parameters_by_name (tool_parameter_bundle : ToolParameterBundle ) -> Dict [str , ToolParameterT ]:
979+ def parameters_by_name (inputs : Union [ Iterable [ ToolParameterModel ], Iterable [ ToolParameterT ], ToolParameterBundle ] ) -> Dict [str , ToolParameterT ]:
967980 as_dict = {}
968- for input_model in simple_input_models (tool_parameter_bundle .input_models ):
981+ if hasattr (inputs , "input_models" ):
982+ inputs_list = simple_input_models (cast (ToolParameterBundle , inputs .input_models ))
983+ else :
984+ inputs_list = cast (Union [Iterable [ToolParameterModel ], Iterable [ToolParameterT ]], inputs )
985+ for input_model in inputs_list :
969986 as_dict [input_model .name ] = input_model
970987 return as_dict
971988
@@ -1003,7 +1020,7 @@ def create_job_internal_model(tool: ToolParameterBundle, name: str = "DynamicMod
10031020
10041021
10051022def create_test_case_model (tool : ToolParameterBundle , name : str = "DynamicModelForTool" ) -> Type [BaseModel ]:
1006- return create_field_model (tool .input_models , name , "test_case " )
1023+ return create_field_model (tool .input_models , name , "test_case_xml " )
10071024
10081025
10091026def create_workflow_step_model (tool : ToolParameterBundle , name : str = "DynamicModelForTool" ) -> Type [BaseModel ]:
0 commit comments