Skip to content
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

test: adding test for start_timeout arg #3554

Merged
merged 4 commits into from
Nov 18, 2024
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
1 change: 1 addition & 0 deletions doc/changelog.d/3554.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: adding test for start_timeout arg
16 changes: 15 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def _patch_method(method):
return "ansys.mapdl.core.mapdl_grpc.MapdlGrpc." + method


_meth_patch_MAPDL_launch = (
_meth_patch_MAPDL_launch = [
# method, and its return
(_patch_method("_connect"), _returns(True)),
(_patch_method("_run"), _returns("")),
Expand All @@ -682,10 +682,24 @@ def _patch_method(method):
]
),
),
]

_meth_patch_MAPDL = _meth_patch_MAPDL_launch.copy()
_meth_patch_MAPDL.extend(
[
# launcher methods
("ansys.mapdl.core.launcher.launch_grpc", _returns(None)),
("ansys.mapdl.core.launcher.check_mapdl_launch", _returns(None)),
]
)

# For testing
# Patch some of the starting procedures
PATCH_MAPDL_START = [patch(method, ret) for method, ret in _meth_patch_MAPDL_launch]

# Patch all the starting procedures so we can have a pseudo mapdl instance
PATCH_MAPDL = [patch(method, ret) for method, ret in _meth_patch_MAPDL]


@pytest.fixture(scope="function")
def set_env_var(request, monkeypatch):
Expand Down
31 changes: 30 additions & 1 deletion tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
from ansys.mapdl.core.misc import stack
from conftest import (
ON_LOCAL,
PATCH_MAPDL,
PATCH_MAPDL_START,
QUICK_LAUNCH_SWITCHES,
TESTING_MINIMAL,
Expand Down Expand Up @@ -263,7 +264,6 @@ def test_license_type_dummy(mapdl):
):
launch_mapdl(
start_instance=True,
port=mapdl.port + 1,
additional_switches=f" -p {dummy_license_type} " + QUICK_LAUNCH_SWITCHES,
start_timeout=start_timeout,
license_server_check=False,
Expand Down Expand Up @@ -1894,3 +1894,32 @@ def return_everything(*arg, **kwags):
assert isinstance(kwargs["stderr"], type(subprocess.PIPE))

assert kwargs["env"] == envvars


@requires("ansys-tools-path")
@patch(
"ansys.tools.path.path._get_application_path",
lambda *args, **kwargs: "path/to/mapdl/executable",
)
@patch("ansys.tools.path.path._mapdl_version_from_path", lambda *args, **kwargs: 242)
@stack(*PATCH_MAPDL)
@pytest.mark.parametrize(
"arg,value,method",
[
("start_timeout", 88, "_timeout"),
("start_timeout", 1099, "_timeout"),
("cleanup_on_exit", False, "_cleanup"),
("cleanup_on_exit", True, "_cleanup"),
("jobname", "myjobnamestrange", "_jobname"),
("jobid", 1088, "_jobid"),
("finish_job_on_exit", True, "finish_job_on_exit"),
("finish_job_on_exit", False, "finish_job_on_exit"),
],
)
def test_args_pass(monkeypatch, arg, value, method):
monkeypatch.delenv("PYMAPDL_START_INSTANCE", False)

kwargs = {arg: value}
mapdl = launch_mapdl(**kwargs)
meth = getattr(mapdl, method)
assert meth == value
Loading