Skip to content

Commit 6388f6f

Browse files
committed
Download hash library in HTML
1 parent f8b473c commit 6388f6f

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

pytest_mpl/plugin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,18 @@ def pytest_unconfigure(self, config):
700700
json.dump(result_hashes, fp, indent=2)
701701

702702
if self.generate_summary:
703+
kwargs = {}
703704
if 'json' in self.generate_summary:
704705
summary = self.generate_summary_json()
705706
print(f"A JSON report can be found at: {summary}")
707+
if result_hash_library.exists(): # link to it in the HTML
708+
kwargs["hash_library"] = result_hash_library.name
706709
if 'html' in self.generate_summary:
707-
summary = generate_summary_html(self._test_results, self.results_dir)
710+
summary = generate_summary_html(self._test_results, self.results_dir, **kwargs)
708711
print(f"A summary of the failed tests can be found at: {summary}")
709712
if 'basic-html' in self.generate_summary:
710-
summary = generate_summary_basic_html(self._test_results, self.results_dir)
713+
summary = generate_summary_basic_html(self._test_results, self.results_dir,
714+
**kwargs)
711715
print(f"A summary of the failed tests can be found at: {summary}")
712716

713717

pytest_mpl/summary/html.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def hash_status_msg(status):
227227
return messages[status]
228228

229229

230-
def generate_summary_html(results, results_dir):
230+
def generate_summary_html(results, results_dir, hash_library=None):
231231
"""Generate the HTML summary.
232232
233233
Parameters
@@ -236,6 +236,9 @@ def generate_summary_html(results, results_dir):
236236
The `pytest_mpl.plugin.ImageComparison._test_results` object.
237237
results_dir : Path
238238
Path to the output directory.
239+
hash_library : str, optional, default=None
240+
Filename of the generated hash library at the root of `results_dir`.
241+
Will be linked to in HTML if not None.
239242
"""
240243

241244
# Initialize Jinja
@@ -251,7 +254,7 @@ def generate_summary_html(results, results_dir):
251254

252255
# Render HTML starting from the base template
253256
template = env.get_template("base.html")
254-
html = template.render(results=Results(results))
257+
html = template.render(results=Results(results), hash_library=hash_library)
255258

256259
# Write files
257260
for file in ['styles.css', 'extra.js', 'hash.svg', 'image.svg']:
@@ -264,7 +267,7 @@ def generate_summary_html(results, results_dir):
264267
return html_file
265268

266269

267-
def generate_summary_basic_html(results, results_dir):
270+
def generate_summary_basic_html(results, results_dir, hash_library=None):
268271
"""Generate the basic HTML summary.
269272
270273
Parameters
@@ -273,6 +276,9 @@ def generate_summary_basic_html(results, results_dir):
273276
The `pytest_mpl.plugin.ImageComparison._test_results` object.
274277
results_dir : Path
275278
Path to the output directory.
279+
hash_library : str, optional, default=None
280+
Filename of the generated hash library at the root of `results_dir`.
281+
Will be linked to in HTML if not None.
276282
"""
277283

278284
# Initialize Jinja
@@ -283,7 +289,7 @@ def generate_summary_basic_html(results, results_dir):
283289

284290
# Render HTML starting from the base template
285291
template = env.get_template("basic.html")
286-
html = template.render(results=Results(results))
292+
html = template.render(results=Results(results), hash_library=hash_library)
287293

288294
# Write files
289295
html_file = results_dir / 'fig_comparison_basic.html'

pytest_mpl/summary/templates/basic.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ <h2>Image test comparison</h2>
4848
of those have a matching baseline image
4949
{%- endif %}
5050
</p>
51+
{% if hash_library -%}
52+
<p>
53+
<a href="{{ hash_library }}" download>Download generated hash library</a>
54+
</p>
55+
{%- endif %}
5156
<table>
5257
<tr>
5358
<th></th>

pytest_mpl/summary/templates/filter.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,12 @@ <h5>Show tests which have...</h5>
6262
</div>
6363
</div>
6464
</form>
65+
{% if hash_library -%}
66+
<hr>
67+
<a download="{{ hash_library }}" href="{{ hash_library }}" class="btn btn-light"
68+
data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-html="true"
69+
title="<pre>{{ hash_library }}</pre>"
70+
role="button">Download generated hash library</a>
71+
{%- endif %}
6572
</div>
6673
</div>

pytest_mpl/summary/templates/styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ body.no-hash-test .mpl-hash {
3535
pre {
3636
white-space: pre-line;
3737
}
38+
.tooltip-inner pre {
39+
margin: 0;
40+
}
3841
div.result div.status-badge button img {
3942
vertical-align: sub;
4043
}

0 commit comments

Comments
 (0)