|
7 | 7 | from planemo.cli import pass_context
|
8 | 8 | from planemo import options
|
9 | 9 | from planemo import shed
|
| 10 | +from planemo.reports import build_report |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @click.command("shed_diff")
|
|
30 | 31 | help="Do not attempt smart diff of XML to filter out attributes "
|
31 | 32 | "populated by the Tool Shed.",
|
32 | 33 | )
|
| 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 | +) |
33 | 41 | @pass_context
|
34 | 42 | def cli(ctx, paths, **kwds):
|
35 | 43 | """Produce diff between local repository and Tool Shed contents.
|
@@ -61,8 +69,39 @@ def cli(ctx, paths, **kwds):
|
61 | 69 | difference applies only to the file contents of files that would actually be
|
62 | 70 | uploaded to the repository.
|
63 | 71 | """
|
| 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 | + |
64 | 85 | 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 |
66 | 99 |
|
67 | 100 | 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 | + |
68 | 107 | sys.exit(exit_code)
|
0 commit comments