diff --git a/lib/galaxy/tool_util/parser/interface.py b/lib/galaxy/tool_util/parser/interface.py index f4c65c13dd0c..0572b8b57960 100644 --- a/lib/galaxy/tool_util/parser/interface.py +++ b/lib/galaxy/tool_util/parser/interface.py @@ -35,7 +35,7 @@ class AssertionDict(TypedDict): tag: str attributes: Dict[str, Any] - children: Optional[List[Dict[str, Any]]] + children: "AssertionList" AssertionList = Optional[List[AssertionDict]] diff --git a/lib/galaxy/tool_util/parser/yaml.py b/lib/galaxy/tool_util/parser/yaml.py index c39599849744..3270b49dead3 100644 --- a/lib/galaxy/tool_util/parser/yaml.py +++ b/lib/galaxy/tool_util/parser/yaml.py @@ -287,10 +287,11 @@ def expand_dict_form(item): new_assertion["that"] = assertion_key new_assertion.update(assertion_value) assertion = new_assertion - children = [] - if "children" in assertion: - children = assertion["children"] - del assertion["children"] + children = assertion.pop("asserts", assertion.pop("children", [])) + # if there are no nested assertions then children should be [] + # but to_test_assert_list would return None + if children: + children = to_test_assert_list(children) assert_dict: AssertionDict = dict( tag=assertion["that"], attributes=assertion, diff --git a/test/unit/tool_util/test_test_parsing.py b/test/unit/tool_util/test_test_parsing.py index c489d9658cae..ca6765d598cd 100644 --- a/test/unit/tool_util/test_test_parsing.py +++ b/test/unit/tool_util/test_test_parsing.py @@ -38,3 +38,26 @@ def test_simple_assert_to_test_assert_list(): def test_assert_legacy_same_as_new_list_style(): assert to_test_assert_list(ASSERT_THAT_LIST) == to_test_assert_list(ASSERT_THAT_LIST) + + +NESTED_ASSERT_LIST = yaml.safe_load( + """ +- has_archive_member: + path: ".*" + asserts: + - has_text: + text: "a text" + - has_text: + text: "another text" +""" +) + + +def test_nested_asserts(): + asserts = to_test_assert_list(NESTED_ASSERT_LIST) + assert asserts and len(asserts) == 1 + assert asserts and asserts[0]["children"] and len(asserts[0]["children"]) == 2 + assert asserts and asserts[0]["children"] and asserts[0]["children"][0]["tag"] == "has_text" + assert asserts and asserts[0]["children"] and asserts[0]["children"][0]["attributes"]["text"] == "a text" + assert asserts and asserts[0]["children"] and asserts[0]["children"][1]["tag"] == "has_text" + assert asserts and asserts[0]["children"] and asserts[0]["children"][1]["attributes"]["text"] == "another text"