Skip to content

Commit 4fa4cc9

Browse files
committed
Write full JSON validation report
1 parent 2dc2601 commit 4fa4cc9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

ogc/bblocks/postprocess.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
PathOrUrl, get_git_repo_url
2323
from ogc.bblocks.schema import annotate_schema, resolve_all_schema_references, write_annotated_schema
2424
from ogc.bblocks.models import BuildingBlock, BuildingBlockRegister, ImportedBuildingBlocks, BuildingBlockError
25-
from ogc.bblocks.validate import validate_test_resources, report_to_html
25+
from ogc.bblocks.validate import validate_test_resources, write_report
2626
from ogc.bblocks.transform import apply_transforms, transformers
2727

2828

@@ -407,14 +407,19 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
407407
print(f"{building_block.identifier} failed postprocessing, skipping...", file=sys.stderr)
408408

409409
full_validation_report_url = None
410+
full_validation_report_url_json = None
410411
if not steps or 'tests' in steps:
411-
print(f"Writing full validation report to {test_outputs_path / 'report.html'}", file=sys.stderr)
412+
print(f"Writing validation report to {test_outputs_path / 'report.html'} and "
413+
f"{test_outputs_path / 'report.json'}", file=sys.stderr)
412414
if base_url:
413415
full_validation_report_url = (f"{base_url}{os.path.relpath(Path(test_outputs_path).resolve(), cwd)}"
414416
f"/report.html")
415-
report_to_html(json_reports=validation_reports,
416-
report_fn=test_outputs_path / 'report.html',
417-
base_url=base_url)
417+
full_validation_report_url_json = (f"{base_url}{os.path.relpath(Path(test_outputs_path).resolve(), cwd)}"
418+
f"/report.json")
419+
write_report(json_reports=validation_reports,
420+
report_fn=test_outputs_path / 'report.html',
421+
json_report_fn=test_outputs_path / 'report.json',
422+
base_url=base_url)
418423

419424
if output_file and (not steps or 'register' in steps):
420425

@@ -430,6 +435,8 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
430435

431436
if full_validation_report_url:
432437
output_register_json['validationReport'] = full_validation_report_url
438+
if full_validation_report_url_json:
439+
output_register_json['validationReportJson'] = full_validation_report_url_json
433440

434441
if additional_metadata:
435442
output_register_json = {

ogc/bblocks/validate.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,25 @@ def report_to_dict(bblock: BuildingBlock,
119119
return result
120120

121121

122-
def report_to_html(json_reports: list[dict],
123-
base_url: str | None = None,
124-
report_fn: Path | None = None) -> str | None:
122+
def write_report(json_reports: list[dict],
123+
base_url: str | None = None,
124+
report_fn: Path | None = None,
125+
json_report_fn: Path | None = None) -> str | None:
125126
pass_count = sum(r['result'] for r in json_reports)
126127
counts = {
127128
'total': len(json_reports),
128129
'passed': pass_count,
129130
'failed': len(json_reports) - pass_count,
130131
}
132+
133+
if json_report_fn:
134+
output_report = {
135+
'summary': {**counts, 'result': counts['failed'] == 0},
136+
'bblocks': {report['bblockId']: report for report in json_reports}
137+
}
138+
with open(json_report_fn, 'w') as f:
139+
json.dump(output_report, f, indent=2)
140+
131141
template = mako_template.Template(filename=str(Path(__file__).parent / 'validation/report.html.mako'))
132142
try:
133143
result = template.render(reports=json_reports, counts=counts, report_fn=report_fn, base_url=base_url)

0 commit comments

Comments
 (0)