Skip to content

Commit 70bebb3

Browse files
committed
Generate the testing report Use the report-summary module to create a report for the frontend with clear structure.
- Add the tolerance values for each test case instead of using fixed value for all tests.
1 parent 807dd4c commit 70bebb3

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

.github/workflows/website.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,16 @@ jobs:
4848

4949
- name: Run the test that generates the plots report.
5050
run: |
51-
pytest tests/IVIMmodels/unit_tests/test_ivim_fit.py
51+
pytest tests/IVIMmodels/unit_tests/test_ivim_fit.py --json-report
52+
python utilities/report-summary.py .report.json report-summary.json
5253
5354
- name: 'Filter and compress results file.'
5455
run: python utilities/reduce_output_size.py test_output.csv test_output.csv.gz
5556

5657
- name: move data to the dashboard folder
5758
run: |
5859
mv test_output.csv.gz website/dashboard
59-
mv test_results_report.json website/dashboard
60+
mv report-summary.json website/dashboard
6061
6162
6263
- name: Build documentation

tests/IVIMmodels/unit_tests/test_ivim_fit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def data_ivim_fit_saved():
7070

7171

7272
@pytest.mark.parametrize("name, bvals, data, algorithm, xfail, kwargs, tolerances", data_ivim_fit_saved())
73-
def test_ivim_fit_saved(name, bvals, data, algorithm, xfail, kwargs, tolerances, request, test_results):
73+
def test_ivim_fit_saved(name, bvals, data, algorithm, xfail, kwargs, tolerances, request, record_property):
7474
if xfail["xfail"]:
7575
mark = pytest.mark.xfail(reason="xfail", strict=xfail["strict"])
7676
request.node.add_marker(mark)
@@ -90,12 +90,12 @@ def to_list_if_needed(value):
9090
"f": to_list_if_needed(data['f']),
9191
"Dp": to_list_if_needed(data['Dp']),
9292
"D": to_list_if_needed(data['D']),
93-
"status": "PASSED"
93+
"rtol": tolerances["rtol"],
94+
"atol": tolerances["atol"]
9495
}
95-
if xfail["xfail"]:
96-
test_result['status'] = "XFAILED"
9796

98-
test_results.append(test_result)
97+
98+
record_property('test_data', test_result)
9999

100100
npt.assert_allclose(data['f'], f_fit, rtol=tolerances["rtol"]["f"], atol=tolerances["atol"]["f"])
101101
npt.assert_allclose(data['D'], D_fit, rtol=tolerances["rtol"]["D"], atol=tolerances["atol"]["D"])

utilities/report-summary.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pathlib
2+
import json
3+
import sys
4+
5+
def summarize_test_report(input_file:str, output_file:str):
6+
file = pathlib.Path(__file__)
7+
report_path = file.with_name(input_file)
8+
with report_path.open() as f:
9+
report_info = json.load(f)
10+
summary = []
11+
for test_case in report_info['tests']:
12+
values = test_case['user_properties'][0]['test_data']
13+
values['status'] = test_case['outcome']
14+
summary.append(values)
15+
16+
with open(output_file, 'w') as f:
17+
json.dump(summary, f, indent=4)
18+
19+
if __name__ == '__main__':
20+
if len(sys.argv) != 3:
21+
print("Usage: python report-summary.py <input_file> <output_file>")
22+
sys.exit(1)
23+
24+
input_file = sys.argv[1]
25+
output_file = sys.argv[2]
26+
summarize_test_report(input_file, output_file)

website/dashboard/test_plots.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
document.addEventListener('DOMContentLoaded', function() {
2-
fetch('test_results_report.json')
2+
fetch('report-summary.json')
33
.then(response => response.json())
44
.then(data => {
5-
var rtol = data['rtol']
6-
7-
var atol = data['atol']
8-
9-
function createPlot(container, parameter, rtol_value, atol_value) {
10-
var reference_values = data['results'].map(d => d[parameter]); // Assuming fit values are the reference
11-
var fit_values = data['results'].map(d => d[parameter + '_fit']);
5+
function createPlot(container, parameter) {
6+
var reference_values = data.map(d => d[parameter]);
7+
var fit_values = data.map(d => d[parameter + '_fit']);
128
var errors = fit_values.map((d, i) => d - reference_values[i]);
139

14-
var tolerance = reference_values.map(d => atol_value + rtol_value * d);
15-
var negative_tolerance = reference_values.map(d => -(atol_value + rtol_value * d));
10+
var tolerance = reference_values.map((d, i) => data[i]['atol'][parameter] + data[i]['rtol'][parameter] * d);
11+
var negative_tolerance = reference_values.map((d, i) => -(data[i]['atol'][parameter] + data[i]['rtol'][parameter] * d));
1612

1713
var scatter_trace = {
1814
x: reference_values,
@@ -51,8 +47,8 @@ document.addEventListener('DOMContentLoaded', function() {
5147
Plotly.newPlot(container, plot_data, layout);
5248
}
5349

54-
createPlot('plot_f_fit', 'f', rtol.f, atol.f);
55-
createPlot('plot_Dp_fit', 'Dp', rtol.Dp, atol.Dp);
56-
createPlot('plot_D_fit', 'D', rtol.D, atol.D);
50+
createPlot('plot_f_fit', 'f');
51+
createPlot('plot_Dp_fit', 'Dp');
52+
createPlot('plot_D_fit', 'D');
5753
});
5854
});

0 commit comments

Comments
 (0)