21
21
# SOFTWARE.
22
22
23
23
import os
24
+ from pathlib import Path
24
25
25
26
import pytest
26
27
import conftest
@@ -77,7 +78,7 @@ def test_loadplugin(server_type):
77
78
reason = "Random SEGFAULT in the GitHub pipeline for 3.7-8 on Windows" ,
78
79
)
79
80
def test_upload_download (tmpdir , server_type_remote_process ):
80
- tmpdir = str (tmpdir )
81
+ tmpdir = Path (tmpdir )
81
82
file = dpf .core .upload_file_in_tmp_folder (
82
83
examples .download_all_kinds_of_complexity (return_local_path = True ),
83
84
server = server_type_remote_process ,
@@ -91,17 +92,14 @@ def test_upload_download(tmpdir, server_type_remote_process):
91
92
fielddef = f .field_definition
92
93
assert fielddef .unit == "Pa"
93
94
94
- dir = os .path .dirname (file )
95
- vtk_path = os .path .join (dir , "file.vtk" )
95
+ vtk_path = Path (file ).parent / "file.vtk"
96
96
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
98
98
)
99
99
vtk .run ()
100
100
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 ()
105
103
106
104
107
105
@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
@@ -114,18 +112,18 @@ def test_download_folder(
114
112
)
115
113
file = dpf .core .upload_file_in_tmp_folder (plate_msup , server = server_type_remote_process )
116
114
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 )
118
116
dpf .core .download_files_in_folder (parent_path , tmpdir , server = server_type_remote_process )
119
117
import ntpath
120
118
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 ( )
124
122
125
123
126
124
@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
127
125
def test_download_with_subdir (multishells , tmpdir , server_type_remote_process ):
128
- tmpdir = str (tmpdir )
126
+ tmpdir = Path (tmpdir )
129
127
file = dpf .core .upload_file_in_tmp_folder (multishells , server = server_type_remote_process )
130
128
131
129
base = dpf .core .BaseService (server = server_type_remote_process )
@@ -134,56 +132,56 @@ def test_download_with_subdir(multishells, tmpdir, server_type_remote_process):
134
132
import ntpath
135
133
136
134
filename = ntpath .basename (file )
137
- parent_path = os . path . dirname ( file )
135
+ parent_path = str ( Path ( file ). parent )
138
136
to_server_path = parent_path + separator + "subdir" + separator + filename
139
137
subdir_filepath = dpf .core .upload_file (file , to_server_path , server = server_type_remote_process )
140
138
folder = parent_path
141
139
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
145
143
# p1 = tmpdir + "/" + filename
146
144
# p2 = tmpdir + "/subdir/" + filename
147
- assert os . path . exists (p1 )
148
- assert os . path . exists (p2 )
145
+ assert p1 . exists ()
146
+ assert p2 . exists ()
149
147
150
148
151
149
@pytest .mark .skipif (running_docker , reason = "Path hidden within docker container" )
152
150
def test_downloadinfolder_uploadinfolder (multishells , tmpdir , server_type_remote_process ):
153
- tmpdir = str (tmpdir )
151
+ tmpdir = Path (tmpdir )
154
152
base = dpf .core .BaseService (server = server_type_remote_process )
155
153
# 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
159
157
from shutil import copyfile
160
158
161
159
copyfile (multishells , path1 )
162
- os . mkdir ( os . path . join ( tmpdir , "subdirA" ))
160
+ tmpdir . joinpath ( "subdirA" ). mkdir ( )
163
161
copyfile (multishells , path2 )
164
- os . mkdir ( os . path . join ( tmpdir , "subdirB" ))
162
+ tmpdir . joinpath ( "subdirB" ). mkdir ( )
165
163
copyfile (multishells , path4 )
166
164
# upload it
167
165
TARGET_PATH = base .make_tmp_dir_server ()
168
166
dpf .core .upload_files_in_folder (
169
167
to_server_folder_path = TARGET_PATH ,
170
- client_folder_path = tmpdir ,
168
+ client_folder_path = str ( tmpdir ) ,
171
169
specific_extension = "rst" ,
172
170
server = server_type_remote_process ,
173
171
)
174
172
# 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 ()
177
175
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
179
177
)
180
178
# 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 ()
187
185
# clean
188
186
# os.remove(os.path.join(tmpdir, "tmpdir"))
189
187
# os.remove(os.path.join(tmpdir, "subdirA"))
@@ -243,18 +241,18 @@ def test_uploadinfolder_emptyfolder(tmpdir, server_type_remote_process):
243
241
def test_load_plugin_correctly (server_type ):
244
242
from ansys .dpf import core as dpf
245
243
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
247
245
248
246
base = dpf .BaseService (server = server_type )
249
247
if server_type .os == "nt" :
250
248
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
252
250
assert datetime .datetime .fromtimestamp (t ).date () == datetime .datetime .today ().date ()
253
251
else :
254
252
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/math/ fft_eval.py" ). exists ( )
256
254
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 ( ))
258
256
assert num_lines >= 11
259
257
260
258
@@ -267,18 +265,16 @@ def test_load_plugin_correctly_remote():
267
265
server .external_ip , server .external_port , as_global = False
268
266
)
269
267
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
271
269
272
270
if server .os == "posix" :
273
271
dpf .load_library ("libAns.Dpf.Math.so" , "math_operators" , server = server_connected )
274
272
else :
275
273
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
277
275
assert datetime .datetime .fromtimestamp (t ).date () == datetime .datetime .today ().date ()
278
276
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 ()
282
278
283
279
284
280
def test_dpf_join (server_type ):
@@ -320,7 +316,7 @@ def test_load_api_without_awp_root(restore_awp_root):
320
316
321
317
assert serv ._client_api_path is not None
322
318
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" )
324
320
assert dpf_inner_path in serv ._client_api_path
325
321
assert dpf_inner_path in serv ._grpc_client_path
326
322
@@ -339,7 +335,7 @@ def test_load_api_with_awp_root():
339
335
340
336
assert serv_2 ._client_api_path is not None
341
337
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" )
343
339
assert dpf_inner_path in serv_2 ._client_api_path
344
340
assert dpf_inner_path in serv_2 ._grpc_client_path
345
341
@@ -366,7 +362,7 @@ def test_load_api_with_awp_root_2():
366
362
367
363
assert serv ._client_api_path is not None
368
364
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" )
370
366
assert dpf_inner_path in serv ._client_api_path
371
367
assert dpf_inner_path in serv ._grpc_client_path
372
368
@@ -421,9 +417,9 @@ def test_load_api_with_awp_root_no_gatebin():
421
417
assert serv_2 ._grpc_client_path is not None
422
418
ISPOSIX = os .name == "posix"
423
419
if not ISPOSIX :
424
- dpf_inner_path = os . path . join ( "aisol" , "bin" , "winx64" )
420
+ dpf_inner_path = str ( Path ( "aisol" ) / "bin" / "winx64" )
425
421
else :
426
- dpf_inner_path = os . path . join ( "aisol" , "dll" , "linx64" )
422
+ dpf_inner_path = str ( Path ( "aisol" ) / "dll" / "linx64" )
427
423
assert dpf_inner_path in serv_2 ._client_api_path
428
424
assert dpf_inner_path in serv_2 ._grpc_client_path
429
425
@@ -449,9 +445,9 @@ def test_load_api_with_awp_root_2_no_gatebin():
449
445
assert serv ._grpc_client_path is not None
450
446
ISPOSIX = os .name == "posix"
451
447
if not ISPOSIX :
452
- dpf_inner_path = os . path . join ( "aisol" , "bin" , "winx64" )
448
+ dpf_inner_path = str ( Path ( "aisol" ) / "bin" / "winx64" )
453
449
else :
454
- dpf_inner_path = os . path . join ( "aisol" , "dll" , "linx64" )
450
+ dpf_inner_path = str ( Path ( "aisol" ) / "dll" / "linx64" )
455
451
assert dpf_inner_path in serv ._client_api_path
456
452
assert dpf_inner_path in serv ._grpc_client_path
457
453
0 commit comments