Skip to content

Commit af7448c

Browse files
committed
Small improvements to xunit stuff.
1 parent 6d81a94 commit af7448c

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

planemo/xml/diff.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
def diff(x1, x2, reporter=None):
3-
return 0 if xml_compare(x1, x2, reporter) else 1
3+
return_val = 0 if xml_compare(x1, x2, reporter) else 1
4+
return return_val
45

56

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

1415
if x1.tag != x2.tag:
15-
reporter('Tags do not match: %s and %s' % (x1.tag, x2.tag))
16+
reporter('Tags do not match: %s and %s\n' % (x1.tag, x2.tag))
1617
return False
1718
for name, value in x1.attrib.items():
1819
if x2.attrib.get(name) != value:
19-
reporter('Attributes do not match: %s=%r, %s=%r'
20+
reporter('Attributes do not match: %s=%r, %s=%r\n'
2021
% (name, value, name, x2.attrib.get(name)))
2122
return False
2223
for name in x2.attrib.keys():
2324
if name not in x1.attrib:
24-
reporter('x2 has an attribute x1 is missing: %s'
25+
reporter('x2 has an attribute x1 is missing: %s\n'
2526
% name)
2627
return False
2728
if not text_compare(x1.text, x2.text):
28-
reporter('text: %r != %r' % (x1.text, x2.text))
29+
reporter('text: %r != %r\n' % (x1.text, x2.text))
2930
return False
3031
if not text_compare(x1.tail, x2.tail):
31-
reporter('tail: %r != %r' % (x1.tail, x2.tail))
32+
reporter('tail: %r != %r\n' % (x1.tail, x2.tail))
3233
return False
3334
return _compare_children(x1, x2, reporter)
3435

@@ -37,14 +38,14 @@ def _compare_children(x1, x2, reporter):
3738
cl1 = x1.getchildren()
3839
cl2 = x2.getchildren()
3940
if len(cl1) != len(cl2):
40-
reporter('children length differs, %i != %i'
41+
reporter('children length differs, %i != %i\n'
4142
% (len(cl1), len(cl2)))
4243
return False
4344
i = 0
4445
for c1, c2 in zip(cl1, cl2):
4546
i += 1
4647
if not xml_compare(c1, c2, reporter=reporter):
47-
reporter('children %i do not match: %s'
48+
reporter('children %i do not match: %s\n'
4849
% (i, c1.tag))
4950
return False
5051
return True

tests/shed_app_test_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def mock_model(directory):
2323
"c1", "Text Manipulation"
2424
).add_category(
2525
"c2", "Sequence Analysis"
26+
).add_category(
27+
"c3", "Tool Dependency Packages"
2628
).add_repository(
2729
"r1",
2830
name="test_repo_1",

tests/test_shed_diff.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from planemo import io
99
import tempfile
10+
import shutil
1011
import sys
1112
import os
1213
from xml.etree import ElementTree
@@ -79,6 +80,21 @@ def test_shed_diff_raw(self):
7980
diff_command.extend(self._shed_args(read_only=True))
8081
self._check_exit_code(diff_command, exit_code=0)
8182

83+
def test_shed_diff_xml(self):
84+
with self._isolate_repo("package_1") as f:
85+
upload_command = [
86+
"shed_upload", "--force_repository_creation",
87+
]
88+
upload_command.extend(self._shed_args())
89+
self._check_exit_code(upload_command)
90+
changed_xml = os.path.join(TEST_REPOS_DIR,
91+
"package_1_changed",
92+
"tool_dependencies.xml")
93+
shutil.copyfile(changed_xml, join(f, "tool_dependencies.xml"))
94+
diff_command = ["shed_diff"]
95+
diff_command.extend(self._shed_args(read_only=True))
96+
self._check_exit_code(diff_command, exit_code=1)
97+
8298
def test_diff_xunit(self):
8399
with self._isolate_repo("multi_repos_nested") as f:
84100
upload_command = [
@@ -99,15 +115,13 @@ def test_diff_xunit(self):
99115
self._check_exit_code(diff_command, exit_code=0)
100116

101117
compare = open(xunit_report.name, 'r').read()
102-
if not diff(
118+
if diff(
103119
self._make_deterministic(ElementTree.parse(known_good_xunit_report).getroot()),
104120
self._make_deterministic(ElementTree.fromstring(compare)),
105121
reporter=sys.stdout.write
106122
):
107-
self.assertTrue(True)
108-
else:
109123
sys.stdout.write(compare)
110-
self.assertTrue(False)
124+
assert False, "XUnit report different from multi_repos_nested.xunit.xml."
111125

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

118132
compare = open(xunit_report.name, 'r').read()
119-
if not diff(
133+
if diff(
120134
self._make_deterministic(ElementTree.parse(known_bad_xunit_report).getroot()),
121135
self._make_deterministic(ElementTree.fromstring(compare)),
122136
reporter=sys.stdout.write
123137
):
124-
self.assertTrue(True)
125-
else:
126138
sys.stdout.write(compare)
127-
self.assertTrue(False)
139+
assert False, "XUnit report different from multi_repos_nested.xunit-bad.xml."
128140

129141
os.unlink(xunit_report.name)
130142

0 commit comments

Comments
 (0)