Permalink
Browse files

Small improvements to xunit stuff.

  • Loading branch information...
jmchilton committed Nov 18, 2015
1 parent 6d81a94 commit af7448c58450b4d48a98e7b5c2c72049b9747cc4
Showing with 31 additions and 16 deletions.
  1. +9 −8 planemo/xml/diff.py
  2. +2 −0 tests/shed_app_test_utils.py
  3. +20 −8 tests/test_shed_diff.py
@@ -1,6 +1,7 @@

def diff(x1, x2, reporter=None):
return 0 if xml_compare(x1, x2, reporter) else 1
return_val = 0 if xml_compare(x1, x2, reporter) else 1
return return_val


# From
@@ -12,23 +13,23 @@ def reporter(x):
return None

if x1.tag != x2.tag:
reporter('Tags do not match: %s and %s' % (x1.tag, x2.tag))
reporter('Tags do not match: %s and %s\n' % (x1.tag, x2.tag))
return False
for name, value in x1.attrib.items():
if x2.attrib.get(name) != value:
reporter('Attributes do not match: %s=%r, %s=%r'
reporter('Attributes do not match: %s=%r, %s=%r\n'
% (name, value, name, x2.attrib.get(name)))
return False
for name in x2.attrib.keys():
if name not in x1.attrib:
reporter('x2 has an attribute x1 is missing: %s'
reporter('x2 has an attribute x1 is missing: %s\n'
% name)
return False
if not text_compare(x1.text, x2.text):
reporter('text: %r != %r' % (x1.text, x2.text))
reporter('text: %r != %r\n' % (x1.text, x2.text))
return False
if not text_compare(x1.tail, x2.tail):
reporter('tail: %r != %r' % (x1.tail, x2.tail))
reporter('tail: %r != %r\n' % (x1.tail, x2.tail))
return False
return _compare_children(x1, x2, reporter)

@@ -37,14 +38,14 @@ def _compare_children(x1, x2, reporter):
cl1 = x1.getchildren()
cl2 = x2.getchildren()
if len(cl1) != len(cl2):
reporter('children length differs, %i != %i'
reporter('children length differs, %i != %i\n'
% (len(cl1), len(cl2)))
return False
i = 0
for c1, c2 in zip(cl1, cl2):
i += 1
if not xml_compare(c1, c2, reporter=reporter):
reporter('children %i do not match: %s'
reporter('children %i do not match: %s\n'
% (i, c1.tag))
return False
return True
@@ -23,6 +23,8 @@ def mock_model(directory):
"c1", "Text Manipulation"
).add_category(
"c2", "Sequence Analysis"
).add_category(
"c3", "Tool Dependency Packages"
).add_repository(
"r1",
name="test_repo_1",
@@ -7,6 +7,7 @@
)
from planemo import io
import tempfile
import shutil
import sys
import os
from xml.etree import ElementTree
@@ -79,6 +80,21 @@ def test_shed_diff_raw(self):
diff_command.extend(self._shed_args(read_only=True))
self._check_exit_code(diff_command, exit_code=0)

def test_shed_diff_xml(self):
with self._isolate_repo("package_1") as f:
upload_command = [
"shed_upload", "--force_repository_creation",
]
upload_command.extend(self._shed_args())
self._check_exit_code(upload_command)
changed_xml = os.path.join(TEST_REPOS_DIR,
"package_1_changed",
"tool_dependencies.xml")
shutil.copyfile(changed_xml, join(f, "tool_dependencies.xml"))
diff_command = ["shed_diff"]
diff_command.extend(self._shed_args(read_only=True))
self._check_exit_code(diff_command, exit_code=1)

def test_diff_xunit(self):
with self._isolate_repo("multi_repos_nested") as f:
upload_command = [
@@ -99,15 +115,13 @@ def test_diff_xunit(self):
self._check_exit_code(diff_command, exit_code=0)

compare = open(xunit_report.name, 'r').read()
if not diff(
if diff(
self._make_deterministic(ElementTree.parse(known_good_xunit_report).getroot()),
self._make_deterministic(ElementTree.fromstring(compare)),
reporter=sys.stdout.write
):
self.assertTrue(True)
else:
sys.stdout.write(compare)
self.assertTrue(False)
assert False, "XUnit report different from multi_repos_nested.xunit.xml."

io.write_file(
join(f, "cat1", "related_file"),
@@ -116,15 +130,13 @@ def test_diff_xunit(self):
self._check_exit_code(diff_command, exit_code=1)

compare = open(xunit_report.name, 'r').read()
if not diff(
if diff(
self._make_deterministic(ElementTree.parse(known_bad_xunit_report).getroot()),
self._make_deterministic(ElementTree.fromstring(compare)),
reporter=sys.stdout.write
):
self.assertTrue(True)
else:
sys.stdout.write(compare)
self.assertTrue(False)
assert False, "XUnit report different from multi_repos_nested.xunit-bad.xml."

os.unlink(xunit_report.name)

0 comments on commit af7448c

Please sign in to comment.