From b42cb4e31ca866184fd5f9bd5ca43de89137aaff Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:14:35 +0100 Subject: [PATCH 1/5] feat: avoiding getting a wrong routine --- src/ansys/mapdl/core/parameters.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ansys/mapdl/core/parameters.py b/src/ansys/mapdl/core/parameters.py index 32c96bbef8..8178e44a0b 100644 --- a/src/ansys/mapdl/core/parameters.py +++ b/src/ansys/mapdl/core/parameters.py @@ -171,7 +171,14 @@ def routine(self) -> str: >>> mapdl.parameters.routine 'PREP7' """ - value = self._mapdl.get_value("ACTIVE", item1="ROUT") + value = int(self._mapdl.get_value("ACTIVE", item1="ROUT")) + if value not in ROUTINE_MAP: + self._mapdl.logger.info( + f"Getting a valid routine number failed. Routine obtained is {value}. Executing 'FINISH'." + ) + self._mapdl.finish() + value = 0 + return ROUTINE_MAP[int(value)] @property From efe8bb7fd090442d9691ac7641556d87044ee93b Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:16:02 +0100 Subject: [PATCH 2/5] tests: adding tests --- tests/test_parameters.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 417c6389cd..aec7512d31 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -20,7 +20,9 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. +import logging import re +from unittest.mock import patch import numpy as np import pytest @@ -470,3 +472,25 @@ def test_non_interactive(mapdl, cleared): mapdl.parameters["qwer"] = 3 assert mapdl.parameters["qwer"] == 3 + + +@pytest.mark.parametrize("value", [121, 299]) +def test_failing_get_routine(mapdl, caplog, value): + from ansys.mapdl.core.parameters import ROUTINE_MAP + + prev_level = mapdl.logger.logger.level + mapdl.logger.setLevel(logging.INFO) + + with patch("ansys.mapdl.core.mapdl_extended._MapdlExtended.get_value") as mck: + mck.return_value = value + with caplog.at_level(logging.INFO): + routine = mapdl.parameters.routine + + mck.assert_called_once() + + txt = str(caplog.text) + assert f"Getting a valid routine number failed." in txt + assert f"Routine obtained is {value}. Executing 'FINISH'." in txt + assert routine == ROUTINE_MAP[0] + + mapdl.logger.setLevel(prev_level) From 91c9000c1aaff773abf6faf5ca88093cc6d3f472 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:19:19 +0000 Subject: [PATCH 3/5] chore: adding changelog file 3606.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3606.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3606.miscellaneous.md diff --git a/doc/changelog.d/3606.miscellaneous.md b/doc/changelog.d/3606.miscellaneous.md new file mode 100644 index 0000000000..f1d7a8a38f --- /dev/null +++ b/doc/changelog.d/3606.miscellaneous.md @@ -0,0 +1 @@ +feat: avoid errors when retriving invalid routine \ No newline at end of file From 1505279d236be3f8f48b0e82fbd33c2c1184e592 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Mon, 9 Dec 2024 13:53:57 +0000 Subject: [PATCH 4/5] chore: adding changelog file 3606.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3606.miscellaneous.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/3606.miscellaneous.md b/doc/changelog.d/3606.miscellaneous.md index f1d7a8a38f..0828ccb275 100644 --- a/doc/changelog.d/3606.miscellaneous.md +++ b/doc/changelog.d/3606.miscellaneous.md @@ -1 +1 @@ -feat: avoid errors when retriving invalid routine \ No newline at end of file +feat: avoid errors when retrieving invalid routine \ No newline at end of file From 8df9ce8980aa17bbf48a1be51cf59f1db93c06f7 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:54:09 +0100 Subject: [PATCH 5/5] tests: renaming test --- tests/test_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 167006d497..682e9447f8 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -1967,7 +1967,7 @@ def test_mapdl_output(tmpdir): mapdl.exit() -def test_mapdl_output_patch(tmpdir): +def test_mapdl_output(tmpdir): def submitter(**kwargs): from _io import FileIO