@@ -28,6 +28,7 @@ def setUp(self) -> None:
28
28
29
29
def tearDown (self ) -> None :
30
30
self ._close_image_stacks ()
31
+ self ._check_datasets_consistent ()
31
32
super ().tearDown ()
32
33
self .assertFalse (self .main_window .isVisible ())
33
34
@@ -43,6 +44,7 @@ def test_func() -> bool:
43
44
return (current_stacks - initial_stacks ) >= 1
44
45
45
46
wait_until (test_func , max_retry = 600 )
47
+ self ._check_datasets_consistent ()
46
48
47
49
@classmethod
48
50
def _click_stack_selector (cls ):
@@ -89,6 +91,7 @@ def test_load_180(self, mocked_select_file):
89
91
self .assertEqual (len (stacks_after ), 5 )
90
92
self .assertIn (stacks [0 ], stacks_after )
91
93
self .assertTrue (stacks [0 ].presenter .images .has_proj180deg ())
94
+ self ._check_datasets_consistent ()
92
95
93
96
def _get_log_angle (self , log_path ):
94
97
with open (log_path ) as log_file :
@@ -224,3 +227,74 @@ def test_func() -> bool:
224
227
self .assertEqual (image_shape , [128 , 128 ])
225
228
self .assertEqual (image_count , expected_count )
226
229
self .assertEqual (len (sample .real_projection_angles ().value ), expected_count )
230
+
231
+ @mock .patch ("mantidimaging.gui.windows.main.MainWindowView._get_file_name" )
232
+ def test_replace_image_stack (self , mocked_select_file ):
233
+ new_stack = Path (LOAD_SAMPLE ).parents [1 ] / "Flat_Before/" / "IMAT_Flower_Flat_Before_000000.tif"
234
+ mocked_select_file .return_value = new_stack
235
+ self .assertEqual (len (self .main_window .presenter .get_active_stack_visualisers ()), 0 )
236
+ self ._load_data_set ()
237
+ self .assertEqual (len (self .main_window .presenter .get_active_stack_visualisers ()), 5 )
238
+ self .assertEqual (100 , list (self .main_window .presenter .datasets )[0 ].sample .data .shape [0 ])
239
+
240
+ self .main_window .dataset_tree_widget .topLevelItem (0 ).setSelected (True )
241
+ self ._check_datasets_consistent ()
242
+
243
+ self .main_window ._add_images_to_existing_dataset ()
244
+ QTest .qWait (SHORT_DELAY )
245
+
246
+ with mock .patch (
247
+ "mantidimaging.gui.windows.add_images_to_dataset_dialog.view.QFileDialog.getOpenFileName" ) as gofn :
248
+ gofn .return_value = (str (new_stack ), None )
249
+ self .main_window .add_to_dataset_dialog .chooseFileButton .click ()
250
+
251
+ self .main_window .add_to_dataset_dialog .accepted .emit ()
252
+ QTest .qWait (SHORT_DELAY )
253
+ self ._check_datasets_consistent ()
254
+ self .assertEqual (20 , list (self .main_window .presenter .datasets )[0 ].sample .data .shape [0 ])
255
+
256
+ def _check_datasets_consistent (self , show_datasets = False ) -> None :
257
+ print ("_check_datasets_consistent" )
258
+ if show_datasets :
259
+ print ("Main window datasets" )
260
+ for k , v in self .main_window .presenter .model .datasets .items ():
261
+ print (" dataset:" , k )
262
+ for image_stack in v .all :
263
+ print (" " , image_stack .id , image_stack .name )
264
+ print ("Main window visualisers/tabs" )
265
+ for vis in self .main_window .presenter .get_active_stack_visualisers ():
266
+ print (" " , vis .id , vis .name )
267
+ print ("Main window treeview" )
268
+ for i in range (self .main_window .dataset_tree_widget .topLevelItemCount ()):
269
+ tree_ds = self .main_window .dataset_tree_widget .topLevelItem (i )
270
+ print (f" dataset: { tree_ds .id } { tree_ds .text (0 )} " )
271
+ for j in range (tree_ds .childCount ()):
272
+ tree_is = tree_ds .child (j )
273
+ print (f" { tree_is .id } { tree_is .text (0 )} " )
274
+
275
+ # Datasets
276
+ open_dataset_ids = list (self .main_window .presenter .model .datasets .keys ())
277
+ self .assertEqual (len (open_dataset_ids ), len (set (open_dataset_ids )))
278
+ image_stack_ids = self .main_window .presenter .model .image_ids
279
+ self .assertEqual (len (image_stack_ids ), len (set (image_stack_ids )))
280
+
281
+ # Visualisers/Tabs
282
+ visualiser_ids = [vis .id for vis in self .main_window .presenter .get_active_stack_visualisers ()]
283
+ self .assertEqual (len (visualiser_ids ), len (set (visualiser_ids )))
284
+ self .assertEqual (len (visualiser_ids ), len (image_stack_ids ))
285
+ for visualiser_id in visualiser_ids :
286
+ self .assertIn (visualiser_id , image_stack_ids )
287
+
288
+ #Tree view
289
+ tree_datasets = [
290
+ self .main_window .dataset_tree_widget .topLevelItem (i )
291
+ for i in range (self .main_window .dataset_tree_widget .topLevelItemCount ())
292
+ ]
293
+ tree_image_stack_ids = []
294
+ self .assertEqual (len (open_dataset_ids ), len (tree_datasets ))
295
+ for tree_dataset in tree_datasets :
296
+ self .assertIn (tree_dataset .id , open_dataset_ids )
297
+ for i in range (tree_dataset .childCount ()):
298
+ tree_image_stack_ids .append (tree_dataset .child (i ).id )
299
+ self .assertEqual (len (tree_image_stack_ids ), len (set (tree_image_stack_ids )))
300
+ self .assertEqual (len (tree_image_stack_ids ), len (image_stack_ids ))
0 commit comments