@@ -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
742742def __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
0 commit comments