brainglobe-segmentation icon indicating copy to clipboard operation
brainglobe-segmentation copied to clipboard

Improve testing of `save` and `export` functionality

Open adamltyson opened this issue 1 year ago • 1 comments

The testing of the GUI functionality is a bit hacky. There are sleep() calls, and we don't test the button clicking and the desired functionality separately.


Based on comments in #114 by @alessandrofelder:

I think a better long-term solution would be to:

  • mock the brainreg_segment.segment.run_save() function in these tests, and check that it's called with the expected parameters
  • write unit tests for run_save() and/or export_all()
    • tests for run_save could again mock export_all to avoid those tests being non-deterministic due to multiprocessing
    • tests for export_all could mock the thread_worker decorator to render it trivial and have export_all run in the same thread. (we trust thread_worker is tested sufficiently in the third party library it comes from and so don't need to test it)

This would ensure cleaner separation between

  • the tests that check that clicking GUI buttons call the expected functionality
  • the tests that call multiprocessing functionality
  • the tests that check the multiprocessing functionality itself

adamltyson avatar Jul 11 '23 09:07 adamltyson

https://pytest-qt.readthedocs.io/en/latest/signals.html might also be useful in this context!

alessandrofelder avatar Jul 11 '23 15:07 alessandrofelder