3737)
3838
3939from galaxy .exceptions import RequestParameterInvalidException
40- from galaxy .tool_util .parser .interface import DrillDownOptionsDict
40+ from galaxy .tool_util .parser .interface import (
41+ DrillDownOptionsDict ,
42+ TestCollectionDict ,
43+ )
4144from ._types import (
4245 cast_as_type ,
4346 is_optional ,
5861# + request_internal: This is a pydantic model to validate what Galaxy expects to find in the database,
5962# in particular dataset and collection references should be decoded integers.
6063StateRepresentationT = Literal [
61- "request" , "request_internal" , "job_internal" , "test_case " , "workflow_step" , "workflow_step_linked"
64+ "request" , "request_internal" , "job_internal" , "test_case_xml " , "workflow_step" , "workflow_step_linked"
6265]
6366
6467
@@ -311,9 +314,9 @@ def py_type_internal(self) -> Type:
311314 def py_type_test_case (self ) -> Type :
312315 base_model : Type
313316 if self .multiple :
314- base_model = MultiDataRequestInternal
317+ base_model = str
315318 else :
316- base_model = DataTestCaseValue
319+ base_model = str
317320 return optional_if_needed (base_model , self .optional )
318321
319322 def pydantic_template (self , state_representation : StateRepresentationT ) -> DynamicModelInformation :
@@ -325,7 +328,7 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
325328 )
326329 elif state_representation == "job_internal" :
327330 return dynamic_model_information_from_py_type (self , self .py_type_internal )
328- elif state_representation == "test_case " :
331+ elif state_representation == "test_case_xml " :
329332 return dynamic_model_information_from_py_type (self , self .py_type_test_case )
330333 elif state_representation == "workflow_step" :
331334 return dynamic_model_information_from_py_type (self , type (None ), requires_value = False )
@@ -369,6 +372,8 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
369372 return dynamic_model_information_from_py_type (self , type (None ), requires_value = False )
370373 elif state_representation == "workflow_step_linked" :
371374 return dynamic_model_information_from_py_type (self , ConnectedValue )
375+ elif state_representation == "test_case_xml" :
376+ return dynamic_model_information_from_py_type (self , TestCollectionDict )
372377 else :
373378 raise NotImplementedError (
374379 f"Have not implemented data collection parameter models for state representation { state_representation } "
@@ -529,17 +534,23 @@ class SelectParameterModel(BaseGalaxyToolParameterModelDefinition):
529534 options : Optional [List [LabelValue ]] = None
530535 multiple : bool
531536
532- def py_type_if_required (self , allow_connections = False ) -> Type :
537+ def py_type_if_required (self , allow_connections : bool = False , expect_list : bool = True ) -> Type :
533538 if self .options is not None :
534539 literal_options : List [Type ] = [cast_as_type (Literal [o .value ]) for o in self .options ]
535540 py_type = union_type (literal_options )
536541 else :
537542 py_type = StrictStr
538543 if self .multiple :
539544 if allow_connections :
540- py_type = list_type (allow_connected_value (py_type ))
545+ if expect_list :
546+ py_type = list_type (allow_connected_value (py_type ))
547+ else :
548+ py_type = allow_connected_value (py_type )
541549 else :
542- py_type = list_type (py_type )
550+ if expect_list :
551+ py_type = list_type (py_type )
552+ else :
553+ py_type = py_type
543554 elif allow_connections :
544555 py_type = allow_connected_value (py_type )
545556 return py_type
@@ -559,6 +570,10 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
559570 elif state_representation == "workflow_step_linked" :
560571 py_type = self .py_type_if_required (allow_connections = True )
561572 return dynamic_model_information_from_py_type (self , optional_if_needed (py_type , self .optional ))
573+ elif state_representation == "test_case_xml" :
574+ # in a YAML test case representation this can be string, in XML we are still expecting a comma separated string
575+ py_type = self .py_type_if_required (allow_connections = False , expect_list = False )
576+ return dynamic_model_information_from_py_type (self , optional_if_needed (py_type , self .optional ))
562577 else :
563578 return dynamic_model_information_from_py_type (self , self .py_type )
564579
@@ -1018,9 +1033,13 @@ class ToolParameterBundleModel(BaseModel):
10181033 input_models : List [ToolParameterT ]
10191034
10201035
1021- def parameters_by_name (tool_parameter_bundle : ToolParameterBundle ) -> Dict [str , ToolParameterT ]:
1036+ def parameters_by_name (inputs : Union [ Iterable [ ToolParameterModel ], Iterable [ ToolParameterT ], ToolParameterBundle ] ) -> Dict [str , ToolParameterT ]:
10221037 as_dict = {}
1023- for input_model in simple_input_models (tool_parameter_bundle .input_models ):
1038+ if hasattr (inputs , "input_models" ):
1039+ inputs_list = simple_input_models (cast (ToolParameterBundle , inputs .input_models ))
1040+ else :
1041+ inputs_list = cast (Union [Iterable [ToolParameterModel ], Iterable [ToolParameterT ]], inputs )
1042+ for input_model in inputs_list :
10241043 as_dict [input_model .name ] = input_model
10251044 return as_dict
10261045
@@ -1058,7 +1077,7 @@ def create_job_internal_model(tool: ToolParameterBundle, name: str = "DynamicMod
10581077
10591078
10601079def create_test_case_model (tool : ToolParameterBundle , name : str = "DynamicModelForTool" ) -> Type [BaseModel ]:
1061- return create_field_model (tool .input_models , name , "test_case " )
1080+ return create_field_model (tool .input_models , name , "test_case_xml " )
10621081
10631082
10641083def create_workflow_step_model (tool : ToolParameterBundle , name : str = "DynamicModelForTool" ) -> Type [BaseModel ]:
0 commit comments