Skip to content

Commit

Permalink
Merge pull request galaxyproject#17641 from bernt-matthias/yaml-neste…
Browse files Browse the repository at this point in the history
…d-assertions

[23.2] Yaml nested assertions: fix parsing
  • Loading branch information
mvdbeek authored Mar 11, 2024
2 parents 8697be0 + 5a48f66 commit b73d9e2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/parser/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
9 changes: 5 additions & 4 deletions lib/galaxy/tool_util/parser/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions test/unit/tool_util/test_test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b73d9e2

Please sign in to comment.