Skip to content

Commit

Permalink
doc: changes to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 10, 2024
1 parent 4600f5d commit be6ecda
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
5 changes: 0 additions & 5 deletions src/ansys/dpf/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
15 changes: 8 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import os
import functools
from pathlib import Path

import psutil
import pytest
Expand All @@ -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":
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions tests/entry/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"""

import os
from pathlib import Path
import functools
import pytest

Expand All @@ -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":
Expand Down
5 changes: 3 additions & 2 deletions tests/test_animation.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

Expand All @@ -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)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_animator.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

Expand All @@ -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)

Expand Down Expand Up @@ -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

0 comments on commit be6ecda

Please sign in to comment.