@@ -46,7 +46,7 @@ def test_export_file_manager_default_ids(self):
46
46
directory = self .create_tempdir ()
47
47
base_name = os .path .join (directory .full_path , 'basename' )
48
48
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 ))
50
50
directory .create_file (manager .next_name ())
51
51
manager .clean_up () # Shouldn't do anything...
52
52
self .assertLen (tf .io .gfile .listdir (directory .full_path ), 1 )
@@ -79,7 +79,7 @@ def next_id():
79
79
80
80
manager = actions .ExportFileManager (
81
81
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 ))
83
83
id_num = 30
84
84
directory .create_file (manager .next_name ())
85
85
self .assertLen (tf .io .gfile .listdir (directory .full_path ), 1 )
@@ -105,6 +105,54 @@ def next_id():
105
105
_id_sorted_file_base_names (directory .full_path ),
106
106
['basename-200' , 'basename-1000' ])
107
107
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
+
108
156
def test_export_file_manager_managed_files (self ):
109
157
directory = self .create_tempdir ()
110
158
directory .create_file ('basename-5' )
0 commit comments