Skip to content

Commit 9813ef0

Browse files
committed
Implement shed_diff xunit reporting
1 parent 7e4db98 commit 9813ef0

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

planemo/commands/cmd_shed_diff.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from planemo.cli import pass_context
88
from planemo import options
99
from planemo import shed
10+
from planemo.reports import build_report
1011

1112

1213
@click.command("shed_diff")
@@ -30,6 +31,13 @@
3031
help="Do not attempt smart diff of XML to filter out attributes "
3132
"populated by the Tool Shed.",
3233
)
34+
@click.option(
35+
"--report_xunit",
36+
type=click.Path(file_okay=True, resolve_path=True),
37+
help="Output diff as a faked XUnit report, useful when you want to "
38+
"automatically diff repositories and be warned when out-of-date.",
39+
default=None,
40+
)
3341
@pass_context
3442
def cli(ctx, paths, **kwds):
3543
"""Produce diff between local repository and Tool Shed contents.
@@ -61,8 +69,39 @@ def cli(ctx, paths, **kwds):
6169
difference applies only to the file contents of files that would actually be
6270
uploaded to the repository.
6371
"""
72+
73+
# In a little bit of cheating, we're defining this variable here to collect
74+
# a "report" on our shed_diff
75+
collected_data = {
76+
'results': {
77+
'total': 0,
78+
'errors': 0,
79+
'failures': 0,
80+
'skips': 0,
81+
},
82+
'tests': [],
83+
}
84+
6485
def diff(realized_repository):
65-
return shed.diff_repo(ctx, realized_repository, **kwds)
86+
result = shed.diff_repo(ctx, realized_repository, **kwds)
87+
# Collect data about what happened
88+
collected_data['results']['total'] += 1
89+
if result >= 200:
90+
collected_data['results']['errors'] += 1
91+
elif result > 0:
92+
collected_data['results']['failures'] += 1
93+
collected_data['tests'].append({
94+
'classname': realized_repository.name,
95+
'result': result,
96+
})
97+
98+
return result
6699

67100
exit_code = shed.for_each_repository(ctx, diff, paths, **kwds)
101+
102+
if 'report_xunit' in kwds:
103+
with open(kwds['report_xunit'], 'w') as handle:
104+
handle.write(build_report.template_data(
105+
collected_data, template_name='diff_xunit.tpl'))
106+
68107
sys.exit(exit_code)

planemo/reports/diff_xunit.tpl

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="planemodiff"
3+
tests="{{ results.total }}"
4+
errors="{{ results.errors }}"
5+
failures="{{ results.failures }}"
6+
skip="{{ results.skips }}">
7+
{% for testcase in tests %}
8+
<testcase classname="{{ testcase.classname }}" name="recursive_diff" time="{{ testcase.time }}"/>
9+
{% if testcase.result == 1 %}
10+
<error type="planemo.Different" message="Repository is different">
11+
<!-- TODO: copy of diff output -->
12+
</error>
13+
{% endif %}
14+
{% if testcase.result == 2 %}
15+
<error type="planemo.RepoDoesNotExit" message="Target repository does not exist">
16+
<!-- TODO: copy of diff output -->
17+
</error>
18+
{% endif %}
19+
{% if testcase.result > 2 %}
20+
<error type="planemo.DiffError" message="Error executing diff">
21+
<!-- TODO: copy of diff output -->
22+
</error>
23+
{% endif %}
24+
{% endfor %}
25+
</testsuite>

0 commit comments

Comments
 (0)