Add tests for chart data
It would be extremely useful to have tests to check that chart output for each modality is as expected for each type of chart, including filtering in a variety of ways.
Ensure there is some testing of chart data that has been filtered by acquisition name to ensure that a study-level chart contains the correct number of studies when a study contains more than one acquisition of the same name.
The table below contains a list of the basic chart types contained in OpenREM and an indication of whether there is test coverage for at least one chart of that type and where the test code is located, correct as of 20/2/2024. Every basic chart type is tested at least once.
Type of chart | File test code located in | Function name(s) of test | Modalities covered by the test |
---|---|---|---|
Bar chart, mean | test_charts_common.py | check_series_and_category_names; check_average_data; check_avg_and_counts | CT, DX, MG |
Bar chart, median | test_charts_common.py | check_series_and_category_names; check_average_data; check_avg_and_counts | CT, DX, MG |
Bar chart, frequency | test_charts_common.py | check_series_and_category_names; check_frequency_data; check_frequencies | CT, DX, MG |
Box plot | test_charts_common.py | check_boxplot_data; check_boxplot_xy | CT, DX, MG |
Histogram | test_charts_mg.py; test_charts_ct.py | test_acq_agd_histogram; test_acq_dlp | CT, MG |
Line chart over time, mean | test_charts_dx.py | test_acquisition_dap_over_time; test_acquisition_kvp_over_time; test_acquisition_mas_over_time | DX |
Line chart over time, median | test_charts_dx.py | test_acquisition_dap_over_time; test_acquisition_kvp_over_time; test_acquisition_mas_over_time | DX |
Scatter chart | test_charts_mg.py | test_agd_vs_cbt; test_kvp_vs_cbt; test_mas_vs_cbt | MG |
Bar chart, workload | test_charts_common.py | check_workload_data | MG |
Bar chart, AGD vs compressed breast thickness | test_charts_common.py | check_sys_name_x_y_data | MG |
Bar chart, average AGD vs compressed breast thickness | test_charts_common.py | check_sys_name_x_y_data | MG |
Comments (55)
-
reporter -
reporter Logging the test user in to see if it lets the tests run. References issue #686
→ <<cset e5cbfa6ab167>>
-
reporter Commenting out print statement (Ed, that was why you saw the results text). References issue #686
→ <<cset fdbfab15e332>>
-
reporter The tests work OK for me locally
python manage.py test remapp.tests.test_charts_dx
I'll try setting an SQLite database later to see if it works with that.
-
reporter It also works fine with an SQLite database
-
reporter Added some specific tests for acquisition DAP mean, count, names and histogram data. These tests work on my local system. References issue #686
→ <<cset a5e173b382ce>>
-
reporter I may be approaching this incorrectly. I think there is a way of testing a Django view.
https://realpython.com/testing-in-django-part-1-best-practices-and-examples/#testing-views
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing#Views
-
reporter Adding test user to the viewgroup to see if remote tests will run. References issue #686
→ <<cset 4cddb213f485>>
-
Quick check that moving the trigger import to later doesn't solve issue. Refs #686
→ <<cset a5e7ac54fb24>>
-
Not sure what is going on, and I don't know if this is the best way of doing it or not, but it works now @dplatten!
I think testing a view is good if you want to inspect the resulting html - that is what we do with for example test_filters_ct
Then we have non-Django specific web testing tools that allow testing automated pointing and clicking, which I had been thinking might be good for all the charts?
And then we have the approach you have taken to get the data that is fed into the charts.
I don't know that any one is the best way -- I think in time we need some of all of them!
-
reporter Many thanks for getting this to work. I can now concentrate on putting together tests that will cover all the chart types for each modality using a range of filters.
-
reporter Added a views test. References issue #686
→ <<cset a5bcf42b78c5>>
-
reporter Added tests of acq DAP per system with and without histograms. References issue #686
→ <<cset 13c9505c47fd>>
-
reporter For DX I still need to add:
- case-insensitive test
- workload chart
- DAP over time chart
- kVp over time chart
- mAs over time chart
- frequency chart test (done)
- study-level bar chart test (done)
- request-level bar chart test (done)
- kVp acquisition chart (done)
- mAs acquisition chart (done)
-
reporter Added further DX chart tests, including acq frequency, mAs, kVp, study and request DAP. References issue #686
→ <<cset 760bbc8a9add>>
-
reporter Farmed some common code into their own methods to reduce duplication and make it a little clearer what each test is actually trying to test. References issue #686
→ <<cset 588c79dc24ed>>
-
Do you need to order the lists before comparing them?
I've used Counter to compare lists for tests. See
test_import_ct_rdsr_multiple.py
for example. -
reporter Hmm. SQLite and PostgreSQL sort the study names in the opposite order to one another. Swapped them so that it works OK with SQLite; need to change how I do the test so that it is database-agnostic. References issue #686
→ <<cset 2c806e965fdb>>
-
reporter The chart options include the ability to state how you want the chart data ordered, so I'd like to keep the ordering in. However, this may be creating a rod for my own back. New commit coming up.
-
I see
-
reporter Added check for SQLite database to help with data order; assumes all other databases will sort strings in the same way that my PostgreSQL does; may be more sensible to bin the idea of worrying about this and just use Counter, as suggested by Ed. References issue #686
→ <<cset 1dc53e0f3333>>
-
reporter These tests now work on my PostgreSQL install and on the SQLite system used by the automatic on-line tests.
-
reporter Adding option for chart code to return a Python dict instead of HTML. This will enable tests to be run on the charts. Refs issue
#477and #686→ <<cset f63db4f2c2b6>>
-
reporter Plumbing dict option into the view. Correcting an error with the CT num events charts that was preventing some from being displayed or calculated. Refs issue
#477and #686→ <<cset 8d1ca21edaa6>>
-
reporter Adding initial DX chart tests. Refs issue
#477and issue #686→ <<cset c0d239497d5d>>
-
reporter Passed code through Black. Refs issue
#477and issue #686→ <<cset 4522780ef28d>>
-
reporter Added tests on boxplot data. Refs issue
#477and issue #686→ <<cset 94de10362a88>>
-
reporter Added an additional comment [skip ci]. Refs issue
#477and issue #686→ <<cset febfb3d23de3>>
-
reporter Reduced length of code a little using some for statements. Refs issue
#477and issue #686→ <<cset 7ce805520295>>
-
reporter Added tests of DX acquisition frequency chart. Refs issue
#477and issue #686→ <<cset fedd3ed1263a>>
-
reporter Separated frequency chart test into own method. Refs issue #686
→ <<cset 54bec7ca7ebe>>
-
reporter Added DX average acquisition mAs chart tests. Refs issue #686
→ <<cset 42bd62481267>>
-
reporter Added method to compare average and count values - saves lots of lines of code. Swapped order of two radiographic charts. Refs issue #686 and
#477→ <<cset 25ca12bbaf8d>>
-
reporter Refactored some code to reduce length and improve readability. Refs issue #686
→ <<cset 8036adccdb9a>>
-
reporter Ran code through Black. Refs issue #686
→ <<cset fdf8a384d7b1>>
-
reporter Added requested procedure tests. These are not really very good as the included DICOM data has blank requested procedure names... Refs issue #686
→ <<cset 319491ab8fa7>>
-
reporter Added requested procedure frequency tests... Refs issue #686
→ <<cset c3d11c282726>>
-
reporter Added study description frequency tests. Refs issue #686
→ <<cset 23233015f287>>
-
reporter Added study description average DAP chart tests. Refs issue #686
→ <<cset cbe79cf7a495>>
-
reporter Added test of required chart list. Refs issue #686
→ <<cset 9f2e72c3a57b>>
-
reporter Modified test of required chart list so it just checks the variable names. Refs issue #686
→ <<cset 511485405533>>
-
reporter Removed redundant test file that is not imported with rdsr command. Refs issue #686
→ <<cset 878baf6723a9>>
-
Refs issue #686 - Included Mean, Median and Boxplot tests for study DLP and requested DLP.
→ <<cset c7c865826175>>
-
Refs issue #686 - Included Histogram tests for acquisition protocol DLP, study DLP and requested procedure DLP
→ <<cset 26d8977f476b>>
-
Refs issue #686 - Included repeated tests wth plot series per system selected for acquisition protocol DLP, study DLP and requested procedure DLP
→ <<cset 2b6c82f5b08a>>
-
Refs issue #686 - Included mean,median, boxplot and histogram with and without plotseriespersystem for acquisition CTDI
→ <<cset 6b9c83b865dd>>
-
Refs issue #686 - Included mean,median, boxplot and histogram with and without plotseriespersystem for study CTDI
→ <<cset 704d647b1878>>
-
Refs issue #686 - Included study frequency tests. Also included mean,median, boxplot and histogram tests for number of events. Yet to add plotseriespersystem repeats Also ran black for formatting
→ <<cset 04c728df1a14>>
-
reporter Merged in issue686writeChartTests (pull request #446)
Issue686writeChartTests
Approved-by: Ed McDonagh Approved-by: David Platten
Refs issue #686
Thanks to Daniel Wyatt for writing the tests
→ <<cset 2350cca70304>>
-
reporter Refactored some chart test methods to reduce duplication. Reduced number of decimal places in some test data. Refs issue
#870and refs issue #686→ <<cset 05da801c9524>>
-
reporter - edited description
-
reporter - edited description
- changed milestone to 1.2.0
-
reporter - edited description
-
reporter - edited description
-
reporter - edited description
- Log in to comment
Added skeleton dx chart test file. Also amended an except in view.py to ensure that data is still created on KeyError. References issue #686
→ <<cset fa3eb598e73b>>