Skip to content

Commit

Permalink
doc: modified more test files
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 10, 2024
1 parent 8d41688 commit 880c247
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 65 deletions.
16 changes: 8 additions & 8 deletions tests/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os
from pathlib import Path

import pytest

Expand All @@ -42,8 +42,8 @@


def remove_picture(picture):
if os.path.exists(os.path.join(os.getcwd(), picture)):
os.remove(os.path.join(os.getcwd(), picture))
if Path.cwd().joinpath(picture).exists():
Path.cwd().joinpath(picture).unlink()


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


Expand Down Expand Up @@ -155,7 +155,7 @@ def test_plot_fieldscontainer_on_mesh(allkindofcomplexity):
picture = "mesh_plot.png"
remove_picture(picture)
mesh.plot(fc, off_screen=True, screenshot=picture)
assert os.path.exists(os.path.join(os.getcwd(), picture))
assert Path.cwd().joinpath(picture).exists()
remove_picture(picture)


Expand Down Expand Up @@ -193,7 +193,7 @@ def test_field_nodal_plot(allkindofcomplexity):
picture = "field_plot.png"
remove_picture(picture)
f.plot(off_screen=True, screenshot=picture)
assert os.path.exists(os.path.join(os.getcwd(), picture))
assert Path.cwd().joinpath(picture).exists()
remove_picture(picture)


Expand Down Expand Up @@ -372,7 +372,7 @@ def test_plot_meshes_container_1(multishells):
picture = "meshes_cont_plot.png"
remove_picture(picture)
meshes_cont.plot(disp_fc, off_screen=True, screenshot=picture)
assert os.path.exists(os.path.join(os.getcwd(), picture))
assert Path.cwd().joinpath(picture).exists()
remove_picture(picture)


Expand Down Expand Up @@ -656,7 +656,7 @@ def test_plot_chart(allkindofcomplexity):
picture = "plot_chart.png"
remove_picture(picture)
plot_chart(new_fields_container, off_screen=True, screenshot=picture)
assert os.path.exists(os.path.join(os.getcwd(), picture))
assert Path.cwd().joinpath(picture).exists()
remove_picture(picture)


Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import os.path
from pathlib import Path

import pytest

