Skip to content

Commit

Permalink
Merge branch 'release_18.09' into release_19.01
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jan 24, 2019
2 parents bdd340c + 1a4c1ec commit f9ca90a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/galaxy/util/__init__.py
Expand Up @@ -222,6 +222,11 @@ def doctype(*args):
tree = ElementTree.ElementTree()
try:
root = tree.parse(fname, parser=ElementTree.XMLParser(target=DoctypeSafeCallbackTarget()))
for elem in root.iter('*'):
if elem.text is not None:
elem.text = elem.text.strip()
if elem.tail is not None:
elem.tail = elem.tail.strip()
except ParseError:
log.exception("Error parsing file %s", fname)
raise
Expand All @@ -231,11 +236,18 @@ def doctype(*args):

def parse_xml_string(xml_string):
tree = ElementTree.fromstring(xml_string)
for elem in tree.iter('*'):
if elem.text is not None:
elem.text = elem.text.strip()
if elem.tail is not None:
elem.tail = elem.tail.strip()
return tree


def xml_to_string(elem, pretty=False):
"""Returns a string from an xml tree"""
"""
Returns a string from an xml tree.
"""
try:
if elem is not None:
if PY2:
Expand Down
4 changes: 3 additions & 1 deletion lib/galaxy/workflow/modules.py
Expand Up @@ -440,8 +440,10 @@ def get_all_outputs(self, data_only=False):
label = workflow_output['label']
if not label:
label = "%s:%s" % (order_index, workflow_output['output_name'])
workflow_output_uuid = workflow_output.get('uuid') or object()
for data_output in data_outputs:
if data_output['name'] == workflow_output['output_name'] or data_output['uuid'] == workflow_output['uuid']:
data_output_uuid = data_output.get('uuid') or object()
if data_output['name'] == workflow_output['output_name'] or data_output_uuid == workflow_output_uuid:
data_output['label'] = label
data_output['name'] = label
# That's the right data_output
Expand Down
54 changes: 54 additions & 0 deletions test/unit/test_utils.py
@@ -1,5 +1,17 @@
from tempfile import NamedTemporaryFile

from galaxy import util

SECTION_XML = """<?xml version="1.0" ?>
<section id="fasta_fastq_manipulation" name="Fasta Fastq Manipulation" version="">
<tool file="toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/fb1313d79396/seq_filter_by_id/tools/seq_filter_by_id/seq_filter_by_id.xml" guid="toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/seq_filter_by_id/0.2.5">
<tool_shed>
toolshed.g2.bx.psu.edu
</tool_shed>
</tool>
</section>
"""


def test_strip_control_characters():
s = '\x00bla'
Expand All @@ -15,3 +27,45 @@ def test_strip_control_characters_nested():
assert util.strip_control_characters_nested(l)[0] == stripped_s
assert util.strip_control_characters_nested(t)[0] == stripped_s
assert util.strip_control_characters_nested(d)[42] == stripped_s


def test_parse_xml_string():
section = util.parse_xml_string(SECTION_XML)
_verify_section(section)


def test_parse_xml_file():
with NamedTemporaryFile(mode='w') as tmp:
tmp.write(SECTION_XML)
tmp.flush()
section = util.parse_xml(tmp.name).getroot()
_verify_section(section)


def _verify_section(section):
tool = next(iter(section))
assert sorted(tool.items()) == [
('file',
'toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/fb1313d79396/seq_filter_by_id/tools/seq_filter_by_id/seq_filter_by_id.xml'),
('guid',
'toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/seq_filter_by_id/0.2.5')
]
assert next(iter(tool)).text == 'toolshed.g2.bx.psu.edu'


def test_xml_to_string():
section = util.parse_xml_string(SECTION_XML)
s = util.xml_to_string(section)
assert len(s.split('\n')) == 1


def test_xml_to_string_pretty():
section = util.parse_xml_string(SECTION_XML)
s = util.xml_to_string(section, pretty=True)
PRETTY = """<?xml version="1.0" ?>
<section id="fasta_fastq_manipulation" name="Fasta Fastq Manipulation" version="">
<tool file="toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/fb1313d79396/seq_filter_by_id/tools/seq_filter_by_id/seq_filter_by_id.xml" guid="toolshed.g2.bx.psu.edu/repos/peterjc/seq_filter_by_id/seq_filter_by_id/0.2.5">
<tool_shed>toolshed.g2.bx.psu.edu</tool_shed>
</tool>
</section>"""
assert s == PRETTY

0 comments on commit f9ca90a

Please sign in to comment.