Skip to content

Commit 6a75716

Browse files
authored
Merge pull request #35 from fubar2/master
2 parents 7d45f9f + 3788b47 commit 6a75716

File tree

9 files changed

+121
-35
lines changed

9 files changed

+121
-35
lines changed

README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ License
2020

2121
Changelog
2222
---------
23+
- 0.4.14
24+
25+
- Fix for TestRepeats (@fubar2)
26+
2327
- 0.4.13
2428

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

examples/example.py

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@
110110
param = gxtp.TestParam("repeatchild", value="foo")
111111
rep_out.append(param)
112112
test_a.append(rep_out)
113+
test_coll = gxtp.TestOutputCollection(name="pdf_out")
114+
test_elem = gxtp.TestOCElement(name="apdf",file="apdf",ftype="pdf")
115+
test_coll.append(test_elem)
116+
test_a.append(test_coll)
117+
rep_out = gxtp.TestRepeat(name="output_repeat")
118+
param = gxtp.TestOutput(name="repeatout", value="repeatfile.out")
119+
rep_out.append(param)
120+
test_a.append(rep_out)
113121
tool.tests.append(test_a)
114122

115123

examples/tool.xml

+8-2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,15 @@ select_local $select_local
6868
<param name="float" value="5.4"/>
6969
<output name="output" value="file.out"/>
7070
<output_collection name="pdf_out"/>
71-
<test_repeat name="testrepeat">
71+
<repeat name="testrepeat">
7272
<param name="repeatchild" value="foo"/>
73-
</test_repeat>
73+
</repeat>
74+
<output_collection name="pdf_out">
75+
<element name="apdf" file="apdf" ftype="pdf"/>
76+
</output_collection>
77+
<repeat name="output_repeat">
78+
<output name="repeatout" value="repeatfile.out"/>
79+
</repeat>
7480
</test>
7581
</tests>
7682
<help><![CDATA[HI]]></help>

galaxyxml/tool/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def export(self, keep_old_command=False):
138138
stdio_element = etree.SubElement(export_xml.root, "stdio")
139139
etree.SubElement(stdio_element, "exit_code", range="1:", level="fatal")
140140
try:
141-
export_xml.append(export_xml.stdio)
141+
export_xml.append(stdio_element)
142142
except Exception:
143143
export_xml.append(Expand(macro="stdio"))
144144

galaxyxml/tool/import_xml.py

