Skip to content

Commit 06fce93

Browse files
committed
Add basic search and sort
Signed-off-by: Conor MacBride <[email protected]>
1 parent 536900b commit 06fce93

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

pytest_mpl/summary/html.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ def template(name):
4141
RESULT_IMAGES = template('result_images')
4242

4343

44+
def status_sort(status):
45+
s = 50
46+
if status['overall'] == 'failed':
47+
s -= 10
48+
if status['image'] == 'diff':
49+
s -= 3
50+
elif status['image'] == 'missing':
51+
s -= 4
52+
if status['hash'] == 'diff':
53+
s -= 1
54+
elif status['hash'] == 'missing':
55+
s -= 5
56+
return s
57+
58+
4459
def get_status(item, card_id, warn_missing):
4560
status = {
4661
'overall': None,
@@ -155,6 +170,7 @@ def card(name, item, warn_missing=None):
155170
id=card_id,
156171
test_name=test_name,
157172
module=module,
173+
status_sort=status_sort(status),
158174

159175
image=image,
160176
badge=badge,

pytest_mpl/summary/templates/base.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
99
<title>{title}</title>
1010
</head>
11-
<body class="{classes}">
11+
<body class="{classes}" id="results">
1212
{navbar}
1313
<div class="album bg-light">
1414
<div class="container-fluid">
15-
<div class="row">
15+
<div class="row list">
1616
{cards}
1717
</div>
1818
</div>
@@ -22,6 +22,9 @@
2222
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
2323
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
2424
crossorigin="anonymous"></script>
25+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/list.min.js"
26+
integrity="sha256-YqOIp4MygNx9/lcWr5lpcR88Ki/MNMWvJJkH0eK+fHM="
27+
crossorigin="anonymous"></script>
2528
<script src="extra.js"></script>
2629
</body>
2730
</html>

pytest_mpl/summary/templates/extra.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggl
1010
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
1111
return new bootstrap.Tooltip(tooltipTriggerEl)
1212
})
13+
14+
// Search, sort and filter
15+
var options = {
16+
valueNames: [ 'test-name', 'status-sort', 'rms', 'baseline-hash', 'result-hash' ]
17+
};
18+
var userList = new List('results', options);
19+
userList.sort('status-sort');

pytest_mpl/summary/templates/filter.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ <h6>Filter results</h6>
66
<div class="offcanvas-body">
77
<h5>Sort tests by...</h5>
88
<div class="btn-group m-2" role="group" aria-label="Select sorting">
9-
<input type="radio" class="btn-check" name="sort" id="sortstatus" autocomplete="off" checked>
9+
<input type="radio" class="btn-check sort" data-sort="status-sort" name="sort" id="sortstatus" autocomplete="off" checked>
1010
<label class="btn btn-outline-secondary" for="sortstatus">status</label>
11-
<input type="radio" class="btn-check" name="sort" id="sortname" autocomplete="off">
11+
<input type="radio" class="btn-check sort" data-sort="test-name" name="sort" id="sortname" autocomplete="off">
1212
<label class="btn btn-outline-secondary" for="sortname">name</label>
13+
<input type="radio" class="btn-check sort" data-sort="rms" name="sort" id="sortrms" autocomplete="off">
14+
<label class="btn btn-outline-secondary" for="sortrms">RMS</label>
1315
</div>
1416
<h5>Show tests which have...</h5>
1517
<div class="list-group m-2">

pytest_mpl/summary/templates/navbar.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
</li>-->
3333
</ul>
3434
<form class="d-flex">
35-
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
36-
<button class="btn btn-outline-success me-2" type="submit">Search</button>
35+
<input class="form-control me-2 search" type="search" placeholder="Search" aria-label="Search">
3736
</form>
3837
<button class="btn btn-outline-primary" aria-label="Filter" type="button" data-bs-toggle="offcanvas"
3938
data-bs-target="#offcanvasFilter" aria-controls="offcanvasFilter">

pytest_mpl/summary/templates/result.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<div class="py-2 col-sm-6 col-lg-4 col-xxl-3 result {classes}">
2+
<span class="test-name" style="display:none">{module}.{test_name}</span>
3+
<span class="status-sort" style="display:none">{status_sort}</span>
24
<div class="card">
35
<a class="btn" data-bs-toggle="offcanvas" href="#offcanvas{id}" role="button" aria-controls="offcanvas{id}">{image}</a>
46
{offcanvas}

pytest_mpl/summary/templates/result_images.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h5 class="card-title">{test_name}</h5>
4141
<div class="card-body">
4242
<div class="mb-3 rms">
4343
<label for="rms" class="form-label">RMS</label>
44-
<pre class="form-control" id="rms">{rms}</pre>
44+
<pre class="form-control rms" id="rms">{rms}</pre>
4545
</div>
4646
<div class="mb-3 tolerance">
4747
<label for="tolerance" class="form-label">Tolerance</label>
@@ -54,11 +54,11 @@ <h5 class="card-title">{test_name}</h5>
5454
<div class="card-body">
5555
<div class="mb-3 baseline-hash">
5656
<label for="baseline_hash" class="form-label">Baseline</label>
57-
<pre class="form-control" id="baseline_hash">{baseline_hash}</pre>
57+
<pre class="form-control baseline-hash" id="baseline_hash">{baseline_hash}</pre>
5858
</div>
5959
<div class="mb-3 result-hash">
6060
<label for="result_hash" class="form-label">Result</label>
61-
<pre class="form-control" id="result_hash">{result_hash}</pre>
61+
<pre class="form-control result-hash" id="result_hash">{result_hash}</pre>
6262
</div>
6363
</div>
6464
</div>

0 commit comments

Comments
 (0)