From 2a7cce03f30b9b7f264caf5978873ea215598fbe Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Fri, 8 Mar 2024 12:46:17 +0100 Subject: [PATCH 1/5] yaml parsing: fix nested assertions were forgotten to be implemented --- lib/galaxy/tool_util/parser/yaml.py | 5 +---- test/unit/tool_util/test_test_parsing.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/galaxy/tool_util/parser/yaml.py b/lib/galaxy/tool_util/parser/yaml.py index c39599849744..1f3bb1e0da04 100644 --- a/lib/galaxy/tool_util/parser/yaml.py +++ b/lib/galaxy/tool_util/parser/yaml.py @@ -287,10 +287,7 @@ 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 = to_test_assert_list(assertion.pop("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..69dd4d894051 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: ".*" + children: + - has_text: + text: "a text" + - has_text: + text: "another text" +""" +) + + +def test_nested_asserts(): + asserts = to_test_assert_list(NESTED_ASSERT_LIST) + assert len(asserts) == 1 + assert len(asserts[0]["children"]) == 2 + assert asserts[0]["children"][0]["tag"] == "has_text" + assert asserts[0]["children"][0]["attributes"]["text"] == "a text" + assert asserts[0]["children"][1]["tag"] == "has_text" + assert asserts[0]["children"][1]["attributes"]["text"] == "another text" From df7c2af45c753fdf3ed8eb46ecda4b3a2f6706ea Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Fri, 8 Mar 2024 12:47:06 +0100 Subject: [PATCH 2/5] typing fix --- lib/galaxy/tool_util/parser/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]] From e76f5ff4e0053598521422d1091f46f98c206c94 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Fri, 8 Mar 2024 13:05:42 +0100 Subject: [PATCH 3/5] adad test to allow for Optional list --- test/unit/tool_util/test_test_parsing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/tool_util/test_test_parsing.py b/test/unit/tool_util/test_test_parsing.py index 69dd4d894051..16552a12b825 100644 --- a/test/unit/tool_util/test_test_parsing.py +++ b/test/unit/tool_util/test_test_parsing.py @@ -55,9 +55,9 @@ def test_assert_legacy_same_as_new_list_style(): def test_nested_asserts(): asserts = to_test_assert_list(NESTED_ASSERT_LIST) - assert len(asserts) == 1 - assert len(asserts[0]["children"]) == 2 - assert asserts[0]["children"][0]["tag"] == "has_text" - assert asserts[0]["children"][0]["attributes"]["text"] == "a text" - assert asserts[0]["children"][1]["tag"] == "has_text" - assert asserts[0]["children"][1]["attributes"]["text"] == "another text" + 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" From 9a17a0478520d6d68c77014c7ac5c35f63ea8f6d Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Fri, 8 Mar 2024 19:32:04 +0100 Subject: [PATCH 4/5] fix: nested assertions must be list --- lib/galaxy/tool_util/parser/yaml.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/parser/yaml.py b/lib/galaxy/tool_util/parser/yaml.py index 1f3bb1e0da04..3270b49dead3 100644 --- a/lib/galaxy/tool_util/parser/yaml.py +++ b/lib/galaxy/tool_util/parser/yaml.py @@ -287,7 +287,11 @@ def expand_dict_form(item): new_assertion["that"] = assertion_key new_assertion.update(assertion_value) assertion = new_assertion - children = to_test_assert_list(assertion.pop("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, From 5a48f66c4678190a0199416afa4596403a47be64 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Sat, 9 Mar 2024 15:10:52 +0100 Subject: [PATCH 5/5] use asserts also in test --- test/unit/tool_util/test_test_parsing.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/tool_util/test_test_parsing.py b/test/unit/tool_util/test_test_parsing.py index 16552a12b825..ca6765d598cd 100644 --- a/test/unit/tool_util/test_test_parsing.py +++ b/test/unit/tool_util/test_test_parsing.py @@ -44,11 +44,11 @@ def test_assert_legacy_same_as_new_list_style(): """ - has_archive_member: path: ".*" - children: - - has_text: - text: "a text" - - has_text: - text: "another text" + asserts: + - has_text: + text: "a text" + - has_text: + text: "another text" """ )