@@ -66,7 +66,7 @@ class KhiopsRemoteAccessTests(unittest.TestCase, KhiopsTestHelper):
6666
6767 @classmethod
6868 def init_remote_bucket (cls , bucket_name = None , proto = None ):
69- # create remote root_temp_dir
69+ # create the remote root_temp_dir
7070 remote_resource = fs .create_resource (
7171 f"{ proto } ://{ bucket_name } /khiops-cicd/tmp"
7272 )
@@ -84,7 +84,7 @@ def init_remote_bucket(cls, bucket_name=None, proto=None):
8484 f"{ proto } ://{ bucket_name } /khiops-cicd/samples/{ file } " ,
8585 os .path .join (kh .get_samples_dir (), file ),
8686 )
87- # symetric call to ensure the upload was OK
87+ # symmetric call to ensure the upload was OK
8888 fs .copy_to_local (
8989 f"{ proto } ://{ bucket_name } /khiops-cicd/samples/{ file } " , "/tmp/dummy"
9090 )
@@ -156,10 +156,22 @@ def setUp(self):
156156 )
157157 self .print_test_title ()
158158
159+ def tearDown (self ):
160+ # Cleanup the output dir (the files within and the folder)
161+ if hasattr (self , "folder_name_to_clean_in_teardown" ):
162+ for filename in fs .list_dir (self .folder_name_to_clean_in_teardown ):
163+ fs .remove (
164+ fs .get_child_path (
165+ self .folder_name_to_clean_in_teardown , filename
166+ )
167+ )
168+ fs .remove (self .folder_name_to_clean_in_teardown )
169+
159170 def test_train_predictor_with_remote_access (self ):
160171 """Test train_predictor with remote resources"""
161172 iris_data_dir = fs .get_child_path (kh .get_runner ().samples_dir , "Iris" )
162- output_dir = fs .get_child_path (
173+ # ask for folder cleaning during tearDown
174+ self .folder_name_to_clean_in_teardown = output_dir = fs .get_child_path (
163175 self .results_dir_root (),
164176 f"test_{ self .remote_access_test_case ()} _remote_files_{ uuid .uuid4 ()} " ,
165177 )
@@ -176,22 +188,21 @@ def test_train_predictor_with_remote_access(self):
176188 trace = True ,
177189 )
178190
179- # Check the existents of the trining files
191+ # Check the existence of the training files
180192 self .assertTrue (fs .exists (fs .get_child_path (output_dir , "AllReports.khj" )))
181193 self .assertTrue (fs .exists (fs .get_child_path (output_dir , "Modeling.kdic" )))
182194
183- # Cleanup
184- for filename in fs .list_dir (output_dir ):
185- fs .remove (fs .get_child_path (output_dir , filename ))
186-
187195 def test_khiops_classifier_with_remote_access (self ):
188196 """Test the training of a khiops_classifier with remote resources"""
197+
189198 # Setup paths
190199 # note : the current implementation forces the khiops.log file
191200 # to be created in the output_dir (thus local)
192201 # (any attempt to override it as an arg
193202 # for the fit method will be ignored)
194- output_dir = (
203+
204+ # ask for folder cleaning during tearDown
205+ self .folder_name_to_clean_in_teardown = output_dir = (
195206 self ._khiops_temp_dir + f"/KhiopsClassifier_output_dir_{ uuid .uuid4 ()} /"
196207 )
197208 iris_data_dir = fs .get_child_path (kh .get_runner ().samples_dir , "Iris" )
@@ -215,10 +226,6 @@ def test_khiops_classifier_with_remote_access(self):
215226 predict_path = fs .get_child_path (output_dir , "predict.txt" )
216227 self .assertTrue (fs .exists (predict_path ), msg = f"Path: { predict_path } " )
217228
218- # Cleanup
219- for filename in fs .list_dir (output_dir ):
220- fs .remove (fs .get_child_path (output_dir , filename ))
221-
222229 def test_khiops_coclustering_with_remote_access (self ):
223230 """Test the training of a khiops_coclustering with remote resources"""
224231 # Skip if only short tests are run
@@ -229,7 +236,9 @@ def test_khiops_coclustering_with_remote_access(self):
229236 # to be created in the output_dir (thus local)
230237 # (any attempt to override it as an arg
231238 # for the fit method will be ignored)
232- output_dir = (
239+
240+ # ask for folder cleaning during tearDown
241+ self .folder_name_to_clean_in_teardown = output_dir = (
233242 self ._khiops_temp_dir
234243 + f"/KhiopsCoclustering_output_dir_{ uuid .uuid4 ()} /"
235244 )
@@ -262,6 +271,8 @@ def test_train_predictor_fail_and_log_with_remote_access(self):
262271 self ._khiops_temp_dir , f"khiops_log_{ uuid .uuid4 ()} .log"
263272 )
264273
274+ # no cleaning required as an exception would be raised
275+ # without any result produced
265276 output_dir = fs .get_child_path (
266277 self .results_dir_root (),
267278 f"test_{ self .remote_access_test_case ()} _remote_files_{ uuid .uuid4 ()} " ,
0 commit comments