Closed sophie22 closed 1 year ago
Coverage Report
Tests | Skipped | Failures | Errors | Time |
---|---|---|---|---|
219 | 0 :zzz: | 0 :x: | 0 :fire: | 3m 12s :stopwatch: |
https://realpython.com/python-main-function/ main function is not supposed to have a return value, but could call other functions that do --> will have to update the test_hazenlib unit tests that rely on evaluating the stdout to check output is as expected
as discussed last week, GitHub tests fail either the CLI test when tasks complete with exit code 1 due to a string being returned from the main
function, or the development tests fail: 2 tests within test_utils rely on having the string returned by main to be compared against expected values.
So to resolve these, I plan to change the main
function so it doesn't return anything and printing of the result is handled before the end of main
and then modifying the test_hazenlib functions to parse sys.stdout to capture the result printed.
https://pytest.org/en/7.4.x/how-to/capture-stdout-stderr.html
@tomaroberts let me know if this sounds sensible and I'll get on it
As discussed on Teams, give it a go :)
made the agreed modifications such that hazenlib.main() does not return anything (completes with exit code 0) and modified the tests for the SNR and relaxometry tasks such that they do not rely on hazenlib.main() which now doesn't return anything, but instead call their respective run() function with equivalent arguments as passed to CLI parser.
in the future, I recommend to separate hazenlib.main() into the following sub-functions:
parse_CLI_args
: purely responsible for presenting a useful help
and parsing the passed arguments
prepare
: all sorts of checks on the inputs provided: includes checking that an available task was requested with applicable optional arguments, and that suitable DICOMs exist within the folder specified. Prepare dicom files to be passed to a task and create report output folder, if applicable.run_task
: make an instance of the selected task class and call its run() function with arguments as identified above, this is what would return the result
dictionary that is printed within the main() function, which returns nothing
Summary
in line with Python best practice, remove all commands possible from the init.py into a new main.py script, make required changes to entry point and subsequently update the READme with the relevant commands EDIT: upon further reading of documentation, looks like there is no real benefit to having the main function in a separate script from init.
combine utility functions from init, tools and shapes.py into a new utils.py, make required changes to all task scripts that use utility functions and their applicable test scripts
resolves #347
Outstanding TODO: