Skip to content

Commit c150183

Browse files
committed
Fix URLs in HTML test report
1 parent 460d205 commit c150183

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

ogc/bblocks/postprocess.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,9 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
321321
print(f"Writing full validation report to {test_outputs_path / 'report.html'}", file=sys.stderr)
322322
if base_url:
323323
full_validation_report_url = f"{base_url}{os.path.relpath(Path(test_outputs_path).resolve(), cwd)}/report.html"
324-
report_to_html(json_reports=validation_reports, report_fn=test_outputs_path / 'report.html')
324+
report_to_html(json_reports=validation_reports,
325+
report_fn=test_outputs_path / 'report.html',
326+
base_url=base_url)
325327

326328
if output_file and (not steps or 'register' in steps):
327329

ogc/bblocks/validate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from mako import exceptions as mako_exceptions, template as mako_template
2323
import requests
2424
from jsonschema.validators import validator_for
25-
from ogc.na.annotate_schema import SchemaResolver
2625
from ogc.na.util import load_yaml, is_url, copy_triples
2726
from pyparsing import ParseBaseException
2827
from rdflib import Graph
@@ -175,7 +174,7 @@ def report_to_dict(bblock: BuildingBlock,
175174
if item.source.filename:
176175
source['filename'] = str(os.path.relpath(item.source.filename, cwd))
177176
if base_url:
178-
source['filename'] = urljoin(base_url, source['filename'])
177+
source['url'] = urljoin(base_url, source['filename'])
179178
if item.source.example_index:
180179
source['exampleIndex'] = item.source.example_index
181180
if item.source.snippet_index:
@@ -236,6 +235,7 @@ def report_to_dict(bblock: BuildingBlock,
236235

237236

238237
def report_to_html(json_reports: list[dict],
238+
base_url: str | None = None,
239239
report_fn: Path | None = None) -> str | None:
240240

241241
pass_count = sum(r['result'] for r in json_reports)
@@ -246,7 +246,7 @@ def report_to_html(json_reports: list[dict],
246246
}
247247
template = mako_template.Template(filename=str(Path(__file__).parent / 'validation/report.html.mako'))
248248
try:
249-
result = template.render(reports=json_reports, counts=counts)
249+
result = template.render(reports=json_reports, counts=counts, report_fn=report_fn, base_url=base_url)
250250
except:
251251
raise ValueError(mako_exceptions.text_error_template().render())
252252

ogc/bblocks/validation/report.html.mako

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from html import escape as e
33
from datetime import datetime, timezone
44
from urllib.parse import urlparse, urljoin
5-
from os.path import basename
5+
from os.path import basename, relpath
66
from pathlib import Path
77
from ogc.na.util import is_url
88
import re
@@ -16,6 +16,18 @@ def get_uid():
1616
last_uid = f"uid-{globals()['uid']}"
1717
return last_uid
1818
get_filename = lambda s: basename(urlparse(s).path)
19+
%>
20+
<%
21+
def get_source_url(source):
22+
if source.get('sourceUrl'):
23+
return source['sourceUrl']
24+
source_fn = source['filename']
25+
if is_url(source_fn) or not report_fn:
26+
return source_fn
27+
if report_fn:
28+
return os.path.relpath(source_fn, report_fn.resolve().parent)
29+
return source.get('url', source_fn)
30+
1931
%>
2032
<!doctype html>
2133
<html>
@@ -114,7 +126,7 @@ get_filename = lambda s: basename(urlparse(s).path)
114126
<i class="bi bi-caret-right-fill caret"></i>
115127
Details
116128
</button>
117-
<a href="${e(item['source']['filename'])}" target="_blank">${e(re.sub(r'.*/', '', item['source']['filename']))}</a>
129+
<a href="${e(get_source_url(item['source']))}" target="_blank">${e(re.sub(r'.*/', '', item['source']['filename']))}</a>
118130
<span class="badge bg-secondary ${e(item['source']['type'].lower())}">${e(item['source']['type'].replace('_', ' ').capitalize())}</span>
119131
% if item['source']['requireFail']:
120132
<span class="badge text-bg-info">Requires fail</span>

0 commit comments

Comments
 (0)