8000 Improve hiding of irrelevant info · matplotlib/pytest-mpl@39b8d83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39b8d83

Browse files
committed
Improve hiding of irrelevant info
1 parent 113acba commit 39b8d83

File tree

6 files changed

+33
-48
lines changed

6 files changed

+33
-48
lines changed

pytest_mpl/summary/html.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,12 @@ class Results:
2626
def __init__(self, results, title="Image comparison"):
2727
self.title = title # HTML <title>
2828

29-
# If any baseline images or baseline hashes are present,
30-
# assume all results should have them
31-
self.warn_missing = {'baseline_image': False, 'baseline_hash': False}
32-
for key in self.warn_missing.keys():
33-
for result in results.values():
34-
if result[key] is not None:
35-
self.warn_missing[key] = True
36-
break
37-
38-
# Additional <body> classes
39-
self.classes = []
40-
if self.warn_missing['baseline_hash'] is False:
41-
self.classes += ['no-hash-test']
42-
4329
# Generate sorted list of results
4430
self.cards = []
4531
pad = len(str(len(results.items()))) # maximum length of a result index
4632
for collect_n, (name, item) in enumerate(results.items()):
4733
card_id = str(collect_n).zfill(pad) # zero pad for alphanumerical sorting
48-
self.cards += [Result(name, item, card_id, self.warn_missing)]
34+
self.cards += [Result(name, item, card_id)]
4935
self.cards = sorted(self.cards, key=lambda i: i.indexes['status'], reverse=True)
5036

5137
@cached_property
@@ -66,6 +52,22 @@ def statistics(self):
6652
stats['skipped'] += 1
6753
return stats
6854

55+
@cached_property
56+
def image_comparison(self):
57+
"""Whether at least one image comparison test or generation was performed."""
58+
for result in self.cards:
59+
if result.image_status:
60+
return True
61+
return False
62+
63+
@cached_property
64+
def hash_comparison(self):
65+
"""Whether at least one hash comparison test or generation was performed."""
66+
for result in self.cards:
67+
if result.hash_status:
68+
return True
69+
return False
70+
6971

7072
class Result:
7173
"""
@@ -81,20 +83,14 @@ class Result:
8183
id : str
8284
The test number in order collected. Numbers must be
8385
zero padded due to alphanumerical sorting.
84-
warn_missing : dict
85-
Whether to include relevant status badges for images and/or hashes.
86-
Must have keys ``baseline_image`` and ``baseline_hash``.
8786
"""
88-
def __init__(self, name, item, id, warn_missing):
87+
def __init__(self, name, item, id):
8988
# Make the summary dictionary available as attributes
9089
self.__dict__ = item
9190

9291
# Sort index for collection order
9392
self.id = id
9493

