From bc441f17d516083ecac290e8dc86382722b8bbdd Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 11:28:19 +1100 Subject: [PATCH 01/13] Added TestOutputCollection - a test parameter that generates a test output collection stub Seems to generate fine - tools passing tests - although at present it has no assertions - how to generate a "proper" test since the generated collection contents are only guessable from the script so would need some file names to check in the collection from the user? --- examples/example.py | 2 ++ galaxyxml/tool/parameters/__init__.py | 28 +++++++++++++++++++++++++++ test/import_xml.xml | 1 + test/unit_test_import_xml.py | 5 +++++ 4 files changed, 36 insertions(+) diff --git a/examples/example.py b/examples/example.py index f7e91b1..7d0439d 100644 --- a/examples/example.py +++ b/examples/example.py @@ -104,6 +104,8 @@ test_a.append(param) test_out = gxtp.TestOutput(name="output", value="file.out") test_a.append(test_out) +coll_out = gxtp.TestOutputCollection(name="coll_out") +test_a.append(coll_out) tool.tests.append(test_a) diff --git a/galaxyxml/tool/parameters/__init__.py b/galaxyxml/tool/parameters/__init__.py index 2387582..ae001e1 100644 --- a/galaxyxml/tool/parameters/__init__.py +++ b/galaxyxml/tool/parameters/__init__.py @@ -859,6 +859,7 @@ class Test(XMLParam): def acceptable_child(self, child): return isinstance(child, TestParam) \ or isinstance(child, TestOutput) \ + or isinstance(child, TestOutputCollection) \ or isinstance(child, Expand) @@ -891,6 +892,33 @@ def __init__( super(TestOutput, self).__init__(**params) +class TestOutputCollection(XMLParam): + name = "output_collection" + + def __init__( + self, + name=None, + ftype=None, + sort=None, + value=None, + compare=None, + lines_diff=None, + delta=None, + **kwargs, + ): + params = Util.clean_kwargs(locals().copy()) + super(TestOutputCollection, self).__init__(**params) + + def command_line_before(self, mako_path): + return "" % self.name + + def command_line_after(self): + return "" + + def command_line_actual(self, mako_path): + return "" + + class Citations(XMLParam): name = "citations" diff --git a/test/import_xml.xml b/test/import_xml.xml index 256145e..0e864db 100644 --- a/test/import_xml.xml +++ b/test/import_xml.xml @@ -71,6 +71,7 @@ + diff --git a/test/unit_test_import_xml.py b/test/unit_test_import_xml.py index 7cd56b5..b107c1a 100644 --- a/test/unit_test_import_xml.py +++ b/test/unit_test_import_xml.py @@ -192,3 +192,8 @@ def test_load_output(self): output = self.tool.tests.children[0].node[1] self.assertEqual(output.attrib["file"], "file.gbk") self.assertEqual(output.attrib["name"], "genbank") + + def test_collection_output(self): + output = self.tool.tests.children[0].node[2] + self.assertEqual(output.attrib["name"], "pdf_out.foo") + From cf24fa72b7179e968fc17b156c514fe33052069c Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 11:32:11 +1100 Subject: [PATCH 02/13] forgot to remove bogus name from trying to fail a test :( --- test/unit_test_import_xml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit_test_import_xml.py b/test/unit_test_import_xml.py index b107c1a..17e0ece 100644 --- a/test/unit_test_import_xml.py +++ b/test/unit_test_import_xml.py @@ -195,5 +195,5 @@ def test_load_output(self): def test_collection_output(self): output = self.tool.tests.children[0].node[2] - self.assertEqual(output.attrib["name"], "pdf_out.foo") + self.assertEqual(output.attrib["name"], "pdf_out") From 63332dc73da5571e930c0302c37a8fd90bf080a6 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 11:39:31 +1100 Subject: [PATCH 03/13] updated example outputs --- examples/example_macros.xml | 3 +-- examples/tool.xml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/example_macros.xml b/examples/example_macros.xml index 912b740..6050ea6 100644 --- a/examples/example_macros.xml +++ b/examples/example_macros.xml @@ -9,8 +9,7 @@ $posint select_local $select_local]]> - +
diff --git a/examples/tool.xml b/examples/tool.xml index f3b84c0..a975172 100644 --- a/examples/tool.xml +++ b/examples/tool.xml @@ -67,6 +67,7 @@ select_local $select_local + From fa4a50a84d87b99d7e549987cd0f29b3b616944f Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 11:53:28 +1100 Subject: [PATCH 04/13] probably needs a version bump as is a new feature? --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 500657e..d672a8e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="galaxyxml", - version="0.4.12", + version="0.4.13", description="Galaxy XML generation library", author="Helena Rasche", author_email="hxr@hx42.org", From 15b89e88729b3cf754aa2630a38fcd65d864c71a Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 13:09:43 +1100 Subject: [PATCH 05/13] fixed tests - added output_collection to test parser in import_xml.py and adjusted test outputs --- examples/example.py | 2 +- examples/tool.xml | 2 +- galaxyxml/tool/import_xml.py | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/examples/example.py b/examples/example.py index 7d0439d..75fdb04 100644 --- a/examples/example.py +++ b/examples/example.py @@ -104,7 +104,7 @@ test_a.append(param) test_out = gxtp.TestOutput(name="output", value="file.out") test_a.append(test_out) -coll_out = gxtp.TestOutputCollection(name="coll_out") +coll_out = gxtp.TestOutputCollection(name="pdf_out") test_a.append(coll_out) tool.tests.append(test_a) diff --git a/examples/tool.xml b/examples/tool.xml index a975172..4c38f6f 100644 --- a/examples/tool.xml +++ b/examples/tool.xml @@ -67,7 +67,7 @@ select_local $select_local - + diff --git a/galaxyxml/tool/import_xml.py b/galaxyxml/tool/import_xml.py index fb08495..6457b4f 100644 --- a/galaxyxml/tool/import_xml.py +++ b/galaxyxml/tool/import_xml.py @@ -698,6 +698,30 @@ def _load_output(self, test_root, output_root): ) ) + def _load_output_collection(self, test_root, output_root): + """ + Add to the . + + :param root: root to append to. + :param repeat_root: root of tag. + :param repeat_root: :class:`xml.etree._Element` + """ + test_root.append( + gxtp.TestOutputCollection( + name=output_root.attrib.get("name", None), + file=output_root.attrib.get("file", None), + ftype=output_root.attrib.get("ftype", None), + sort=output_root.attrib.get("sort", None), + value=output_root.attrib.get("value", None), + md5=output_root.attrib.get("md5", None), + checksum=output_root.attrib.get("checksum", None), + compare=output_root.attrib.get("compare", None), + lines_diff=output_root.attrib.get("lines_diff", None), + delta=output_root.attrib.get("delta", None), + ) + ) + + def load_tests(self, root, tests_root): """ Add to the root. From d0725f52f17ce1b25b2793411b3b5f21ac93fd02 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 31 Mar 2021 13:41:02 +1100 Subject: [PATCH 06/13] reverting examples/example_macros.xml - regenerating didn't help --- examples/example_macros.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/example_macros.xml b/examples/example_macros.xml index 6050ea6..912b740 100644 --- a/examples/example_macros.xml +++ b/examples/example_macros.xml @@ -9,7 +9,8 @@ $posint select_local $select_local]]> - +
From 6ebc4fc5cfe2e64614aec5ec11b9d0b9c12e4f56 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Mon, 5 Apr 2021 21:23:21 +1000 Subject: [PATCH 07/13] Working on repeats - complex... --- examples/example.py | 4 +++ examples/tool.xml | 3 ++ galaxyxml/__init__.py | 4 +-- galaxyxml/tool/import_xml.py | 17 +++++++++++ galaxyxml/tool/parameters/__init__.py | 43 ++++++++++++++++++++++++--- test/import_xml.xml | 3 ++ test/unit_test_import_xml.py | 5 ++++ 7 files changed, 73 insertions(+), 6 deletions(-) diff --git a/examples/example.py b/examples/example.py index 75fdb04..69d5e83 100644 --- a/examples/example.py +++ b/examples/example.py @@ -106,6 +106,10 @@ test_a.append(test_out) coll_out = gxtp.TestOutputCollection(name="pdf_out") test_a.append(coll_out) +rep_out = gxtp.TestRepeat(name="testrepeat") +param = gxtp.TestParam("repeatchild", value="foo") +rep_out.append(param) +test_a.append(rep_out) tool.tests.append(test_a) diff --git a/examples/tool.xml b/examples/tool.xml index 4c38f6f..c574e0a 100644 --- a/examples/tool.xml +++ b/examples/tool.xml @@ -68,6 +68,9 @@ select_local $select_local + + + diff --git a/galaxyxml/__init__.py b/galaxyxml/__init__.py index 3486a71..38fc4a7 100644 --- a/galaxyxml/__init__.py +++ b/galaxyxml/__init__.py @@ -1,6 +1,6 @@ from builtins import ( - str, - object + object, + str ) from lxml import etree diff --git a/galaxyxml/tool/import_xml.py b/galaxyxml/tool/import_xml.py index 6457b4f..69ae982 100644 --- a/galaxyxml/tool/import_xml.py +++ b/galaxyxml/tool/import_xml.py @@ -721,6 +721,23 @@ def _load_output_collection(self, test_root, output_root): ) ) + def _load_repeat(self, test_root, output_root): + """ + Add to the . + + :param root: root to append to. + :param output_root: root of tag. + :param output_root: :class:`xml.etree._Element` + """ + test_root.append( + gxtp.TestRepeat( + output_root.attrib.get("name", None), + output_root.attrib.get("title",None), + min=output_root.attrib.get("min", None), + max=output_root.attrib.get("max", None), + default=output_root.attrib.get("default", None) + ) + ) def load_tests(self, root, tests_root): """ diff --git a/galaxyxml/tool/parameters/__init__.py b/galaxyxml/tool/parameters/__init__.py index ae001e1..b7a523f 100644 --- a/galaxyxml/tool/parameters/__init__.py +++ b/galaxyxml/tool/parameters/__init__.py @@ -1,12 +1,13 @@ +import logging from builtins import ( - str, - object + object, + str ) -import logging + +from galaxy.tool_util.parser.util import _parse_name from galaxyxml import Util -from galaxy.tool_util.parser.util import _parse_name from lxml import etree logging.basicConfig(level=logging.INFO) @@ -860,6 +861,7 @@ def acceptable_child(self, child): return isinstance(child, TestParam) \ or isinstance(child, TestOutput) \ or isinstance(child, TestOutputCollection) \ + or isinstance(child, TestRepeat) \ or isinstance(child, Expand) @@ -916,8 +918,41 @@ def command_line_after(self): return "" def command_line_actual(self, mako_path): + return "" +class TestRepeat(XMLParam): + name = "repeat" + + def __init__( + self, + name=None, + ftype=None, + sort=None, + value=None, + compare=None, + lines_diff=None, + delta=None, + **kwargs, + ): + params = Util.clean_kwargs(locals().copy()) + super(TestRepeat, self).__init__(**params) + + def acceptable_child(self, child): + return issubclass(type(child), TestParam) + + def command_line_before(self, mako_path): + return "" % self.name + + def command_line_after(self): + return "" + + def command_line_actual(self, mako_path): + lines = [] + for child in self.children: + lines.append(child.command_line()) + return "\n".join(lines) + class Citations(XMLParam): name = "citations" diff --git a/test/import_xml.xml b/test/import_xml.xml index 0e864db..b654960 100644 --- a/test/import_xml.xml +++ b/test/import_xml.xml @@ -72,6 +72,9 @@ + + + diff --git a/test/unit_test_import_xml.py b/test/unit_test_import_xml.py index 17e0ece..18e2cd0 100644 --- a/test/unit_test_import_xml.py +++ b/test/unit_test_import_xml.py @@ -197,3 +197,8 @@ def test_collection_output(self): output = self.tool.tests.children[0].node[2] self.assertEqual(output.attrib["name"], "pdf_out") + def test_repeat(self): + output = self.tool.tests.children[0].node[3] + self.assertEqual(output.attrib["name"],"test_repeat") + # how to test the repeat's parameter is parsed? + From ed27141a76ad09eb87d226b8ca0521375de0c520 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 08:42:48 +1000 Subject: [PATCH 08/13] Added README.md and setup.py notes to include version bump --- README.rst | 3 +++ setup.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 9224608..415279d 100644 --- a/README.rst +++ b/README.rst @@ -20,6 +20,9 @@ License Changelog --------- +- 0.4.13 + + - Add TestOutputCollection and tests (thanks @fubar2) - 0.4.12 diff --git a/setup.py b/setup.py index d672a8e..d8ad24a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="galaxyxml", - version="0.4.13", + version="0.4.14", description="Galaxy XML generation library", author="Helena Rasche", author_email="hxr@hx42.org", From 9cb716f4d95024c66ef06ba9944ff8e7073c212a Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 10:03:35 +1000 Subject: [PATCH 09/13] Removed a couple of bogus copypasta parameters from load_output_collection in import_xml.py to align with the init of TestOutputCollection. Still passes tests :) --- galaxyxml/tool/import_xml.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/galaxyxml/tool/import_xml.py b/galaxyxml/tool/import_xml.py index 6457b4f..ae29423 100644 --- a/galaxyxml/tool/import_xml.py +++ b/galaxyxml/tool/import_xml.py @@ -709,12 +709,9 @@ def _load_output_collection(self, test_root, output_root): test_root.append( gxtp.TestOutputCollection( name=output_root.attrib.get("name", None), - file=output_root.attrib.get("file", None), ftype=output_root.attrib.get("ftype", None), sort=output_root.attrib.get("sort", None), value=output_root.attrib.get("value", None), - md5=output_root.attrib.get("md5", None), - checksum=output_root.attrib.get("checksum", None), compare=output_root.attrib.get("compare", None), lines_diff=output_root.attrib.get("lines_diff", None), delta=output_root.attrib.get("delta", None), From 9b3e81df604f81eae7f6d8f45b8a84ea3d516a1b Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 11:18:32 +1000 Subject: [PATCH 10/13] grrrr - overbumped setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d8ad24a..d672a8e 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="galaxyxml", - version="0.4.14", + version="0.4.13", description="Galaxy XML generation library", author="Helena Rasche", author_email="hxr@hx42.org", From 3414b714304593045974dfa2de37229d36d8cf71 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 15:00:12 +1000 Subject: [PATCH 11/13] Looks like TestRepeat is working - tests work and one sample tested. --- galaxyxml/tool/import_xml.py | 34 +++++++++++++++++++++++++--------- test/unit_test_import_xml.py | 9 +++++---- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/galaxyxml/tool/import_xml.py b/galaxyxml/tool/import_xml.py index 69ae982..a05f781 100644 --- a/galaxyxml/tool/import_xml.py +++ b/galaxyxml/tool/import_xml.py @@ -721,7 +721,7 @@ def _load_output_collection(self, test_root, output_root): ) ) - def _load_repeat(self, test_root, output_root): + def _load_repeat(self, root, repeat_root): """ Add to the . @@ -729,15 +729,31 @@ def _load_repeat(self, test_root, output_root): :param output_root: root of tag. :param output_root: :class:`xml.etree._Element` """ - test_root.append( - gxtp.TestRepeat( - output_root.attrib.get("name", None), - output_root.attrib.get("title",None), - min=output_root.attrib.get("min", None), - max=output_root.attrib.get("max", None), - default=output_root.attrib.get("default", None) + + repeat = gxtp.TestRepeat( + repeat_root.attrib.get("name", None), + repeat_root.attrib.get("title",None), + min=repeat_root.attrib.get("min", None), + max=repeat_root.attrib.get("max", None), + default=repeat_root.attrib.get("default", None) ) - ) + # Deal with child nodes + self.load_inputs(repeat, repeat_root) + root.append(repeat) + + def load_inputs(self, repeat, repeat_root): + """ + Add children to repeat for test + + :param repeat_root: repeat to attach inputs to. + :param repeat: root of tag. + :type repeat_root: :class:`xml.etree._Element` + """ + for rep_child in repeat_root: + try: + getattr(self, "_load_{}".format(rep_child.tag))(repeat, rep_child) + except AttributeError: + logger.warning(inp_child.tag + " tag is not processed for <" + repeat_root.tag + "> tag.") def load_tests(self, root, tests_root): """ diff --git a/test/unit_test_import_xml.py b/test/unit_test_import_xml.py index 18e2cd0..a41fcdb 100644 --- a/test/unit_test_import_xml.py +++ b/test/unit_test_import_xml.py @@ -198,7 +198,8 @@ def test_collection_output(self): self.assertEqual(output.attrib["name"], "pdf_out") def test_repeat(self): - output = self.tool.tests.children[0].node[3] - self.assertEqual(output.attrib["name"],"test_repeat") - # how to test the repeat's parameter is parsed? - + repeat = self.tool.tests.children[0].node[3] + self.assertEqual(repeat.attrib["name"],"test_repeat") + # test param within repeat + self.assertEqual(repeat[0].attrib["name"], "repeatchild") + self.assertEqual(repeat[0].attrib["value"], "foo") From 7dc600e94e1b937564563c77f33e7ff2edbe038b Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 15:05:35 +1000 Subject: [PATCH 12/13] Updated readme to include testrepeat --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 415279d..84250cc 100644 --- a/README.rst +++ b/README.rst @@ -22,7 +22,7 @@ Changelog --------- - 0.4.13 - - Add TestOutputCollection and tests (thanks @fubar2) + - Add TestOutputCollection, TestRepeat and tests (thanks @fubar2) - 0.4.12 From 12b345d6ba3485b56154705189b681b38ba065b8 Mon Sep 17 00:00:00 2001 From: fubar2 Date: Wed, 7 Apr 2021 15:11:18 +1000 Subject: [PATCH 13/13] Flake news fixed. Oy. --- galaxyxml/tool/import_xml.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/galaxyxml/tool/import_xml.py b/galaxyxml/tool/import_xml.py index c9b34c4..ec645ba 100644 --- a/galaxyxml/tool/import_xml.py +++ b/galaxyxml/tool/import_xml.py @@ -728,13 +728,13 @@ def _load_repeat(self, root, repeat_root): """ repeat = gxtp.TestRepeat( - repeat_root.attrib.get("name", None), - repeat_root.attrib.get("title",None), - min=repeat_root.attrib.get("min", None), - max=repeat_root.attrib.get("max", None), - default=repeat_root.attrib.get("default", None) - ) - # Deal with child nodes + repeat_root.attrib.get("name", None), + repeat_root.attrib.get("title",None), + min=repeat_root.attrib.get("min", None), + max=repeat_root.attrib.get("max", None), + default=repeat_root.attrib.get("default", None) + ) + # Deal with child nodes self.load_inputs(repeat, repeat_root) root.append(repeat) @@ -750,7 +750,7 @@ def load_inputs(self, repeat, repeat_root): try: getattr(self, "_load_{}".format(rep_child.tag))(repeat, rep_child) except AttributeError: - logger.warning(inp_child.tag + " tag is not processed for <" + repeat_root.tag + "> tag.") + logger.warning(rep_child.tag + " tag is not processed for <" + repeat_root.tag + "> tag.") def load_tests(self, root, tests_root): """