2121# SOFTWARE.
2222
2323import os
24+ from pathlib import Path
2425
2526import pytest
2627import conftest
@@ -77,7 +78,7 @@ def test_loadplugin(server_type):
7778 reason = "Random SEGFAULT in the GitHub pipeline for 3.7-8 on Windows" ,
7879)
7980def test_upload_download (tmpdir , server_type_remote_process ):
80- tmpdir = str (tmpdir )
81+ tmpdir = Path (tmpdir )
8182 file = dpf .core .upload_file_in_tmp_folder (
8283 examples .download_all_kinds_of_complexity (return_local_path = True ),
8384 server = server_type_remote_process ,
@@ -91,17 +92,14 @@ def test_upload_download(tmpdir, server_type_remote_process):
9192 fielddef = f .field_definition
9293 assert fielddef .unit == "Pa"
9394
94- dir = os .path .dirname (file )
95- vtk_path = os .path .join (dir , "file.vtk" )
95+ vtk_path = Path (file ).parent / "file.vtk"
9696 vtk = dpf .core .operators .serialization .vtk_export (
97- file_path = vtk_path , fields1 = fcOut , server = server_type_remote_process
97+ file_path = str ( vtk_path ) , fields1 = fcOut , server = server_type_remote_process
9898 )
9999 vtk .run ()
100100
101- dpf .core .download_file (
102- vtk_path , os .path .join (tmpdir , "file.vtk" ), server = server_type_remote_process
103- )
104- assert os .path .exists (os .path .join (tmpdir , "file.vtk" ))
101+ dpf .core .download_file (vtk_path , str (tmpdir / "file.vtk" ), server = server_type_remote_process )
102+ assert tmpdir .joinpath ("file.vtk" ).exists ()
105103
106104
107105@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
@@ -114,18 +112,18 @@ def test_download_folder(
114112 )
115113 file = dpf .core .upload_file_in_tmp_folder (plate_msup , server = server_type_remote_process )
116114 file = dpf .core .upload_file_in_tmp_folder (multishells , server = server_type_remote_process )
117- parent_path = os . path . dirname ( file )
115+ parent_path = str ( Path ( file ). parent )
118116 dpf .core .download_files_in_folder (parent_path , tmpdir , server = server_type_remote_process )
119117 import ntpath
120118
121- assert os . path . exists ( os . path . join ( tmpdir , ntpath .basename (allkindofcomplexity )))
122- assert os . path . exists ( os . path . join ( tmpdir , ntpath .basename (plate_msup )))
123- assert os . path . exists ( os . path . join ( tmpdir , ntpath .basename (multishells )))
119+ assert Path ( tmpdir ). joinpath ( ntpath .basename (allkindofcomplexity )). exists ( )
120+ assert Path ( tmpdir ). joinpath ( ntpath .basename (plate_msup )). exists ( )
121+ assert Path ( tmpdir ). joinpath ( ntpath .basename (multishells )). exists ( )
124122
125123
126124@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
127125def test_download_with_subdir (multishells , tmpdir , server_type_remote_process ):
128- tmpdir = str (tmpdir )
126+ tmpdir = Path (tmpdir )
129127 file = dpf .core .upload_file_in_tmp_folder (multishells , server = server_type_remote_process )
130128
131129 base = dpf .core .BaseService (server = server_type_remote_process )
@@ -134,56 +132,56 @@ def test_download_with_subdir(multishells, tmpdir, server_type_remote_process):
134132 import ntpath
135133
136134 filename = ntpath .basename (file )
137- parent_path = os . path . dirname ( file )
135+ parent_path = str ( Path ( file ). parent )
138136 to_server_path = parent_path + separator + "subdir" + separator + filename
139137 subdir_filepath = dpf .core .upload_file (file , to_server_path , server = server_type_remote_process )
140138 folder = parent_path
141139
142- out = dpf .core .download_files_in_folder (folder , tmpdir , server = server_type_remote_process )
143- p1 = os . path . join ( tmpdir , filename )
144- p2 = os . path . join ( tmpdir , "subdir" , filename )
140+ out = dpf .core .download_files_in_folder (folder , str ( tmpdir ) , server = server_type_remote_process )
141+ p1 = tmpdir / filename
142+ p2 = tmpdir / "subdir" / filename
145143 # p1 = tmpdir + "/" + filename
146144 # p2 = tmpdir + "/subdir/" + filename
147- assert os . path . exists (p1 )
148- assert os . path . exists (p2 )
145+ assert p1 . exists ()
146+ assert p2 . exists ()
149147
150148
151149@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
152150def test_downloadinfolder_uploadinfolder (multishells , tmpdir , server_type_remote_process ):
153- tmpdir = str (tmpdir )
151+ tmpdir = Path (tmpdir )
154152 base = dpf .core .BaseService (server = server_type_remote_process )
155153 # create in tmpdir some architecture with subfolder in subfolder
156- path1 = os . path . join ( tmpdir , os . path . basename (multishells ))
157- path2 = os . path . join ( tmpdir , "subdirA" , os . path . basename (multishells ))
158- path4 = os . path . join ( tmpdir , "subdirB" , os . path . basename (multishells ))
154+ path1 = tmpdir / Path (multishells ). name
155+ path2 = tmpdir / "subdirA" / Path (multishells ). name
156+ path4 = tmpdir / "subdirB" / Path (multishells ). name
159157 from shutil import copyfile
160158
161159 copyfile (multishells , path1 )
162- os . mkdir ( os . path . join ( tmpdir , "subdirA" ))
160+ tmpdir . joinpath ( "subdirA" ). mkdir ( )
163161 copyfile (multishells , path2 )
164- os . mkdir ( os . path . join ( tmpdir , "subdirB" ))
162+ tmpdir . joinpath ( "subdirB" ). mkdir ( )
165163 copyfile (multishells , path4 )
166164 # upload it
167165 TARGET_PATH = base .make_tmp_dir_server ()
168166 dpf .core .upload_files_in_folder (
169167 to_server_folder_path = TARGET_PATH ,
170- client_folder_path = tmpdir ,
168+ client_folder_path = str ( tmpdir ) ,
171169 specific_extension = "rst" ,
172170 server = server_type_remote_process ,
173171 )
174172 # download it
175- new_tmpdir = os . path . join ( tmpdir , "my_tmp_dir" )
176- os .mkdir (new_tmpdir )
173+ new_tmpdir = tmpdir / "my_tmp_dir"
174+ new_tmpdir .mkdir ()
177175 out = dpf .core .download_files_in_folder (
178- TARGET_PATH , new_tmpdir , server = server_type_remote_process
176+ TARGET_PATH , str ( new_tmpdir ) , server = server_type_remote_process
179177 )
180178 # check if the architecture of the download is ok
181- path1_check = os . path . join ( new_tmpdir , os . path . basename (multishells ))
182- path2_check = os . path . join ( new_tmpdir , "subdirA" , os . path . basename (multishells ))
183- path4_check = os . path . join ( new_tmpdir , "subdirB" , os . path . basename (multishells ))
184- assert os . path . exists (path1_check )
185- assert os . path . exists (path2_check )
186- assert os . path . exists (path4_check )
179+ path1_check = new_tmpdir / Path (multishells ). name
180+ path2_check = new_tmpdir / "subdirA" / Path (multishells ). name
181+ path4_check = new_tmpdir / "subdirB" / Path (multishells ). name
182+ assert path1_check . exists ()
183+ assert path2_check . exists ()
184+ assert path4_check . exists ()
187185 # clean
188186 # os.remove(os.path.join(tmpdir, "tmpdir"))
189187 # os.remove(os.path.join(tmpdir, "subdirA"))
@@ -243,18 +241,18 @@ def test_uploadinfolder_emptyfolder(tmpdir, server_type_remote_process):
243241def test_load_plugin_correctly (server_type ):
244242 from ansys .dpf import core as dpf
245243
246- actual_path = os . path . dirname (pkgutil .get_loader ("ansys.dpf.core" ).path )
244+ actual_path = Path (pkgutil .get_loader ("ansys.dpf.core" ).path ). parent
247245
248246 base = dpf .BaseService (server = server_type )
249247 if server_type .os == "nt" :
250248 base .load_library ("Ans.Dpf.Math.dll" , "math_operators" , generate_operators = True )
251- t = os . path . getmtime ( os . path . join ( actual_path , r "operators/math/fft_eval.py" ))
249+ t = actual_path . joinpath ( "operators/math/fft_eval.py" ). stat (). st_mtime
252250 assert datetime .datetime .fromtimestamp (t ).date () == datetime .datetime .today ().date ()
253251 else :
254252 base .load_library ("libAns.Dpf.Math.so" , "math_operators" )
255- exists = os . path . exists ( os . path . join ( actual_path , r "operators/fft_eval.py" ))
253+ exists = actual_path . joinpath ( "operators/fft_eval.py" ). exists ( )
256254 assert not exists
257- num_lines = sum (1 for line in open ( os . path . join ( actual_path , r "operators/math/__init__.py" )))
255+ num_lines = sum (1 for line in actual_path . joinpath ( "operators/math/__init__.py" ). open ( ))
258256 assert num_lines >= 11
259257
260258
@@ -267,18 +265,16 @@ def test_load_plugin_correctly_remote():
267265 server .external_ip , server .external_port , as_global = False
268266 )
269267
270- actual_path = os . path . dirname (pkgutil .get_loader ("ansys.dpf.core" ).path )
268+ actual_path = Path (pkgutil .get_loader ("ansys.dpf.core" ).path ). parent
271269
272270 if server .os == "posix" :
273271 dpf .load_library ("libAns.Dpf.Math.so" , "math_operators" , server = server_connected )
274272 else :
275273 dpf .load_library ("Ans.Dpf.Math.dll" , "math_operators" , server = server_connected )
276- t = os . path . getmtime ( os . path . join ( actual_path , r "operators/math/fft_eval.py" ))
274+ t = actual_path . joinpath ( "operators/math/fft_eval.py" ). stat (). st_mtime
277275 assert datetime .datetime .fromtimestamp (t ).date () == datetime .datetime .today ().date ()
278276
279- actual_path = os .path .dirname (pkgutil .get_loader ("ansys.dpf.core" ).path )
280-
281- assert os .path .exists (os .path .join (actual_path , r"operators/math/fft_eval.py" ))
277+ assert actual_path .joinpath ("operators/math/fft_eval.py" ).exists ()
282278
283279
284280def test_dpf_join (server_type ):
@@ -320,7 +316,7 @@ def test_load_api_without_awp_root(restore_awp_root):
320316
321317 assert serv ._client_api_path is not None
322318 assert serv ._grpc_client_path is not None
323- dpf_inner_path = os . path . join ( "ansys" , "dpf" , "gatebin" )
319+ dpf_inner_path = str ( Path ( "ansys" ) / "dpf" / "gatebin" )
324320 assert dpf_inner_path in serv ._client_api_path
325321 assert dpf_inner_path in serv ._grpc_client_path
326322
@@ -339,7 +335,7 @@ def test_load_api_with_awp_root():
339335
340336 assert serv_2 ._client_api_path is not None
341337 assert serv_2 ._grpc_client_path is not None
342- dpf_inner_path = os . path . join ( "ansys" , "dpf" , "gatebin" )
338+ dpf_inner_path = str ( Path ( "ansys" ) / "dpf" / "gatebin" )
343339 assert dpf_inner_path in serv_2 ._client_api_path
344340 assert dpf_inner_path in serv_2 ._grpc_client_path
345341
@@ -366,7 +362,7 @@ def test_load_api_with_awp_root_2():
366362
367363 assert serv ._client_api_path is not None
368364 assert serv ._grpc_client_path is not None
369- dpf_inner_path = os . path . join ( "ansys" , "dpf" , "gatebin" )
365+ dpf_inner_path = str ( Path ( "ansys" ) / "dpf" / "gatebin" )
370366 assert dpf_inner_path in serv ._client_api_path
371367 assert dpf_inner_path in serv ._grpc_client_path
372368
@@ -421,9 +417,9 @@ def test_load_api_with_awp_root_no_gatebin():
421417 assert serv_2 ._grpc_client_path is not None
422418 ISPOSIX = os .name == "posix"
423419 if not ISPOSIX :
424- dpf_inner_path = os . path . join ( "aisol" , "bin" , "winx64" )
420+ dpf_inner_path = str ( Path ( "aisol" ) / "bin" / "winx64" )
425421 else :
426- dpf_inner_path = os . path . join ( "aisol" , "dll" , "linx64" )
422+ dpf_inner_path = str ( Path ( "aisol" ) / "dll" / "linx64" )
427423 assert dpf_inner_path in serv_2 ._client_api_path
428424 assert dpf_inner_path in serv_2 ._grpc_client_path
429425
@@ -449,9 +445,9 @@ def test_load_api_with_awp_root_2_no_gatebin():
449445 assert serv ._grpc_client_path is not None
450446 ISPOSIX = os .name == "posix"
451447 if not ISPOSIX :
452- dpf_inner_path = os . path . join ( "aisol" , "bin" , "winx64" )
448+ dpf_inner_path = str ( Path ( "aisol" ) / "bin" / "winx64" )
453449 else :
454- dpf_inner_path = os . path . join ( "aisol" , "dll" , "linx64" )
450+ dpf_inner_path = str ( Path ( "aisol" ) / "dll" / "linx64" )
455451 assert dpf_inner_path in serv ._client_api_path
456452 assert dpf_inner_path in serv ._grpc_client_path
457453
0 commit comments