95-
# Whether to show image and/or hash status badges
96-
self.warn_missing = warn_missing
97-
9894
# Name of test with module and test function together and separate
9995
self.full_name = name
10096
self.name = name.split('.')[-1]
@@ -154,8 +150,6 @@ def badges(self):
154150
"""Additional badges to show beside overall status badge."""
155151
for test_type, status_getter in [('image', image_status_msg), ('hash', hash_status_msg)]:
156152
status = getattr(self, f'{test_type}_status')
157-
if not self.warn_missing[f'baseline_{test_type}']:
158-
continue # not expected to exist
159153
if (
160154
(status == 'missing') or
161155
(self.status == 'failed' and status == 'match') or

pytest_mpl/summary/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
99
<title>{{ results.title }}</title>
1010
</head>
11-
<body{% if results.classes | length %} class="{{ results.classes | join(' ') }}"{% endif %} id="results">
11+
<body id="results">
1212
{% include 'navbar.html' %}
1313
<div class="album bg-light">
1414
<div class="container-fluid">

pytest_mpl/summary/templates/extra.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
// Remove all elements of class mpl-hash if hash test not run
2-
if (document.body.classList[0] == 'no-hash-test') {
3-
document.querySelectorAll('.mpl-hash').forEach(function (elem) {
4-
elem.parentElement.removeChild(elem);
5-
});
6-
}
7-
81
// Enable tooltips
92
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
103
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {

pytest_mpl/summary/templates/filter.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h5>Sort tests by...</h5>
1616
{{ sort_option('status-sort', 'status', 'desc', default=true) }}
1717
{{ sort_option('collected-sort', 'collected', 'asc') }}
1818
{{ sort_option('test-name', 'name') }}
19-
{% if results.warn_missing['baseline_image'] -%}
19+
{% if results.image_comparison -%}
2020
{{ sort_option('rms-sort', 'RMS', 'desc') }}
2121
{%- endif %}
2222
</div>
@@ -34,15 +34,15 @@ <h5>Show tests which have...</h5>
3434
{{ filter_option('overall-failed', 'failed') }}
3535
{{ filter_option('overall-skipped', 'skipped') }}
3636
</div>
37-
{% if results.warn_missing['baseline_image'] -%}
37+
{% if results.image_comparison -%}
3838
<div class="list-group m-2">
3939
{{ filter_option('image-match', 'matching images') }}
4040
{{ filter_option('image-diff', 'differing images') }}
4141
{{ filter_option('image-missing', 'no baseline image') }}
4242
</div>
4343
{%- endif %}
44-
{% if results.warn_missing['baseline_hash'] -%}
45-
<div class="list-group m-2 mpl-hash">
44+
{% if results.hash_comparison -%}
45+
<div class="list-group m-2">
4646
{{ filter_option('hash-match', 'matching hashes') }}
4747
{{ filter_option('hash-diff', 'differing hashes') }}
4848
{{ filter_option('hash-missing', 'no baseline hash') }}

pytest_mpl/summary/templates/result_images.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ <h6><small class="text-muted">{{ r.module }}</small></h6>
66
</div>
77
<div class="offcanvas-body">
88
<h5 class="card-title">{{ r.name }}</h5>
9-
{% if results.warn_missing['baseline_image'] and r.image_status != 'generated' -%}
9+
{% if r.image_status and r.image_status != 'generated' -%}
1010
<div class="row row-cols-1 row-cols-md-3 g-4 mt-3">
1111
{% macro image_card(file, name) -%}
1212
<div class="col py-3 m-0">
1313
<div class="card h-100">
1414
<div class="card-header">{{ name }}</div>
1515
{% if file -%}
16-
<img src="{{ file }}" class="card-img-top" alt="">
16+
<img src="{{ file }}" class="card-img-top" alt="{{ name }}">
1717
{%- endif %}
1818
</div>
1919
</div>
@@ -41,21 +41,25 @@ <h5 class="card-title">{{ r.name }}</h5>
4141
</div>
4242
{%- endfilter %}
4343
{%- endmacro -%}
44-
{% if results.warn_missing['baseline_image'] -%}
45-
<div class="card text-white bg-{{ r.image_status | status_class }} mb-3 mpl-image">
44+
{% if r.image_status -%}
45+
<div class="card text-white bg-{{ r.image_status | status_class }} mb-3">
4646
<div class="card-header">{{ r.image_status | image_status_msg }}</div>
47+
{% if r.image_status == 'match' or r.image_status == 'diff' -%}
4748
<div class="card-body">
4849
{{ pre_data('rms', r.rms_str, 'RMS') }}
4950
{{ pre_data('tolerance', r.tolerance, 'Tolerance') }}
5051
</div>
52+
{%- endif %}
5153
</div>
5254
{%- endif %}
53-
{% if results.warn_missing['baseline_hash'] -%}
54-
<div class="card text-white bg-{{ r.hash_status | status_class }} mb-3 mpl-hash">
55+
{% if r.hash_status -%}
56+
<div class="card text-white bg-{{ r.hash_status | status_class }} mb-3">
5557
<div class="card-header">{{ r.hash_status | hash_status_msg }}</div>
5658
<div class="card-body">
5759
{{ pre_data('baseline_hash', r.baseline_hash, 'Baseline') }}
60+
{% if r.hash_status != 'generated' -%}
5861
{{ pre_data('result_hash', r.result_hash, 'Result') }}
62+
{%- endif %}
5963
</div>
6064
</div>
6165
{%- endif %}

pytest_mpl/summary/templates/styles.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
body.no-hash-test .mpl-hash {
2-
display: none;
3-
}
41
.navbar-brand span.repo {
52
font-weight: bold;
63
}
@@ -29,9 +26,6 @@ body.no-hash-test .mpl-hash {
2926
max-width: 400px;
3027
}
3128
}
32-
.image-missing .mpl-image .card-body {
33-
display: none;
34-
}
3529
pre {
3630
white-space: pre-line;
3731
}

0 commit comments

Comments
 (0)
0