@@ -43,14 +43,12 @@ def setUp(self):
4343 self .automl ._delete_output_directories = lambda : 0
4444
4545 def test_refit_shuffle_on_fail (self ):
46- output = os .path .join (self .test_dir , '..' , '.tmp_refit_shuffle_on_fail' )
47- context = BackendContext (output , output , False , False )
48- backend = Backend (context )
46+ backend_api = self ._create_backend ('test_refit_shuffle_on_fail' )
4947
5048 failing_model = unittest .mock .Mock ()
5149 failing_model .fit .side_effect = [ValueError (), ValueError (), None ]
5250
53- auto = AutoML (backend , 20 , 5 )
51+ auto = AutoML (backend_api , 20 , 5 )
5452 ensemble_mock = unittest .mock .Mock ()
5553 auto .ensemble_ = ensemble_mock
5654 ensemble_mock .get_selected_model_identifiers .return_value = [1 ]
@@ -63,6 +61,10 @@ def test_refit_shuffle_on_fail(self):
6361
6462 self .assertEqual (failing_model .fit .call_count , 3 )
6563
64+ del auto
65+ self ._tearDown (backend_api .temporary_directory )
66+ self ._tearDown (backend_api .output_directory )
67+
6668 def test_only_loads_ensemble_models (self ):
6769 identifiers = [(1 , 2 ), (3 , 4 )]
6870
@@ -96,11 +98,9 @@ def test_raises_if_no_models(self):
9698 self .automl ._load_models ()
9799
98100 def test_fit (self ):
99- output = os .path .join (self .test_dir , '..' , '.tmp_test_fit' )
100- self ._setUp (output )
101+ backend_api = self ._create_backend ('test_fit' )
101102
102103 X_train , Y_train , X_test , Y_test = putil .get_dataset ('iris' )
103- backend_api = backend .create (output , output )
104104 automl = autosklearn .automl .AutoML (backend_api , 20 , 5 )
105105 automl .fit (
106106 X_train , Y_train , metric = accuracy , task = MULTICLASS_CLASSIFICATION ,
@@ -110,7 +110,8 @@ def test_fit(self):
110110 self .assertEqual (automl ._task , MULTICLASS_CLASSIFICATION )
111111
112112 del automl
113- self ._tearDown (output )
113+ self ._tearDown (backend_api .temporary_directory )
114+ self ._tearDown (backend_api .output_directory )
114115
115116 def test_fit_roar (self ):
116117 def get_roar_object_callback (
@@ -129,11 +130,9 @@ def get_roar_object_callback(
129130 tae_runner = ta ,
130131 )
131132
132- output = os .path .join (self .test_dir , '..' , '.tmp_test_fit_roar' )
133- self ._setUp (output )
133+ backend_api = self ._create_backend ('test_fit_roar' )
134134
135135 X_train , Y_train , X_test , Y_test = putil .get_dataset ('iris' )
136- backend_api = backend .create (output , output )
137136 automl = autosklearn .automl .AutoML (
138137 backend = backend_api ,
139138 time_left_for_this_task = 20 ,
@@ -149,16 +148,15 @@ def get_roar_object_callback(
149148 self .assertEqual (automl ._task , MULTICLASS_CLASSIFICATION )
150149
151150 del automl
152- self ._tearDown (output )
151+ self ._tearDown (backend_api .temporary_directory )
152+ self ._tearDown (backend_api .output_directory )
153153
154154 def test_binary_score_and_include (self ):
155155 """
156156 Test fix for binary classification prediction
157157 taking the index 1 of second dimension in prediction matrix
158158 """
159-
160- output = os .path .join (self .test_dir , '..' , '.tmp_test_binary_score' )
161- self ._setUp (output )
159+ backend_api = self ._create_backend ('test_binary_score_and_include' )
162160
163161 data = sklearn .datasets .make_classification (
164162 n_samples = 400 , n_features = 10 , n_redundant = 1 , n_informative = 3 ,
@@ -168,7 +166,6 @@ def test_binary_score_and_include(self):
168166 X_test = data [0 ][200 :]
169167 Y_test = data [1 ][200 :]
170168
171- backend_api = backend .create (output , output )
172169 automl = autosklearn .automl .AutoML (backend_api , 20 , 5 ,
173170 include_estimators = ['sgd' ],
174171 include_preprocessors = ['no_preprocessing' ])
@@ -182,18 +179,17 @@ def test_binary_score_and_include(self):
182179 self .assertGreaterEqual (score , 0.4 )
183180
184181 del automl
185- self ._tearDown (output )
182+ self ._tearDown (backend_api .temporary_directory )
183+ self ._tearDown (backend_api .output_directory )
186184
187185 def test_automl_outputs (self ):
188- output = os .path .join (self .test_dir , '..' ,
189- '.tmp_test_automl_outputs' )
190- self ._setUp (output )
186+ backend_api = self ._create_backend ('test_automl_outputs' )
187+
191188 name = '31_bac'
192189 dataset = os .path .join (self .test_dir , '..' , '.data' , name )
193- data_manager_file = os .path .join (output , '.auto-sklearn' ,
190+ data_manager_file = os .path .join (backend_api . temporary_directory , '.auto-sklearn' ,
194191 'datamanager.pkl' )
195192
196- backend_api = backend .create (output , output )
197193 auto = autosklearn .automl .AutoML (
198194 backend_api , 20 , 5 ,
199195 initial_configurations_via_metalearning = 0 ,
@@ -212,43 +208,41 @@ def test_automl_outputs(self):
212208 'start_time_100' , 'datamanager.pkl' ,
213209 'predictions_ensemble' ,
214210 'ensembles' , 'predictions_test' , 'models' ]
215- self .assertEqual (sorted (os .listdir (os .path .join (output ,
211+ self .assertEqual (sorted (os .listdir (os .path .join (backend_api . temporary_directory ,
216212 '.auto-sklearn' ))),
217213 sorted (fixture ))
218214
219215 # At least one ensemble, one validation, one test prediction and one
220216 # model and one ensemble
221- fixture = os .listdir (os .path .join (output , '.auto-sklearn' ,
217+ fixture = os .listdir (os .path .join (backend_api . temporary_directory , '.auto-sklearn' ,
222218 'predictions_ensemble' ))
223219 self .assertIn ('predictions_ensemble_100_1.npy' , fixture )
224220
225- fixture = os .listdir (os .path .join (output , '.auto-sklearn' ,
221+ fixture = os .listdir (os .path .join (backend_api . temporary_directory , '.auto-sklearn' ,
226222 'models' ))
227223 self .assertIn ('100.1.model' , fixture )
228224
229- fixture = os .listdir (os .path .join (output , '.auto-sklearn' ,
225+ fixture = os .listdir (os .path .join (backend_api . temporary_directory , '.auto-sklearn' ,
230226 'ensembles' ))
231227 self .assertIn ('100.0.ensemble' , fixture )
232228
233229 # Start time
234- start_time_file_path = os .path .join (output , '.auto-sklearn' ,
230+ start_time_file_path = os .path .join (backend_api . temporary_directory , '.auto-sklearn' ,
235231 "start_time_100" )
236232 with open (start_time_file_path , 'r' ) as fh :
237233 start_time = float (fh .read ())
238234 self .assertGreaterEqual (time .time () - start_time , 10 )
239235
240236 del auto
241- self ._tearDown (output )
237+ self ._tearDown (backend_api .temporary_directory )
238+ self ._tearDown (backend_api .output_directory )
242239
243240 def test_do_dummy_prediction (self ):
244241 for name in ['401_bac' , '31_bac' , 'adult' , 'cadata' ]:
245- output = os .path .join (self .test_dir , '..' ,
246- '.tmp_test_do_dummy_prediction' )
247- self ._setUp (output )
242+ backend_api = self ._create_backend ('test_do_dummy_prediction' )
248243
249244 dataset = os .path .join (self .test_dir , '..' , '.data' , name )
250245
251- backend_api = backend .create (output , output )
252246 auto = autosklearn .automl .AutoML (
253247 backend_api , 20 , 5 ,
254248 initial_configurations_via_metalearning = 25 )
@@ -260,14 +254,17 @@ def test_do_dummy_prediction(self):
260254 auto ._do_dummy_prediction (D , 1 )
261255
262256 # Ensure that the dummy predictions are not in the current working
263- # directory, but in the output directory (under output)
257+ # directory, but in the temporary directory.
264258 self .assertFalse (os .path .exists (os .path .join (os .getcwd (),
265259 '.auto-sklearn' )))
266260 self .assertTrue (os .path .exists (os .path .join (
267- output , '.auto-sklearn' , 'predictions_ensemble' ,
261+ backend_api . temporary_directory , '.auto-sklearn' , 'predictions_ensemble' ,
268262 'predictions_ensemble_1_1.npy' )))
269263
270264 del auto
271- self ._tearDown (output )
265+ self ._tearDown (backend_api .temporary_directory )
266+ self ._tearDown (backend_api .output_directory )
272267
273268
269+ if __name__ == "__main__" :
270+ unittest .main ()
0 commit comments