+33-18
Original file line numberDiff line numberDiff line change
@@ -706,44 +706,59 @@ def _load_output_collection(self, test_root, output_root):
706706
:param repeat_root: root of <output_collection> tag.
707707
:param repeat_root: :class:`xml.etree._Element`
708708
"""
709-
test_root.append(
710-
gxtp.TestOutputCollection(
711-
name=output_root.attrib.get("name", None),
712-
ftype=output_root.attrib.get("ftype", None),
713-
sort=output_root.attrib.get("sort", None),
714-
value=output_root.attrib.get("value", None),
715-
compare=output_root.attrib.get("compare", None),
716-
lines_diff=output_root.attrib.get("lines_diff", None),
717-
delta=output_root.attrib.get("delta", None),
718-
)
709+
collection = gxtp.TestOutputCollection(
710+
name=output_root.attrib.get("name", None),
711+
ftype=output_root.attrib.get("ftype", None),
712+
sort=output_root.attrib.get("sort", None),
713+
value=output_root.attrib.get("value", None),
714+
compare=output_root.attrib.get("compare", None),
715+
lines_diff=output_root.attrib.get("lines_diff", None),
716+
delta=output_root.attrib.get("delta", None),
719717
)
718+
# Deal with child nodes
719+
self.load_inputs(collection, output_root)
720+
test_root.append(collection)
720721

721-
def _load_repeat(self, root, repeat_root):
722+
def _load_element(self, test_root, element_root):
722723
"""
723-
Add <test_repeat> to the <test>.
724+
Add <element> to the <test>.
724725
725726
:param root: <test> root to append <output> to.
726-
:param output_root: root of <test_repeat> tag.
727-
:param output_root: :class:`xml.etree._Element`
727+
:param repeat_root: root of <output_collection> tag.
728+
:param repeat_root: :class:`xml.etree._Element`
728729
"""
730+
test_root.append(gxtp.TestOCElement(
731+
name=element_root.attrib.get("name", None),
732+
ftype=element_root.attrib.get("ftype", None),
733+
file=element_root.attrib.get("file", None)
734+
)
735+
)
729736

737+
def _load_repeat(self, test_root, repeat_root):
738+
"""
739+
Add <repeat> to the <test>.
740+
741+
:param root: <test> root to append <output> to.
742+
:param output_root: root of <repeat> tag.
743+
:param output_root: :class:`xml.etree._Element`
744+
"""
730745
repeat = gxtp.TestRepeat(
731746
repeat_root.attrib.get("name", None),
732-
repeat_root.attrib.get("title",None),
747+
repeat_root.attrib.get("title", None),
733748
min=repeat_root.attrib.get("min", None),
734749
max=repeat_root.attrib.get("max", None),
735750
default=repeat_root.attrib.get("default", None)
736751
)
737752
# Deal with child nodes
738753
self.load_inputs(repeat, repeat_root)
739-
root.append(repeat)
754+
test_root.append(repeat)
740755

741756
def load_inputs(self, repeat, repeat_root):
742757
"""
743-
Add children to repeat for test
758+
Add children to repeat/collection for test
744759
745760
:param repeat_root: repeat to attach inputs to.
746-
:param repeat: root of <repeat> tag.
761+
:param repeat: root of <repeat> or <collection> tag.
747762
:type repeat_root: :class:`xml.etree._Element`
748763
"""
749764
for rep_child in repeat_root:

galaxyxml/tool/parameters/__init__.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
logging.basicConfig(level=logging.INFO)
1414
logger = logging.getLogger(__name__)
1515

16+
1617
class XMLParam(object):
1718
name = "node"
1819

@@ -69,7 +70,7 @@ def cli(self):
6970
lines.append(child.command_line())
7071
return "\n".join(lines)
7172

72-
def command_line(self, mako_path = None):
73+
def command_line(self, mako_path=None):
7374
"""
7475
genetate the command line for the node (and its childres)
7576
@@ -355,7 +356,7 @@ def __init__(self, name, **kwargs):
355356
# We use kwargs instead of the usual locals(), so manually copy the
356357
# name to kwargs
357358
if name is not None:
358-
kwargs = dict([("name", name)] + list(kwargs.items()) )
359+
kwargs = dict([("name", name)] + list(kwargs.items()))
359360

360361
# Handle positional parameters
361362
if "positional" in kwargs and kwargs["positional"]:
@@ -420,7 +421,7 @@ def mako_name(self, mako_path=None):
420421
if len(parent_identifiers) > 0:
421422
parent_identifiers.append("")
422423
path = ".".join(parent_identifiers)
423-
return "$"+ path + self.mako_identifier
424+
return "$" + path + self.mako_identifier
424425

