@@ -66,6 +66,24 @@ def test_no_files_exist(self, mock_print, mock_gather, mock_exists):
6666 mock_print .assert_called_once ()
6767 self .assertIn ("There are 0 files" , mock_print .call_args [0 ][0 ])
6868
69+ @patch ("cautiousrobot.utils.os.path.exists" , return_value = True )
70+ @patch ("cautiousrobot.utils.gather_file_paths" , return_value = ["test_images/species1/a.jpg" , "test_images/shouldnotcount/b.jpg" ])
71+ def test_subfolders_handling (self , mock_gather , mock_exists ):
72+ """When `subfolders` is provided, expected paths should be constructed and matched."""
73+ sub_df = pd .DataFrame ({
74+ "subfolder" : ["species1" , "species2" ],
75+ self .filename_col : ["a.jpg" , "b.jpg" ]
76+ })
77+
78+ updated_df , missing_df = check_existing_images (
79+ self .csv_path , self .img_dir , sub_df .copy (), self .filename_col , subfolders = "subfolder"
80+ )
81+
82+ # species1/a.jpg should be marked present, species2/b.jpg missing
83+ self .assertTrue (updated_df .loc [0 , "in_img_dir" ])
84+ self .assertFalse (updated_df .loc [1 , "in_img_dir" ])
85+ self .assertEqual (len (missing_df ), 1 )
86+
6987
7088if __name__ == "__main__" :
7189 unittest .main ()
0 commit comments