diff --git a/src/ansys/dpf/core/workflow.py b/src/ansys/dpf/core/workflow.py index 56a4033cbd..347f284370 100644 --- a/src/ansys/dpf/core/workflow.py +++ b/src/ansys/dpf/core/workflow.py @@ -933,15 +933,11 @@ def view( name = title if save_as: - # dot_path = os.path.splitext(str(save_as))[0] + ".dot" image_path = Path(save_as) dot_path = image_path.parent / image_path.stem / ".dot" - # image_path = save_as else: - # dot_path = os.path.join(os.getcwd(), f"{name}.dot") image_path = Path.cwd() / f"{name}.png" dot_path = image_path.parent / image_path.stem / ".dot" - # image_path = os.path.join(os.getcwd(), f"{name}.png") # Create graphviz file of workflow self.to_graphviz(dot_path) @@ -951,7 +947,6 @@ def view( # View workflow graphviz.view(filepath=image_path) if not keep_dot_file: - # os.remove(dot_path) dot_path.unlink() return image_path diff --git a/tests/conftest.py b/tests/conftest.py index 73c3f59ce9..ba50e0451e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,6 +28,7 @@ import os import functools +from pathlib import Path import psutil import pytest @@ -54,10 +55,10 @@ def _get_test_files_directory(): if local_test_repo is False: - test_path = os.path.join(os.path.dirname(os.path.abspath(__file__))) - return os.path.join(test_path, os.pardir, "tests", "testfiles") + test_path = Path(__file__).parent + return str(test_path.joinpath("testfiles")) else: - return os.path.join(os.environ["AWP_UNIT_TEST_FILES"], "python") + return str(Path(os.environ["AWP_UNIT_TEST_FILES"]).joinpath("python")) if os.name == "posix": @@ -94,11 +95,11 @@ def resolve_test_file(basename, additional_path="", is_in_examples=None): if is_in_examples: return examples.find_files(getattr(examples, is_in_examples)) else: - test_files_path = _get_test_files_directory() - filename = os.path.join(test_files_path, additional_path, basename) - if not os.path.isfile(filename): + test_files_path = Path(_get_test_files_directory()) + filename = test_files_path.joinpath(additional_path, basename) + if not filename.is_file(): raise FileNotFoundError(f"Unable to locate {basename} at {test_files_path}") - return examples.find_files(filename) + return examples.find_files(str(filename)) @pytest.fixture() diff --git a/tests/entry/conftest.py b/tests/entry/conftest.py index 027c1ca64e..ee70a9737f 100644 --- a/tests/entry/conftest.py +++ b/tests/entry/conftest.py @@ -29,6 +29,7 @@ """ import os +from pathlib import Path import functools import pytest @@ -54,10 +55,10 @@ def _get_test_files_directory(): if local_test_repo is False: - test_path = os.path.join(os.path.dirname(os.path.abspath(__file__))) - return os.path.join(test_path, os.pardir, "tests", "testfiles") + test_path = Path(__file__).parent + return str(test_path.joinpath("testfiles")) else: - return os.path.join(os.environ["AWP_UNIT_TEST_FILES"], "python") + return str(Path(os.environ["AWP_UNIT_TEST_FILES"]).joinpath("python")) if os.name == "posix": diff --git a/tests/test_animation.py b/tests/test_animation.py index d1f7185b3e..4161bb9845 100644 --- a/tests/test_animation.py +++ b/tests/test_animation.py @@ -21,6 +21,7 @@ # SOFTWARE. import os +from pathlib import Path import pytest @@ -43,8 +44,8 @@ def remove_gifs(request): """Remove GIF once finished.""" def remove_gif(): - if os.path.exists(os.path.join(os.getcwd(), gif_name)): - os.remove(os.path.join(os.getcwd(), gif_name)) + if Path.cwd().joinpath(gif_name).exists(): + Path.cwd().joinpath(gif_name).unlink() request.addfinalizer(remove_gif) diff --git a/tests/test_animator.py b/tests/test_animator.py index d0fada4cd8..c5ef1f5fab 100644 --- a/tests/test_animator.py +++ b/tests/test_animator.py @@ -21,6 +21,7 @@ # SOFTWARE. import os +from pathlib import Path import pytest @@ -42,8 +43,8 @@ def remove_gifs(request): """Remove GIF once finished.""" def remove_gif(): - if os.path.exists(os.path.join(os.getcwd(), gif_name)): - os.remove(os.path.join(os.getcwd(), gif_name)) + if Path.cwd().joinpath(gif_name).exists(): + Path.cwd().joinpath(gif_name).unlink() request.addfinalizer(remove_gif) @@ -250,5 +251,5 @@ def test_animator_animate_fields_container_cpos(remove_gifs, displacement_fields off_screen=True, show_axes=True, ) - assert os.path.isfile(gif_name) - assert os.path.getsize(gif_name) > 6000 + assert Path(gif_name).is_file() + assert Path(gif_name).stat().st_size > 6000