@@ -567,6 +567,67 @@ def test_dimension_slider_with_nans(
567567 )
568568
569569
570+ @pytest .mark .parametrize (
571+ "nan_time_location" ,
572+ ["start" , "middle" , "end" ],
573+ )
574+ @pytest .mark .parametrize (
575+ "nan_individuals" ,
576+ [["id_0" ], ["id_0" , "id_1" ]],
577+ ids = ["one_individual" , "all_individuals" ],
578+ )
579+ def test_dimension_slider_with_nans_bboxes (
580+ valid_bboxes_path_and_ds_with_localised_nans ,
581+ nan_time_location ,
582+ nan_individuals ,
583+ make_napari_viewer_proxy ,
584+ ):
585+ """Test that the dimension slider is set to the total number of frames
586+ when bboxes data layers with NaNs are loaded.
587+ """
588+ nan_location = {
589+ "time" : nan_time_location ,
590+ "individuals" : nan_individuals ,
591+ }
592+ file_path , ds = valid_bboxes_path_and_ds_with_localised_nans (
593+ nan_location
594+ )
595+
596+ # Define the expected frame index with the NaN value
597+ if nan_location ["time" ] == "start" :
598+ expected_frame = ds .coords ["time" ][0 ]
599+ elif nan_location ["time" ] == "middle" :
600+ expected_frame = ds .coords ["time" ][ds .coords ["time" ].shape [0 ] // 2 ]
601+ elif nan_location ["time" ] == "end" :
602+ expected_frame = ds .coords ["time" ][- 1 ]
603+
604+ # Load the data loader widget
605+ viewer = make_napari_viewer_proxy ()
606+ data_loader_widget = DataLoader (viewer )
607+
608+ # Read sample data with a NaN at the specified location
609+ data_loader_widget .file_path_edit .setText (file_path .as_posix ())
610+ data_loader_widget .source_software_combo .setCurrentText ("VIA-tracks" )
611+
612+ # Check the data contains nans where expected
613+ assert (
614+ ds .position .sel (
615+ individuals = nan_location ["individuals" ],
616+ time = expected_frame ,
617+ )
618+ .isnull ()
619+ .all ()
620+ )
621+
622+ # Call the _on_load_clicked method
623+ data_loader_widget ._on_load_clicked ()
624+
625+ # Check the frame slider is set to the full range of frames
626+ assert viewer .dims .range [0 ] == RangeTuple (
627+ start = 0.0 , stop = ds .position .shape [0 ] - 1 , step = 1.0
628+ )
629+
630+
570631@pytest .mark .parametrize (
571632 "list_input_data_files" ,
572633 [
@@ -614,6 +675,53 @@ def test_dimension_slider_multiple_files(
614675 assert max_frames == ds_long .sizes ["time" ]
615676
616677
678+ @pytest .mark .parametrize (
679+ "list_input_data_files" ,
680+ [
681+ ["valid_bboxes_path_and_ds" , "valid_bboxes_path_and_ds_short" ],
682+ ["valid_bboxes_path_and_ds_short" , "valid_bboxes_path_and_ds" ],
683+ ],
684+ ids = ["long_first" , "short_first" ],
685+ )
686+ def test_dimension_slider_multiple_files_bboxes (
687+ list_input_data_files , make_napari_viewer_proxy , request
688+ ):
689+ """Test that the dimension slider is set to the maximum number of frames
690+ when multiple bboxes data layers are loaded.
691+ """
692+ # Get the datasets to load (paths and ds)
693+ list_paths , list_datasets = [
694+ [
695+ request .getfixturevalue (file_name )[j ]
696+ for file_name in list_input_data_files
697+ ]
698+ for j in range (len (list_input_data_files ))
699+ ]
700+
701+ # Get the maximum number of frames from all datasets
702+ max_frames = max (ds .sizes ["time" ] for ds in list_datasets )
703+
704+ # Load the data loader widget
705+ viewer = make_napari_viewer_proxy ()
706+ data_loader_widget = DataLoader (viewer )
707+
708+ # Load each dataset in order
709+ for file_path in list_paths :
710+ data_loader_widget .file_path_edit .setText (file_path .as_posix ())
711+ data_loader_widget .source_software_combo .setCurrentText ("VIA-tracks" )
712+ data_loader_widget ._on_load_clicked ()
713+
714+ # Check the frame slider is as expected
715+ assert viewer .dims .range [0 ] == RangeTuple (
716+ start = 0.0 , stop = max_frames - 1 , step = 1.0
717+ )
718+
719+ # Check the maximum number of frames is the number of frames
720+ # in the longest dataset
721+ _ , ds_long = request .getfixturevalue ("valid_bboxes_path_and_ds" )
722+ assert max_frames == ds_long .sizes ["time" ]
723+
724+
617725@pytest .mark .parametrize (
618726 "list_input_data_files" ,
619727 [
0 commit comments