unit test added for spectrum widget roi colour change #2233
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.
Description
This pull request enhances the Spectrum Widget by adding unit tests to validate the ROI colour change functionality. Two main test scenarios have been implemented.
Test 1: Valid Color Change
Verifies that when a valid colour is selected and applied using onChangeColor(), the ROI colour (colour attribute) in the Spectrum Widget is correctly updated.
Test 2: Invalid Color Handling
Ensures that if an invalid colour is selected (detected by check_color_valid() returning False), the ROI colour remains unchanged from its initial state.
These tests utilize mock.Mock to simulate the behaviour of the colour selection dialog (openColorDialog) and the validation function (check_color_valid), providing controlled testing environments.
Testing
Added unit tests in spectrum_viewer/test/spectrum_test.py:
test_WHEN_colour_changed_THEN_roi_colour_is_set
test_WHEN_colour_is_not_valid_THEN_roi_colour_is_unchanged
Verified tests locally with Python unittest framework.
All tests passed successfully, confirming the accurate behaviour of ROI colour change handling.
Acceptance Criteria
To consider this pull request ready for acceptance and merge into the main branch, the following criteria should be met:
Unit Test Coverage:
Ensure that all newly added unit tests (test_WHEN_colour_changed_THEN_roi_colour_is_set and test_WHEN_colour_is_not_valid_THEN_roi_colour_is_unchanged) pass without errors or failures.
Manual Verification:
Manually verify in a development environment that the Spectrum Widget responds correctly to valid and invalid colour changes as defined in the tests.