Expand Down Expand Up @@ -124,7 +124,7 @@ def test_vtk(server_type, tmpdir):
u = model.operator("U")
op.inputs.fields1.connect(u)
op.inputs.mesh.connect(model.metadata.mesh_provider)
op.inputs.directory.connect(os.path.dirname(rst_file))
op.inputs.directory.connect(str(Path(rst_file).parent))
out_path = op.eval()
# assert out_path.result_files is not []
# try:
Expand Down
9 changes: 5 additions & 4 deletions tests/test_python_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import pytest
import os
from pathlib import Path
import platform
import numpy as np
from conftest import SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_4_0
Expand Down Expand Up @@ -56,7 +57,7 @@
@pytest.fixture(scope="module")
def load_all_types_plugin(testfiles_dir):
return dpf.load_library(
dpf.path_utilities.to_server_os(os.path.join(testfiles_dir, "pythonPlugins", "all_types")),
dpf.path_utilities.to_server_os(Path(testfiles_dir) / "pythonPlugins" / "all_types"),
"py_test_types",
"load_operators",
)
Expand All @@ -65,7 +66,7 @@ def load_all_types_plugin(testfiles_dir):
def load_all_types_plugin_with_serv(my_server, testfiles_dir):
return dpf.load_library(
dpf.path_utilities.to_server_os(
os.path.join(testfiles_dir, "pythonPlugins", "all_types"), my_server
Path(testfiles_dir) / "pythonPlugins" / "all_types", my_server
),
"py_test_types",
"load_operators",
Expand Down Expand Up @@ -242,7 +243,7 @@ def test_generic_data_container(server_clayer_remote_process, testfiles_dir):
def test_syntax_error(server_type_remote_process, testfiles_dir):
dpf.load_library(
dpf.path_utilities.to_server_os(
os.path.join(testfiles_dir, "pythonPlugins", "syntax_error_plugin"),
Path(testfiles_dir) / "pythonPlugins" / "syntax_error_plugin",
server_type_remote_process,
),
"py_raising",
Expand Down Expand Up @@ -381,7 +382,7 @@ def test_create_properties_specification(server_in_process):
def test_custom_op_with_spec(server_type_remote_process, testfiles_dir):
dpf.load_library(
dpf.path_utilities.to_server_os(
os.path.join(testfiles_dir, "pythonPlugins"), server_type_remote_process
Path(testfiles_dir) / "pythonPlugins", server_type_remote_process
),
"py_operator_with_spec",
"load_operators",
Expand Down
98 changes: 47 additions & 51 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# SOFTWARE.

import os
from pathlib import Path

import pytest
import conftest
Expand Down Expand Up @@ -77,7 +78,7 @@ def test_loadplugin(server_type):
reason="Random SEGFAULT in the GitHub pipeline for 3.7-8 on Windows",
)
def test_upload_download(tmpdir, server_type_remote_process):
tmpdir = str(tmpdir)
tmpdir = Path(tmpdir)
file = dpf.core.upload_file_in_tmp_folder(
examples.download_all_kinds_of_complexity(return_local_path=True),
server=server_type_remote_process,
Expand All @@ -91,17 +92,14 @@ def test_upload_download(tmpdir, server_type_remote_process):
fielddef = f.field_definition
assert fielddef.unit == "Pa"

dir = os.path.dirname(file)
vtk_path = os.path.join(dir, "file.vtk")
vtk_path = Path(file).parent / "file.vtk"
vtk = dpf.core.operators.serialization.vtk_export(
file_path=vtk_path, fields1=fcOut, server=server_type_remote_process
file_path=str(vtk_path), fields1=fcOut, server=server_type_remote_process
)
vtk.run()

dpf.core.download_file(
vtk_path, os.path.join(tmpdir, "file.vtk"), server=server_type_remote_process
)
assert os.path.exists(os.path.join(tmpdir, "file.vtk"))
dpf.core.download_file(vtk_path, str(tmpdir / "file.vtk"), server=server_type_remote_process)
assert tmpdir.joinpath("file.vtk").exists()


@pytest.mark.skipif(running_docker, reason="Path hidden within docker container")
Expand All @@ -114,18 +112,18 @@ def test_download_folder(
)
file = dpf.core.upload_file_in_tmp_folder(plate_msup, server=server_type_remote_process)
file = dpf.core.upload_file_in_tmp_folder(multishells, server=server_type_remote_process)
parent_path = os.path.dirname(file)
parent_path = str(Path(file).parent)
dpf.core.download_files_in_folder(parent_path, tmpdir, server=server_type_remote_process)
import ntpath

assert os.path.exists(os.path.join(tmpdir, ntpath.basename(allkindofcomplexity)))
assert os.path.exists(os.path.join(tmpdir, ntpath.basename(plate_msup)))
assert os.path.exists(os.path.join(tmpdir, ntpath.basename(multishells)))
assert Path(tmpdir).joinpath(ntpath.basename(allkindofcomplexity)).exists()
assert Path(tmpdir).joinpath(ntpath.basename(plate_msup)).exists()
assert Path(tmpdir).joinpath(ntpath.basename(multishells)).exists()


@pytest.mark.skipif(running_docker, reason="Path hidden within docker container")
def test_download_with_subdir(multishells, tmpdir, server_type_remote_process):
tmpdir = str(tmpdir)
tmpdir = Path(tmpdir)
file = dpf.core.upload_file_in_tmp_folder(multishells, server=server_type_remote_process)

base = dpf.core.BaseService(server=server_type_remote_process)
Expand All @@ -134,56 +132,56 @@ def test_download_with_subdir(multishells, tmpdir, server_type_remote_process):
import ntpath

filename = ntpath.basename(file)
parent_path = os.path.dirname(file)
parent_path = str(Path(file).parent)
to_server_path = parent_path + separator + "subdir" + separator + filename
subdir_filepath = dpf.core.upload_file(file, to_server_path, server=server_type_remote_process)
folder = parent_path

out = dpf.core.download_files_in_folder(folder, tmpdir, server=server_type_remote_process)
p1 = os.path.join(tmpdir, filename)
p2 = os.path.join(tmpdir, "subdir", filename)
out = dpf.core.download_files_in_folder(folder, str(tmpdir), server=server_type_remote_process)
p1 = tmpdir / filename
p2 = tmpdir / "subdir" / filename
# p1 = tmpdir + "/" + filename
# p2 = tmpdir + "/subdir/" + filename
assert os.path.exists(p1)
assert os.path.exists(p2)
assert p1.exists()
assert p2.exists()


@pytest.mark.skipif(running_docker, reason="Path hidden within docker container")
def test_downloadinfolder_uploadinfolder(multishells, tmpdir, server_type_remote_process):
tmpdir = str(tmpdir)
tmpdir = Path(tmpdir)
base = dpf.core.BaseService(server=server_type_remote_process)
# create in tmpdir some architecture with subfolder in subfolder
path1 = os.path.join(tmpdir, os.path.basename(multishells))
path2 = os.path.join(tmpdir, "subdirA", os.path.basename(multishells))
path4 = os.path.join(tmpdir, "subdirB", os.path.basename(multishells))
path1 = tmpdir / Path(multishells).name
path2 = tmpdir / "subdirA" / Path(multishells).name
path4 = tmpdir / "subdirB" / Path(multishells).name
from shutil import copyfile

copyfile(multishells, path1)
os.mkdir(os.path.join(tmpdir, "subdirA"))
tmpdir.joinpath("subdirA").mkdir()
copyfile(multishells, path2)
os.mkdir(os.path.join(tmpdir, "subdirB"))
tmpdir.joinpath("subdirB").mkdir()
copyfile(multishells, path4)
# upload it
TARGET_PATH = base.make_tmp_dir_server()
dpf.core.upload_files_in_folder(
to_server_folder_path=TARGET_PATH,
client_folder_path=tmpdir,
client_folder_path=str(tmpdir),
specific_extension="rst",
server=server_type_remote_process,
)
# download it
new_tmpdir = os.path.join(tmpdir, "my_tmp_dir")
os.mkdir(new_tmpdir)
new_tmpdir = tmpdir / "my_tmp_dir"
new_tmpdir.mkdir()
out = dpf.core.download_files_in_folder(
TARGET_PATH, new_tmpdir, server=server_type_remote_process
TARGET_PATH, str(new_tmpdir), server=server_type_remote_process
)
# check if the architecture of the download is ok
path1_check = os.path.join(new_tmpdir, os.path.basename(multishells))
path2_check = os.path.join(new_tmpdir, "subdirA", os.path.basename(multishells))
path4_check = os.path.join(new_tmpdir, "subdirB", os.path.basename(multishells))
assert os.path.exists(path1_check)
assert os.path.exists(path2_check)
assert os.path.exists(path4_check)
path1_check = new_tmpdir / Path(multishells).name
path2_check = new_tmpdir / "subdirA" / Path(multishells).name
path4_check = new_tmpdir / "subdirB" / Path(multishells).name
assert path1_check.exists()
assert path2_check.exists()
assert path4_check.exists()
# clean
# os.remove(os.path.join(tmpdir, "tmpdir"))
# os.remove(os.path.join(tmpdir, "subdirA"))
Expand Down Expand Up @@ -243,18 +241,18 @@ def test_uploadinfolder_emptyfolder(tmpdir, server_type_remote_process):
def test_load_plugin_correctly(server_type):
from ansys.dpf import core as dpf

actual_path = os.path.dirname(pkgutil.get_loader("ansys.dpf.core").path)
actual_path = Path(pkgutil.get_loader("ansys.dpf.core").path).parent

base = dpf.BaseService(server=server_type)
if server_type.os == "nt":
base.load_library("Ans.Dpf.Math.dll", "math_operators", generate_operators=True)
t = os.path.getmtime(os.path.join(actual_path, r"operators/math/fft_eval.py"))
t = actual_path.joinpath("operators/math/fft_eval.py").stat().st_mtime
assert datetime.datetime.fromtimestamp(t).date() == datetime.datetime.today().date()
else:
base.load_library("libAns.Dpf.Math.so", "math_operators")
exists = os.path.exists(os.path.join(actual_path, r"operators/fft_eval.py"))
exists = actual_path.joinpath("operators/math/fft_eval.py").exists()
assert not exists
num_lines = sum(1 for line in open(os.path.join(actual_path, r"operators/math/__init__.py")))
num_lines = sum(1 for line in actual_path.joinpath("operators/math/__init__.py").open())
assert num_lines >= 11


Expand All @@ -267,18 +265,16 @@ def test_load_plugin_correctly_remote():
server.external_ip, server.external_port, as_global=False
)

actual_path = os.path.dirname(pkgutil.get_loader("ansys.dpf.core").path)
actual_path = Path(pkgutil.get_loader("ansys.dpf.core").path).parent

if server.os == "posix":
dpf.load_library("libAns.Dpf.Math.so", "math_operators", server=server_connected)
else:
dpf.load_library("Ans.Dpf.Math.dll", "math_operators", server=server_connected)
t = os.path.getmtime(os.path.join(actual_path, r"operators/math/fft_eval.py"))
t = actual_path.joinpath("operators/math/fft_eval.py").stat().st_mtime
assert datetime.datetime.fromtimestamp(t).date() == datetime.datetime.today().date()

actual_path = os.path.dirname(pkgutil.get_loader("ansys.dpf.core").path)

assert os.path.exists(os.path.join(actual_path, r"operators/math/fft_eval.py"))
assert actual_path.joinpath("operators/math/fft_eval.py").exists()


def test_dpf_join(server_type):
Expand Down Expand Up @@ -320,7 +316,7 @@ def test_load_api_without_awp_root(restore_awp_root):

assert serv._client_api_path is not None
assert serv._grpc_client_path is not None
dpf_inner_path = os.path.join("ansys", "dpf", "gatebin")
dpf_inner_path = str(Path("ansys") / "dpf" / "gatebin")
assert dpf_inner_path in serv._client_api_path
assert dpf_inner_path in serv._grpc_client_path

Expand All @@ -339,7 +335,7 @@ def test_load_api_with_awp_root():

assert serv_2._client_api_path is not None
assert serv_2._grpc_client_path is not None
dpf_inner_path = os.path.join("ansys", "dpf", "gatebin")
dpf_inner_path = str(Path("ansys") / "dpf" / "gatebin")
assert dpf_inner_path in serv_2._client_api_path
assert dpf_inner_path in serv_2._grpc_client_path

Expand All @@ -366,7 +362,7 @@ def test_load_api_with_awp_root_2():

assert serv._client_api_path is not None
assert serv._grpc_client_path is not None
dpf_inner_path = os.path.join("ansys", "dpf", "gatebin")
dpf_inner_path = str(Path("ansys") / "dpf" / "gatebin")
assert dpf_inner_path in serv._client_api_path
assert dpf_inner_path in serv._grpc_client_path

Expand Down Expand Up @@ -421,9 +417,9 @@ def test_load_api_with_awp_root_no_gatebin():
assert serv_2._grpc_client_path is not None
ISPOSIX = os.name == "posix"
if not ISPOSIX:
dpf_inner_path = os.path.join("aisol", "bin", "winx64")
dpf_inner_path = str(Path("aisol") / "bin" / "winx64")
else:
dpf_inner_path = os.path.join("aisol", "dll", "linx64")
dpf_inner_path = str(Path("aisol") / "dll" / "linx64")
assert dpf_inner_path in serv_2._client_api_path
assert dpf_inner_path in serv_2._grpc_client_path

Expand All @@ -449,9 +445,9 @@ def test_load_api_with_awp_root_2_no_gatebin():
assert serv._grpc_client_path is not None
ISPOSIX = os.name == "posix"
if not ISPOSIX:
dpf_inner_path = os.path.join("aisol", "bin", "winx64")
dpf_inner_path = str(Path("aisol") / "bin" / "winx64")
else:
dpf_inner_path = os.path.join("aisol", "dll", "linx64")
dpf_inner_path = str(Path("aisol") / "dll" / "linx64")
assert dpf_inner_path in serv._client_api_path
assert dpf_inner_path in serv._grpc_client_path

Expand Down

0 comments on commit 880c247

Please sign in to comment.