@@ -46,7 +46,7 @@ def test_export_file_manager_default_ids(self):
4646 directory = self .create_tempdir ()
4747 base_name = os .path .join (directory .full_path , 'basename' )
4848 manager = actions .ExportFileManager (base_name , max_to_keep = 3 )
49- self .assertLen (tf .io .gfile .listdir (directory .full_path ), 0 )
49+ self .assertEmpty (tf .io .gfile .listdir (directory .full_path ))
5050 directory .create_file (manager .next_name ())
5151 manager .clean_up () # Shouldn't do anything...
5252 self .assertLen (tf .io .gfile .listdir (directory .full_path ), 1 )
@@ -79,7 +79,7 @@ def next_id():
7979
8080 manager = actions .ExportFileManager (
8181 base_name , max_to_keep = 2 , next_id_fn = next_id )
82- self .assertLen (tf .io .gfile .listdir (directory .full_path ), 0 )
82+ self .assertEmpty (tf .io .gfile .listdir (directory .full_path ))
8383 id_num = 30
8484 directory .create_file (manager .next_name ())
8585 self .assertLen (tf .io .gfile .listdir (directory .full_path ), 1 )
@@ -105,6 +105,54 @@ def next_id():
105105 _id_sorted_file_base_names (directory .full_path ),
106106 ['basename-200' , 'basename-1000' ])
107107
108+ def test_export_file_manager_with_suffix (self ):
109+ directory = self .create_tempdir ()
110+ base_name = os .path .join (directory .full_path , 'basename' )
111+
112+ id_num = 0
113+
114+ def next_id ():
115+ return id_num
116+
117+ subdirectory = 'sub'
118+
119+ manager = actions .ExportFileManager (
120+ base_name , max_to_keep = 2 , next_id_fn = next_id , subdirectory = subdirectory
121+ )
122+ self .assertEmpty (tf .io .gfile .listdir (directory .full_path ))
123+ id_num = 30
124+ directory .create_file (manager .next_name ())
125+ self .assertLen (tf .io .gfile .listdir (directory .full_path ), 1 )
126+ manager .clean_up () # Shouldn't do anything...
127+ self .assertEqual (
128+ _id_sorted_file_base_names (directory .full_path ), ['basename-30' ]
129+ )
130+ id_num = 200
131+ directory .create_file (manager .next_name ())
132+ self .assertLen (tf .io .gfile .listdir (directory .full_path ), 2 )
133+ manager .clean_up () # Shouldn't do anything...
134+ self .assertEqual (
135+ _id_sorted_file_base_names (directory .full_path ),
136+ ['basename-30' , 'basename-200' ],
137+ )
138+ id_num = 1000
139+ directory .create_file (manager .next_name ())
140+ self .assertLen (tf .io .gfile .listdir (directory .full_path ), 3 )
141+ self .assertEqual (
142+ _id_sorted_file_base_names (directory .full_path ),
143+ ['basename-30' , 'basename-200' , 'basename-1000' ],
144+ )
145+ manager .clean_up () # Should delete file with lowest ID.
146+ self .assertLen (tf .io .gfile .listdir (directory .full_path ), 3 )
147+ # Note that the base folder is intact, only the suffix folder is deleted.
148+ self .assertEqual (
149+ _id_sorted_file_base_names (directory .full_path ),
150+ ['basename-30' , 'basename-200' , 'basename-1000' ],
151+ )
152+
153+ step_folder = os .path .join (directory .full_path , 'basename-1000' )
154+ self .assertIn (subdirectory , tf .io .gfile .listdir (step_folder ))
155+
108156 def test_export_file_manager_managed_files (self ):
109157 directory = self .create_tempdir ()
110158 directory .create_file ('basename-5' )
0 commit comments