3
3
from __future__ import annotations
4
4
5
5
from unittest import mock
6
+ from pathlib import Path
6
7
7
8
from PyQt5 .QtCore import Qt
8
9
from PyQt5 .QtTest import QTest
9
10
11
+ from mantidimaging .core .utility .sensible_roi import SensibleROI
10
12
from mantidimaging .gui .test .gui_system_base import GuiSystemBase , SHOW_DELAY , SHORT_DELAY
13
+ from mantidimaging .gui .windows .spectrum_viewer .model import SpecType
11
14
from mantidimaging .test_helpers .qt_test_helpers import wait_until
12
15
13
16
@@ -57,6 +60,19 @@ def test_add_roi(self) -> None:
57
60
self .assertIn (f'roi_{ i } ' , self .spectrum_window .roi_table_model .roi_names ())
58
61
self .assertIn (f'roi_{ i } ' , self .spectrum_window .spectrum_widget .roi_dict )
59
62
63
+ def test_remove_roi (self ) -> None :
64
+ QTest .mouseClick (self .spectrum_window .addBtn , Qt .MouseButton .LeftButton )
65
+ QTest .qWait (SHORT_DELAY )
66
+ initial_roi_count = self .spectrum_window .roi_table_model .rowCount ()
67
+
68
+ QTest .mouseClick (self .spectrum_window .removeBtn , Qt .MouseButton .LeftButton )
69
+ QTest .qWait (SHORT_DELAY )
70
+ final_roi_count = self .spectrum_window .roi_table_model .rowCount ()
71
+
72
+ self .assertEqual (final_roi_count , initial_roi_count - 1 )
73
+ self .assertNotIn (f'roi_{ initial_roi_count - 1 } ' , self .spectrum_window .roi_table_model .roi_names ())
74
+ self .assertNotIn (f'roi_{ initial_roi_count - 1 } ' , self .spectrum_window .spectrum_widget .roi_dict )
75
+
60
76
def test_change_roi_color (self ) -> None :
61
77
QTest .mouseClick (self .spectrum_window .addBtn , Qt .MouseButton .LeftButton )
62
78
QTest .qWait (SHORT_DELAY )
@@ -80,22 +96,19 @@ def test_rename_roi(self) -> None:
80
96
def test_adjust_roi (self ):
81
97
QTest .mouseClick (self .spectrum_window .addBtn , Qt .MouseButton .LeftButton )
82
98
QTest .qWait (SHORT_DELAY )
83
- roi_name = self .spectrum_window .presenter .get_roi_names ()[0 ]
84
- roi = self .spectrum_window .presenter .model .get_roi (roi_name )
85
- new_roi = roi .copy ()
86
- new_roi .left += 10
87
- new_roi .top += 10
88
- self .spectrum_window .presenter .model .set_roi (roi_name , new_roi )
99
+
100
+ roi_names = self .spectrum_window .presenter .get_roi_names ()
101
+ roi_name = next (name for name in roi_names if name != 'all' )
102
+
103
+ roi_widget = self .spectrum_window .spectrum_widget .roi_dict [roi_name ]
104
+
105
+ roi_widget .setPos ((roi_widget .pos ().x () + 10 , roi_widget .pos ().y () + 10 ))
89
106
self .spectrum_window .presenter .handle_roi_moved ()
90
- updated_roi = self .spectrum_window .presenter .model .get_roi (roi_name )
91
- assert updated_roi .left == new_roi .left
92
- assert updated_roi .top == new_roi .top
93
107
94
- def test_reset_units_menu (self ) -> None :
95
- self .assertFalse (self .spectrum_window .tof_mode_select_group .isEnabled ())
108
+ updated_roi = self .spectrum_window .presenter .model .get_roi (roi_name )
96
109
97
- self . spectrum_window . presenter . handle_sample_change ( "sample_uuid" )
98
- self . assertTrue ( self . spectrum_window . tof_mode_select_group . isEnabled () )
110
+ assert updated_roi . left == roi_widget . pos (). x ( )
111
+ assert updated_roi . top == roi_widget . pos (). y ( )
99
112
100
113
def test_normalisation_toggle (self ):
101
114
self .spectrum_window .normaliseCheckBox .setCheckState (Qt .CheckState .Checked )
@@ -114,3 +127,18 @@ def test_export_csv(self) -> None:
114
127
with open ("test_output.csv" , "r" ) as file :
115
128
lines = file .readlines ()
116
129
self .assertGreater (len (lines ), 1 )
130
+
131
+ @mock .patch ("mantidimaging.gui.windows.spectrum_viewer.presenter.SpectrumViewerWindowPresenter._async_save_done" )
132
+ def test_export_rits (self , mock_async_save_done ):
133
+ with mock .patch (
134
+ 'mantidimaging.gui.windows.spectrum_viewer.view.SpectrumViewerWindowView.get_rits_export_filename'
135
+ ) as mock_get_rits_export_filename :
136
+ mock_get_rits_export_filename .return_value = '/tmp/test_export.dat'
137
+ QTest .mouseClick (self .spectrum_window .exportButtonRITS , Qt .MouseButton .LeftButton )
138
+ QTest .qWait (SHORT_DELAY )
139
+ wait_until (lambda : mock_async_save_done .call_count > 0 )
140
+
141
+ def test_reset_units_menu (self ) -> None :
142
+ self .assertFalse (self .spectrum_window .tof_mode_select_group .isEnabled ())
143
+ self .spectrum_window .presenter .handle_sample_change ("uuid" )
144
+ self .assertTrue (self .spectrum_window .tof_mode_select_group .isEnabled ())
0 commit comments