Skip to content

Commit 880c247

Browse files
committed
doc: modified more test files
1 parent 8d41688 commit 880c247

File tree

4 files changed

+62
-65
lines changed

4 files changed

+62
-65
lines changed

tests/test_plotter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
import os
23+
from pathlib import Path
2424

2525
import pytest
2626

@@ -42,8 +42,8 @@
4242

4343

4444
def remove_picture(picture):
45-
if os.path.exists(os.path.join(os.getcwd(), picture)):
46-
os.remove(os.path.join(os.getcwd(), picture))
45+
if Path.cwd().joinpath(picture).exists():
46+
Path.cwd().joinpath(picture).unlink()
4747

4848

4949
@pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista")
@@ -53,7 +53,7 @@ def test_plotter_on_model(plate_msup):
5353
picture = "model_plot.png"
5454
remove_picture(picture)
5555
model.plot(off_screen=True, screenshot=picture)
56-
assert os.path.exists(os.path.join(os.getcwd(), picture))
56+
assert Path.cwd().joinpath(picture).exists()
5757
remove_picture(picture)
5858

5959

@@ -155,7 +155,7 @@ def test_plot_fieldscontainer_on_mesh(allkindofcomplexity):
155155
picture = "mesh_plot.png"
156156
remove_picture(picture)
157157
mesh.plot(fc, off_screen=True, screenshot=picture)
158-
assert os.path.exists(os.path.join(os.getcwd(), picture))
158+
assert Path.cwd().joinpath(picture).exists()
159159
remove_picture(picture)
160160

161161

@@ -193,7 +193,7 @@ def test_field_nodal_plot(allkindofcomplexity):
193193
picture = "field_plot.png"
194194
remove_picture(picture)
195195
f.plot(off_screen=True, screenshot=picture)
196-
assert os.path.exists(os.path.join(os.getcwd(), picture))
196+
assert Path.cwd().joinpath(picture).exists()
197197
remove_picture(picture)
198198

199199

@@ -372,7 +372,7 @@ def test_plot_meshes_container_1(multishells):
372372
picture = "meshes_cont_plot.png"
373373
remove_picture(picture)
374374
meshes_cont.plot(disp_fc, off_screen=True, screenshot=picture)
375-
assert os.path.exists(os.path.join(os.getcwd(), picture))
375+
assert Path.cwd().joinpath(picture).exists()
376376
remove_picture(picture)
377377

378378

@@ -656,7 +656,7 @@ def test_plot_chart(allkindofcomplexity):
656656
picture = "plot_chart.png"
657657
remove_picture(picture)
658658
plot_chart(new_fields_container, off_screen=True, screenshot=picture)
659-
assert os.path.exists(os.path.join(os.getcwd(), picture))
659+
assert Path.cwd().joinpath(picture).exists()
660660
remove_picture(picture)
661661

662662

tests/test_plugins.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
import os.path
23+
from pathlib import Path
2424

2525
import pytest
2626

@@ -124,7 +124,7 @@ def test_vtk(server_type, tmpdir):
124124
u = model.operator("U")
125125
op.inputs.fields1.connect(u)
126126
op.inputs.mesh.connect(model.metadata.mesh_provider)
127-
op.inputs.directory.connect(os.path.dirname(rst_file))
127+
op.inputs.directory.connect(str(Path(rst_file).parent))
128128
out_path = op.eval()
129129
# assert out_path.result_files is not []
130130
# try:

tests/test_python_plugins.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import pytest
2424
import os
25+
from pathlib import Path
2526
import platform
2627
import numpy as np
2728
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0
@@ -56,7 +57,7 @@
5657
@pytest.fixture(scope="module")
5758
def load_all_types_plugin(testfiles_dir):
5859
return dpf.load_library(
59-
dpf.path_utilities.to_server_os(os.path.join(testfiles_dir, "pythonPlugins", "all_types")),
60+
dpf.path_utilities.to_server_os(Path(testfiles_dir) / "pythonPlugins" / "all_types"),
6061
"py_test_types",
6162
"load_operators",
6263
)
@@ -65,7 +66,7 @@ def load_all_types_plugin(testfiles_dir):
6566
def load_all_types_plugin_with_serv(my_server, testfiles_dir):
6667
return dpf.load_library(
6768
dpf.path_utilities.to_server_os(
68-
os.path.join(testfiles_dir, "pythonPlugins", "all_types"), my_server
69+
Path(testfiles_dir) / "pythonPlugins" / "all_types", my_server
6970
),
7071
"py_test_types",
7172
"load_operators",
@@ -242,7 +243,7 @@ def test_generic_data_container(server_clayer_remote_process, testfiles_dir):
242243
def test_syntax_error(server_type_remote_process, testfiles_dir):
243244
dpf.load_library(
244245
dpf.path_utilities.to_server_os(
245-
os.path.join(testfiles_dir, "pythonPlugins", "syntax_error_plugin"),
246+
Path(testfiles_dir) / "pythonPlugins" / "syntax_error_plugin",
246247
server_type_remote_process,
247248
),
248249
"py_raising",
@@ -381,7 +382,7 @@ def test_create_properties_specification(server_in_process):
381382
def test_custom_op_with_spec(server_type_remote_process, testfiles_dir):
382383
dpf.load_library(
383384
dpf.path_utilities.to_server_os(
384-
os.path.join(testfiles_dir, "pythonPlugins"), server_type_remote_process
385+
Path(testfiles_dir) / "pythonPlugins", server_type_remote_process
385386
),
386387
"py_operator_with_spec",
387388
"load_operators",

tests/test_service.py

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222

2323
import os
24+
from pathlib import Path
2425

2526
import pytest
2627
import 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
)
7980
def 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")
127125
def 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")
152150
def 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):
243241
def 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/math/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

284280
def 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

Comments
 (0)