From 6fc830b018c9a1910e21279d59f0dfffabb3a8b0 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:36:43 +0100 Subject: [PATCH 1/4] feat: adding mapdl patcher --- tests/conftest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 98bfe2e3e9..4742b6326c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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("")), @@ -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): From 5f5ff113fcfddaef6864fd91906806800d0adb03 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:37:45 +0100 Subject: [PATCH 2/4] test: adding test --- tests/test_launcher.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index f530ba0a8c..a24ad1186a 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -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, @@ -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, @@ -1894,3 +1894,28 @@ 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"), + ], +) +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 From 330488ddcd72300facd8cde608736c3e505a2d77 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 18 Nov 2024 13:43:13 +0100 Subject: [PATCH 3/4] test: added more cases --- tests/test_launcher.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index a24ad1186a..4633a3f029 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -1910,6 +1910,10 @@ def return_everything(*arg, **kwags): ("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): From a1c8f566ad745e9f674a24b34e6d98433c4009a0 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:46:18 +0000 Subject: [PATCH 4/4] chore: adding changelog file 3554.added.md [dependabot-skip] --- doc/changelog.d/3554.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3554.added.md diff --git a/doc/changelog.d/3554.added.md b/doc/changelog.d/3554.added.md new file mode 100644 index 0000000000..41caad6cb3 --- /dev/null +++ b/doc/changelog.d/3554.added.md @@ -0,0 +1 @@ +test: adding test for start_timeout arg \ No newline at end of file