Skip to content

Commit abcb5ae

Browse files
authored
test: adding test for start_timeout arg (#3554)
* feat: adding mapdl patcher * test: adding test * test: added more cases
1 parent 423ff9b commit abcb5ae

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

doc/changelog.d/3554.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test: adding test for start_timeout arg

tests/conftest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def _patch_method(method):
663663
return "ansys.mapdl.core.mapdl_grpc.MapdlGrpc." + method
664664

665665

666-
_meth_patch_MAPDL_launch = (
666+
_meth_patch_MAPDL_launch = [
667667
# method, and its return
668668
(_patch_method("_connect"), _returns(True)),
669669
(_patch_method("_run"), _returns("")),
@@ -682,10 +682,24 @@ def _patch_method(method):
682682
]
683683
),
684684
),
685+
]
686+
687+
_meth_patch_MAPDL = _meth_patch_MAPDL_launch.copy()
688+
_meth_patch_MAPDL.extend(
689+
[
690+
# launcher methods
691+
("ansys.mapdl.core.launcher.launch_grpc", _returns(None)),
692+
("ansys.mapdl.core.launcher.check_mapdl_launch", _returns(None)),
693+
]
685694
)
686695

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

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

690704
@pytest.fixture(scope="function")
691705
def set_env_var(request, monkeypatch):

tests/test_launcher.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
from ansys.mapdl.core.misc import stack
7777
from conftest import (
7878
ON_LOCAL,
79+
PATCH_MAPDL,
7980
PATCH_MAPDL_START,
8081
QUICK_LAUNCH_SWITCHES,
8182
TESTING_MINIMAL,
@@ -263,7 +264,6 @@ def test_license_type_dummy(mapdl):
263264
):
264265
launch_mapdl(
265266
start_instance=True,
266-
port=mapdl.port + 1,
267267
additional_switches=f" -p {dummy_license_type} " + QUICK_LAUNCH_SWITCHES,
268268
start_timeout=start_timeout,
269269
license_server_check=False,
@@ -1894,3 +1894,32 @@ def return_everything(*arg, **kwags):
18941894
assert isinstance(kwargs["stderr"], type(subprocess.PIPE))
18951895

18961896
assert kwargs["env"] == envvars
1897+
1898+
1899+
@requires("ansys-tools-path")
1900+
@patch(
1901+
"ansys.tools.path.path._get_application_path",
1902+
lambda *args, **kwargs: "path/to/mapdl/executable",
1903+
)
1904+
@patch("ansys.tools.path.path._mapdl_version_from_path", lambda *args, **kwargs: 242)
1905+
@stack(*PATCH_MAPDL)
1906+
@pytest.mark.parametrize(
1907+
"arg,value,method",
1908+
[
1909+
("start_timeout", 88, "_timeout"),
1910+
("start_timeout", 1099, "_timeout"),
1911+
("cleanup_on_exit", False, "_cleanup"),
1912+
("cleanup_on_exit", True, "_cleanup"),
1913+
("jobname", "myjobnamestrange", "_jobname"),
1914+
("jobid", 1088, "_jobid"),
1915+
("finish_job_on_exit", True, "finish_job_on_exit"),
1916+
("finish_job_on_exit", False, "finish_job_on_exit"),
1917+
],
1918+
)
1919+
def test_args_pass(monkeypatch, arg, value, method):
1920+
monkeypatch.delenv("PYMAPDL_START_INSTANCE", False)
1921+
1922+
kwargs = {arg: value}
1923+
mapdl = launch_mapdl(**kwargs)
1924+
meth = getattr(mapdl, method)
1925+
assert meth == value

0 commit comments

Comments
 (0)