Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmeigh committed Aug 20, 2024
1 parent 31f6373 commit a40660a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2320: Enhance System Tests for Spectrum Viewer
58 changes: 58 additions & 0 deletions mantidimaging/gui/test/gui_system_spectrum_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,61 @@ def test_add_roi(self) -> None:
self.assertEqual(final_roi_count, initial_roi_count + 1)
self.assertIn(f'roi_{i}', self.spectrum_window.roi_table_model.roi_names())
self.assertIn(f'roi_{i}', self.spectrum_window.spectrum_widget.roi_dict)

def test_change_roi_color(self) -> None:
QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton)
QTest.qWait(SHORT_DELAY)

new_color = (255, 0, 0, 255)
self.spectrum_window.spectrum_widget.change_roi_colour('roi_1', new_color)

self.assertEqual(self.spectrum_window.spectrum_widget.roi_dict['roi_1'].colour, new_color)

def test_rename_roi(self) -> None:
QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton)
QTest.qWait(SHORT_DELAY)

old_name = 'roi_1'
new_name = 'roi_renamed'
self.spectrum_window.presenter.rename_roi(old_name, new_name)

self.assertNotIn(old_name, self.spectrum_window.spectrum_widget.roi_dict)
self.assertIn(new_name, self.spectrum_window.spectrum_widget.roi_dict)

def test_adjust_roi(self):
QTest.mouseClick(self.spectrum_window.addBtn, Qt.MouseButton.LeftButton)
QTest.qWait(SHORT_DELAY)
roi_name = self.spectrum_window.presenter.get_roi_names()[0]
roi = self.spectrum_window.presenter.model.get_roi(roi_name)
new_roi = roi.copy()
new_roi.left += 10
new_roi.top += 10
self.spectrum_window.presenter.model.set_roi(roi_name, new_roi)
self.spectrum_window.presenter.handle_roi_moved()
updated_roi = self.spectrum_window.presenter.model.get_roi(roi_name)
assert updated_roi.left == new_roi.left
assert updated_roi.top == new_roi.top

def test_reset_units_menu(self) -> None:
self.assertFalse(self.spectrum_window.tof_mode_select_group.isEnabled())

self.spectrum_window.presenter.handle_sample_change("sample_uuid")
self.assertTrue(self.spectrum_window.tof_mode_select_group.isEnabled())

def test_normalisation_toggle(self):
self.spectrum_window.normaliseCheckBox.setCheckState(Qt.CheckState.Checked)
QTest.qWait(SHORT_DELAY)
assert self.spectrum_window.presenter.spectrum_mode == SpecType.SAMPLE_NORMED

self.spectrum_window.normaliseCheckBox.setCheckState(Qt.CheckState.Unchecked)
QTest.qWait(SHORT_DELAY)
assert self.spectrum_window.presenter.spectrum_mode == SpecType.SAMPLE

def test_export_csv(self) -> None:
with mock.patch("mantidimaging.gui.windows.spectrum_viewer.view.QFileDialog.getSaveFileName",
return_value=("test_output.csv", "CSV Files (*.csv)")):
self.spectrum_window.presenter.handle_export_csv()

with open("test_output.csv", "r") as file:
lines = file.readlines()
self.assertGreater(len(lines), 1)

0 comments on commit a40660a

Please sign in to comment.