425426
def flag(self):
426427
flag = "-" * self.num_dashes
@@ -492,7 +493,7 @@ def command_line(self, mako_path=None):
492493
for c in self.children[1:]:
493494
if len(c.children) == 0:
494495
continue
495-
lines.append('#if str(%s) == "%s"' %(self.children[0].mako_name(mako_path), c.value))
496+
lines.append('#if str(%s) == "%s"' % (self.children[0].mako_name(mako_path), c.value))
496497
lines.append(c.cli())
497498
lines.append('#end if')
498499
return "\n".join(lines)
@@ -835,8 +836,18 @@ def __init__(
835836
def acceptable_child(self, child):
836837
return isinstance(child, OutputData) or isinstance(child, OutputFilter) or isinstance(child, DiscoverDatasets)
837838

838-
def command_line(self, mako_path):
839-
return "## TODO CLI for OutputCollection %s" % self.name
839+
def command_line_before(self, mako_path):
840+
return "<output_collection name = '%s'>" % self.name
841+
842+
def command_line_after(self):
843+
return "</output_collection>"
844+
845+
def command_line_actual(self, mako_path):
846+
lines = []
847+
for child in self.children:
848+
lines.append(child.command_line())
849+
return "\n".join(lines)
850+
840851

841852
class DiscoverDatasets(XMLParam):
842853
name = "discover_datasets"
@@ -894,6 +905,14 @@ def __init__(
894905
super(TestOutput, self).__init__(**params)
895906

896907

908+
class TestOCElement(XMLParam):
909+
name = "element"
910+
911+
def __init__(self, name=None, file=None, ftype=None, **kwargs):
912+
params = Util.clean_kwargs(locals().copy())
913+
super(TestOCElement, self).__init__(**params)
914+
915+
897916
class TestOutputCollection(XMLParam):
898917
name = "output_collection"
899918

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

933+
def acceptable_child(self, child):
934+
return isinstance(child, TestOCElement)
935+
914936
def command_line_before(self, mako_path):
915937
return "<output_collection name = '%s'>" % self.name
916938

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

920942
def command_line_actual(self, mako_path):
943+
lines = []
944+
for child in self.children:
945+
lines.append(child.command_line())
946+
return "\n".join(lines)
921947

922-
return ""
923948

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

941966
def acceptable_child(self, child):
942-
return issubclass(type(child), TestParam)
967+
return issubclass(type(child), TestParam) \
968+
or issubclass(type(child), TestOutput) \
969+
or issubclass(type(child), TestOutputCollection)
943970

944971
def command_line_before(self, mako_path):
945972
return "<repeat name = '%s'>" % self.name

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="galaxyxml",
8-
version="0.4.13",
8+
version="0.4.14",
99
description="Galaxy XML generation library",
1010
author="Helena Rasche",
1111
author_email="[email protected]",
@@ -20,5 +20,5 @@
2020
"Environment :: Console",
2121
"License :: OSI Approved :: Apache Software License",
2222
],
23-
data_files = [("", ["LICENSE.TXT"])]
23+
data_files=[("", ["LICENSE.TXT"])]
2424
)

test/import_xml.xml

+13-3
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,21 @@
7171
<test>
7272
<param name="sequence" value="seq.fasta"/>
7373
<output file="file.gbk" name="genbank"/>
74-
<output_collection name="pdf_out"></output_collection>
75-
<repeat name="test_repeat">
74+
<output_collection name="pdf_out">
75+
<element name="apdf" file="apdf" ftype="pdf"/>
76+
</output_collection>
77+
<repeat name="testrepeat">
7678
<param name="repeatchild" value="foo"/>
7779
</repeat>
78-
</test>
80+
<repeat name="output_repeat">
81+
<output file="outputchild" name="bar"/>
82+
</repeat>
83+
<repeat name="collection_repeat">
84+
<output_collection name="collectionchild">
85+
<element name="elementary" file="efile" ftype="txt"/>
86+
</output_collection>
87+
</repeat>
88+
</test>
7989
</tests>
8090
<help><![CDATA[help]]></help>
8191
<citations>

test/unit_test_import_xml.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,23 @@ def test_collection_output(self):
199199

200200
def test_repeat(self):
201201
repeat = self.tool.tests.children[0].node[3]
202-
self.assertEqual(repeat.attrib["name"],"test_repeat")
202+
self.assertEqual(repeat.attrib["name"],"testrepeat")
203203
# test param within repeat
204204
self.assertEqual(repeat[0].attrib["name"], "repeatchild")
205205
self.assertEqual(repeat[0].attrib["value"], "foo")
206+
# test output within repeat
207+
output = self.tool.tests.children[0].node[4]
208+
self.assertEqual(output.attrib["name"],"output_repeat")
209+
self.assertEqual(output[0].attrib["file"], "outputchild")
210+
self.assertEqual(output[0].attrib["name"], "bar")
211+
212+
def test_ocr(self):
213+
# test outputcollection within repeat - who knows...
214+
output = self.tool.tests.children[0].node[5]
215+
self.assertEqual(output.attrib["name"],"collection_repeat")
216+
collection = output[0]
217+
self.assertEqual(collection.attrib["name"], "collectionchild")
218+
element = collection[0]
219+
self.assertEqual(element.attrib["name"], "elementary")
220+
self.assertEqual(element.attrib["file"], "efile")
221+
self.assertEqual(element.attrib["ftype"], "txt")

0 commit comments

Comments
 (0)