Skip to content

Commit

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

Changelog
---------
- 0.4.14

- Fix for TestRepeats (@fubar2)

- 0.4.13

- Add TestOutputCollection, TestRepeat and tests (thanks @fubar2)
Expand Down
8 changes: 8 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
param = gxtp.TestParam("repeatchild", value="foo")
rep_out.append(param)
test_a.append(rep_out)
test_coll = gxtp.TestOutputCollection(name="pdf_out")
test_elem = gxtp.TestOCElement(name="apdf",file="apdf",ftype="pdf")
test_coll.append(test_elem)
test_a.append(test_coll)
rep_out = gxtp.TestRepeat(name="output_repeat")
param = gxtp.TestOutput(name="repeatout", value="repeatfile.out")
rep_out.append(param)
test_a.append(rep_out)
tool.tests.append(test_a)


Expand Down
10 changes: 8 additions & 2 deletions examples/tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ select_local $select_local
<param name="float" value="5.4"/>
<output name="output" value="file.out"/>
<output_collection name="pdf_out"/>
<test_repeat name="testrepeat">
<repeat name="testrepeat">
<param name="repeatchild" value="foo"/>
</test_repeat>
</repeat>
<output_collection name="pdf_out">
<element name="apdf" file="apdf" ftype="pdf"/>
</output_collection>
<repeat name="output_repeat">
<output name="repeatout" value="repeatfile.out"/>
</repeat>
</test>
</tests>
<help><![CDATA[HI]]></help>
Expand Down
2 changes: 1 addition & 1 deletion galaxyxml/tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def export(self, keep_old_command=False):
stdio_element = etree.SubElement(export_xml.root, "stdio")
etree.SubElement(stdio_element, "exit_code", range="1:", level="fatal")
try:
export_xml.append(export_xml.stdio)
export_xml.append(stdio_element)
except Exception:
export_xml.append(Expand(macro="stdio"))

Expand Down
51 changes: 33 additions & 18 deletions galaxyxml/tool/import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,44 +706,59 @@ def _load_output_collection(self, test_root, output_root):
: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),
)
collection = 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),
)
# Deal with child nodes
self.load_inputs(collection, output_root)
test_root.append(collection)

def _load_repeat(self, root, repeat_root):
def _load_element(self, test_root, element_root):
"""
Add <test_repeat> to the <test>.
Add <element> 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`
:param repeat_root: root of <output_collection> tag.
:param repeat_root: :class:`xml.etree._Element`
"""
test_root.append(gxtp.TestOCElement(
name=element_root.attrib.get("name", None),
ftype=element_root.attrib.get("ftype", None),
file=element_root.attrib.get("file", None)
)
)

