Skip to content

Adapting test_cwd to work in local and remote #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ansys/mapdl/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def __init__(self, msg=""):
MapdlDidNotStart.__init__(self, msg)


class IncorrectWorkingDirectory(OSError, MapdlRuntimeError):
"""Raised when the MAPDL working directory does not exist."""

# The working directory specified (wrong_path) is not a directory.

def __init__(self, msg=""):
MapdlRuntimeError.__init__(self, msg)


# handler for protect_grpc
def handler(sig, frame): # pragma: no cover
"""Pass signal to custom interrupt handler."""
Expand Down
5 changes: 4 additions & 1 deletion src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
inject_docs,
)
from ansys.mapdl.core.errors import (
IncorrectWorkingDirectory,
MapdlCommandIgnoredError,
MapdlInvalidRoutineError,
MapdlRuntimeError,
Expand Down Expand Up @@ -3399,7 +3400,9 @@ def cwd(self, *args, **kwargs):

if output is not None:
if "*** WARNING ***" in output:
raise FileNotFoundError("\n" + "\n".join(output.splitlines()[1:]))
raise IncorrectWorkingDirectory(
"\n" + "\n".join(output.splitlines()[1:])
)

return output

Expand Down
25 changes: 19 additions & 6 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core.commands import CommandListingOutput
from ansys.mapdl.core.errors import MapdlCommandIgnoredError, MapdlRuntimeError
from ansys.mapdl.core.errors import (
IncorrectWorkingDirectory,
MapdlCommandIgnoredError,
MapdlRuntimeError,
)
from ansys.mapdl.core.launcher import get_start_instance, launch_mapdl
from ansys.mapdl.core.misc import random_string

Expand Down Expand Up @@ -1143,18 +1147,27 @@ def test_path_with_spaces(mapdl, path_tests):
@skip_in_cloud
def test_path_with_single_quote(mapdl, path_tests):
with pytest.raises(RuntimeError):
resp = mapdl.cwd(path_tests.path_with_single_quote)
mapdl.cwd(path_tests.path_with_single_quote)


@skip_in_cloud
def test_cwd(mapdl, tmpdir):
old_path = mapdl.directory
if mapdl._local:
tempdir_ = tmpdir
else:
if mapdl.platform == "linux":
mapdl.sys("mkdir -p /tmp")
tempdir_ = "/tmp"
elif mapdl.platform == "windows":
tempdir_ = "C:\\Windows\\Temp"
else:
raise ValueError("Unknown platform")
try:
mapdl.directory = str(tmpdir)
assert mapdl.directory == str(tmpdir).replace("\\", "/")
mapdl.directory = str(tempdir_)
assert str(mapdl.directory) == str(tempdir_).replace("\\", "/")

wrong_path = "wrong_path"
with pytest.raises(MapdlCommandIgnoredError, match="working directory"):
with pytest.raises(IncorrectWorkingDirectory, match="working directory"):
mapdl.directory = wrong_path

finally:
Expand Down