@@ -295,27 +295,39 @@ def test_license_type_dummy(mapdl, cleared):
295
295
)
296
296
297
297
298
- @requires ("local" )
299
- @requires ("nostudent" )
300
- def test_remove_temp_dir_on_exit (mapdl , cleared ):
298
+ @patch ("ansys.mapdl.core.Mapdl._exit_mapdl" , lambda * args , ** kwargs : None )
299
+ def test_remove_temp_dir_on_exit (mapdl , cleared , tmpdir ):
301
300
"""Ensure the working directory is removed when run_location is not set."""
302
- mapdl_ = launch_mapdl (
303
- port = mapdl .port + 1 ,
304
- remove_temp_dir_on_exit = True ,
305
- start_timeout = start_timeout ,
306
- additional_switches = QUICK_LAUNCH_SWITCHES ,
307
- )
308
301
309
- # possible MAPDL is installed but running in "remote" mode
310
- path = mapdl_ .directory
311
- mapdl_ .exit ()
302
+ with (
303
+ patch .object (mapdl , "finish_job_on_exit" , False ),
304
+ patch .object (mapdl , "_local" , True ),
305
+ patch .object (mapdl , "remove_temp_dir_on_exit" , True ),
306
+ ):
312
307
313
- tmp_dir = tempfile .gettempdir ()
314
- ans_temp_dir = os .path .join (tmp_dir , "ansys_" )
315
- if path .startswith (ans_temp_dir ):
316
- assert not os .path .isdir (path )
317
- else :
318
- assert os .path .isdir (path )
308
+ # Testing reaching the method
309
+ with patch .object (mapdl , "_remove_temp_dir_on_exit" ) as mock_rm :
310
+ mock_rm .side_effect = None
311
+
312
+ mapdl .exit (force = True )
313
+
314
+ mock_rm .assert_called ()
315
+ assert mapdl .directory == mock_rm .call_args .args [0 ]
316
+
317
+ # Testing the method
318
+ # Directory to be deleted
319
+ ans_temp_dir = os .path .join (tempfile .gettempdir (), "ansys_" )
320
+
321
+ os .makedirs (ans_temp_dir , exist_ok = True )
322
+ assert os .path .isdir (ans_temp_dir )
323
+ mapdl ._remove_temp_dir_on_exit (ans_temp_dir )
324
+ assert not os .path .isdir (ans_temp_dir )
325
+
326
+ # Directory to NOT be deleted
327
+ tmp_dir = str (tmpdir )
328
+ assert os .path .isdir (tmp_dir )
329
+ mapdl ._remove_temp_dir_on_exit (tmp_dir )
330
+ assert os .path .isdir (tmp_dir )
319
331
320
332
321
333
@requires ("local" )
0 commit comments