Conversation
This was referenced Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds in a
tests/directory with two test scripts.First,
test_spectra.pyis a proper unit testing module, which has functions for testing loading and manipulating the spectra (scaling, combining etc). This is mostly done using mock data (any of the test functions that end with_mock), since we can feed simple values in and compare to what we'd expect to get out with Numpy. There are also some_realfunctions that apply to the included data files to make sure they are loaded correctly as well.Ultimately this is the first part of a full unit testing suite, which should be run through continuous integration whenever future changes are made to the code (see #6). As included, this can be run with pytest, and all tests currently pass. There are a few major limitations before it's ready for proper CI though:
-sflag to be used).SNF-simulations/snf_simulationsdirectory. For example:SNF-simulations/snf_simulations/load_data.py
Line 8 in 64e3e9d
Most of the test functions use Numpy arrays to verify the output of ROOT functions (TH1::Interpolate, TH1::Merge etc). This was a deliberate choice with the aim of eventually replacing ROOT in the main package code (see #14).
The second script,
test_commandline.py, is more of a functional script to verify the results of the code compared to the "canonical" output of the maincommand_line.pyscript in the package. These output files are included intests/test_data/, so when runningtest_commandline.pyit will check that what's calculated matches those files, for both Sizewell and Hartlepool.As mentioned above, there are a lot of plotting and output functions currently embedded into the main code, but the script will run the function, load the output, check with the test output and then clean up the spare file. You still have to close each plot window as it opens, and while we can compare the contents of CSVs and some returned values you can't easily do that for plots or values that are only printed to the terminal.
This isn't really meant for integrated testing like
test_spectra.py, although I've formatted it as such, and it does run and pass with pytest. Instead, it's more to verify later on that the output is still the same if larger structural/functional changes are made within the package. Eventually, once the entire package is rewritten then this script should be replaced with more structured unit and end-to-end testing.When running pytest with code coverage enabled (from within
SNF-simulations/snf_simulationsrunpytest -s --cov=snf_simulations --cov-report html ../tests/test_spectra.pyto generate the HTML report) the current coverage value is 93%, which is pretty good. I'd have liked to get to 100%, but the only function that isn't covered isplotting.plot()which since it only outputs a file can't really be tested easily. Also the actualcommand_line.pyfile has 0% coverage, but that's because it's really a script not a module andtest_commandline.pyduplicates everything it does. Otherwise everything is covered.While writing these tests, I did my best to keep the main part of the code completely untouched, since the entire point was to get a baseline that I can compare later changes to. However there were a few major bugs I found that I did include fixes for:
These all came from noticing issues when feeding in mock data in the test functions, but don't really make any difference to the outputs.