Skip to content

Commit

Permalink
Merge pull request #33 from fubar2/master
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena authored Apr 7, 2021
2 parents 806488c + 12b345d commit 7d45f9f
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ License

Changelog
---------
- 0.4.13

- Add TestOutputCollection, TestRepeat and tests (thanks @fubar2)

- 0.4.12

Expand Down
6 changes: 6 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
test_a.append(param)
test_out = gxtp.TestOutput(name="output", value="file.out")
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)


Expand Down
4 changes: 4 additions & 0 deletions examples/tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ select_local $select_local
<test>
<param name="float" value="5.4"/>
<output name="output" value="file.out"/>
<output_collection name="pdf_out"/>
<test_repeat name="testrepeat">
<param name="repeatchild" value="foo"/>
</test_repeat>
</test>
</tests>
<help><![CDATA[HI]]></help>
Expand Down
4 changes: 2 additions & 2 deletions galaxyxml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from builtins import (
str,
object
object,
str
)

from lxml import etree
Expand Down
54 changes: 54 additions & 0 deletions galaxyxml/tool/import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,60 @@ def _load_output(self, test_root, output_root):
)
)

def _load_output_collection(self, test_root, output_root):
"""
Add <output_collection> to the <test>.
:param root: <test> root to append <output> to.
:param repeat_root: root of <output_collection> tag.
:param repeat_root: :class:`xml.etree._Element`
"""
test_root.append(
gxtp.TestOutputCollection(
name=output_root.attrib.get("name", None),
ftype=output_root.attrib.get("ftype", None),
sort=output_root.attrib.get("sort", None),
value=output_root.attrib.get("value", 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_repeat(self, root, repeat_root):
"""
Add <test_repeat> to the <test>.
:param root: <test> root to append <output> to.
:param output_root: root of <test_repeat> tag.
:param output_root: :class:`xml.etree._Element`
"""

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 <repeat> 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(rep_child.tag + " tag is not processed for <" + repeat_root.tag + "> tag.")

def load_tests(self, root, tests_root):
"""
Add <tests> to the root.
Expand Down
71 changes: 67 additions & 4 deletions galaxyxml/tool/parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -859,6 +860,8 @@ class Test(XMLParam):
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)


Expand Down Expand Up @@ -891,6 +894,66 @@ 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 "<output_collection name = '%s'>" % self.name

def command_line_after(self):
return "</output_collection>"

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 "<repeat name = '%s'>" % self.name

def command_line_after(self):
return "</repeat>"

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"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions test/import_xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
<test>
<param name="sequence" value="seq.fasta"/>
<output file="file.gbk" name="genbank"/>
<output_collection name="pdf_out"></output_collection>
<repeat name="test_repeat">
<param name="repeatchild" value="foo"/>
</repeat>
</test>
</tests>
<help><![CDATA[help]]></help>
Expand Down
11 changes: 11 additions & 0 deletions test/unit_test_import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,14 @@ 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")

def test_repeat(self):
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")

0 comments on commit 7d45f9f

Please sign in to comment.