def _load_repeat(self, test_root, repeat_root):
"""
Add <repeat> to the <test>.
:param root: <test> root to append <output> to.
:param output_root: root of <repeat> tag.
:param output_root: :class:`xml.etree._Element`
"""
repeat = gxtp.TestRepeat(
repeat_root.attrib.get("name", None),
repeat_root.attrib.get("title",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)
test_root.append(repeat)

def load_inputs(self, repeat, repeat_root):
"""
Add children to repeat for test
Add children to repeat/collection for test
:param repeat_root: repeat to attach inputs to.
:param repeat: root of <repeat> tag.
:param repeat: root of <repeat> or <collection> tag.
:type repeat_root: :class:`xml.etree._Element`
"""
for rep_child in repeat_root:
Expand Down
43 changes: 35 additions & 8 deletions galaxyxml/tool/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


class XMLParam(object):
name = "node"

Expand Down Expand Up @@ -69,7 +70,7 @@ def cli(self):
lines.append(child.command_line())
return "\n".join(lines)

def command_line(self, mako_path = None):
def command_line(self, mako_path=None):
"""
genetate the command line for the node (and its childres)
Expand Down Expand Up @@ -355,7 +356,7 @@ def __init__(self, name, **kwargs):
# We use kwargs instead of the usual locals(), so manually copy the
# name to kwargs
if name is not None:
kwargs = dict([("name", name)] + list(kwargs.items()) )
kwargs = dict([("name", name)] + list(kwargs.items()))

# Handle positional parameters
if "positional" in kwargs and kwargs["positional"]:
Expand Down Expand Up @@ -420,7 +421,7 @@ def mako_name(self, mako_path=None):
if len(parent_identifiers) > 0:
parent_identifiers.append("")
path = ".".join(parent_identifiers)
return "$"+ path + self.mako_identifier
return "$" + path + self.mako_identifier

def flag(self):
flag = "-" * self.num_dashes
Expand Down Expand Up @@ -492,7 +493,7 @@ def command_line(self, mako_path=None):
for c in self.children[1:]:
if len(c.children) == 0:
continue
lines.append('#if str(%s) == "%s"' %(self.children[0].mako_name(mako_path), c.value))
lines.append('#if str(%s) == "%s"' % (self.children[0].mako_name(mako_path), c.value))
lines.append(c.cli())
lines.append('#end if')
return "\n".join(lines)
Expand Down Expand Up @@ -835,8 +836,18 @@ def __init__(
def acceptable_child(self, child):
return isinstance(child, OutputData) or isinstance(child, OutputFilter) or isinstance(child, DiscoverDatasets)

def command_line(self, mako_path):
return "## TODO CLI for OutputCollection %s" % self.name
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):
lines = []
for child in self.children:
lines.append(child.command_line())
return "\n".join(lines)


class DiscoverDatasets(XMLParam):
name = "discover_datasets"
Expand Down Expand Up @@ -894,6 +905,14 @@ def __init__(
super(TestOutput, self).__init__(**params)


class TestOCElement(XMLParam):
name = "element"

def __init__(self, name=None, file=None, ftype=None, **kwargs):
params = Util.clean_kwargs(locals().copy())
super(TestOCElement, self).__init__(**params)


class TestOutputCollection(XMLParam):
name = "output_collection"

Expand All @@ -911,15 +930,21 @@ def __init__(
params = Util.clean_kwargs(locals().copy())
super(TestOutputCollection, self).__init__(**params)

def acceptable_child(self, child):
return isinstance(child, TestOCElement)

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):
lines = []
for child in self.children:
lines.append(child.command_line())
return "\n".join(lines)

return ""

class TestRepeat(XMLParam):
name = "repeat"
Expand All @@ -939,7 +964,9 @@ def __init__(
super(TestRepeat, self).__init__(**params)

def acceptable_child(self, child):
return issubclass(type(child), TestParam)
return issubclass(type(child), TestParam) \
or issubclass(type(child), TestOutput) \
or issubclass(type(child), TestOutputCollection)

def command_line_before(self, mako_path):
return "<repeat name = '%s'>" % self.name
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
Expand All @@ -20,5 +20,5 @@
"Environment :: Console",
"License :: OSI Approved :: Apache Software License",
],
data_files = [("", ["LICENSE.TXT"])]
data_files=[("", ["LICENSE.TXT"])]
)
16 changes: 13 additions & 3 deletions test/import_xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,21 @@
<test>
<param name="sequence" value="seq.fasta"/>
<output file="file.gbk" name="genbank"/>
<output_collection name="pdf_out"></output_collection>
<repeat name="test_repeat">
<output_collection name="pdf_out">
<element name="apdf" file="apdf" ftype="pdf"/>
</output_collection>
<repeat name="testrepeat">
<param name="repeatchild" value="foo"/>
</repeat>
</test>
<repeat name="output_repeat">
<output file="outputchild" name="bar"/>
</repeat>
<repeat name="collection_repeat">
<output_collection name="collectionchild">
<element name="elementary" file="efile" ftype="txt"/>
</output_collection>
</repeat>
</test>
</tests>
<help><![CDATA[help]]></help>
<citations>
Expand Down
18 changes: 17 additions & 1 deletion test/unit_test_import_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,23 @@ def test_collection_output(self):

def test_repeat(self):
repeat = self.tool.tests.children[0].node[3]
self.assertEqual(repeat.attrib["name"],"test_repeat")
self.assertEqual(repeat.attrib["name"],"testrepeat")
# test param within repeat
self.assertEqual(repeat[0].attrib["name"], "repeatchild")
self.assertEqual(repeat[0].attrib["value"], "foo")
# test output within repeat
output = self.tool.tests.children[0].node[4]
self.assertEqual(output.attrib["name"],"output_repeat")
self.assertEqual(output[0].attrib["file"], "outputchild")
self.assertEqual(output[0].attrib["name"], "bar")

def test_ocr(self):
# test outputcollection within repeat - who knows...
output = self.tool.tests.children[0].node[5]
self.assertEqual(output.attrib["name"],"collection_repeat")
collection = output[0]
self.assertEqual(collection.attrib["name"], "collectionchild")
element = collection[0]
self.assertEqual(element.attrib["name"], "elementary")
self.assertEqual(element.attrib["file"], "efile")
self.assertEqual(element.attrib["ftype"], "txt")

0 comments on commit 6a75716

Please sign in to comment.