From d8d3f33c84b6c133de4a0a250be7dde126fb1fc2 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:18:51 +0100 Subject: [PATCH 1/5] fix: promote to exposed function --- src/ansys/mapdl/core/__init__.py | 2 +- src/ansys/mapdl/core/misc.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ansys/mapdl/core/__init__.py b/src/ansys/mapdl/core/__init__.py index 99df5b589f..66eefed548 100644 --- a/src/ansys/mapdl/core/__init__.py +++ b/src/ansys/mapdl/core/__init__.py @@ -115,7 +115,7 @@ from ansys.mapdl.core.information import Information from ansys.mapdl.core.mapdl_grpc import MapdlGrpc as Mapdl -from ansys.mapdl.core.misc import _check_has_ansys +from ansys.mapdl.core.misc import check_has_mapdl from ansys.mapdl.core.pool import MapdlPool from ansys.mapdl.core.report import Report diff --git a/src/ansys/mapdl/core/misc.py b/src/ansys/mapdl/core/misc.py index 5ec3e355a9..1c14e05610 100644 --- a/src/ansys/mapdl/core/misc.py +++ b/src/ansys/mapdl/core/misc.py @@ -112,7 +112,7 @@ def random_string(stringLength: int = 10, letters: str = string.ascii_lowercase) return "".join(secrets.choice(letters) for _ in range(stringLength)) -def _check_has_ansys() -> bool: +def check_has_mapdl() -> bool: """Safely wraps check_valid_ansys Returns @@ -125,7 +125,10 @@ def _check_has_ansys() -> bool: try: return check_valid_ansys() - except: + except Exception as err: + LOG.error( + f"An error was obtained when checking for a valid MAPDL installation:\n{str(err)}" + ) return False From 5d37bad86282360bf24338519e321656d5e85b56 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:19:52 +0100 Subject: [PATCH 2/5] tests: adding tests --- tests/test_launcher.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index e890cfc1bc..5fefce37a9 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -73,7 +73,7 @@ update_env_vars, ) from ansys.mapdl.core.licensing import LICENSES -from ansys.mapdl.core.misc import stack +from ansys.mapdl.core.misc import check_has_mapdl, stack from conftest import ( ON_LOCAL, PATCH_MAPDL, @@ -1931,3 +1931,16 @@ def test_args_pass(monkeypatch, arg, value, method): mapdl = launch_mapdl(**kwargs) meth = getattr(mapdl, method) assert meth == value + + +def test_check_has_mapdl(): + assert check_has_mapdl() == ON_LOCAL + + +def raising(): + raise Exception("An error") + + +@patch("ansys.mapdl.core.launcher.check_valid_ansys", raising) +def test_check_has_mapdl_failed(): + assert check_has_mapdl() is False From b908564fcc638be84253ed22a2157f501d363177 Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:22:14 +0000 Subject: [PATCH 3/5] chore: adding changelog file 3576.miscellaneous.md [dependabot-skip] --- doc/changelog.d/3576.miscellaneous.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3576.miscellaneous.md diff --git a/doc/changelog.d/3576.miscellaneous.md b/doc/changelog.d/3576.miscellaneous.md new file mode 100644 index 0000000000..baf1ad34eb --- /dev/null +++ b/doc/changelog.d/3576.miscellaneous.md @@ -0,0 +1 @@ +feat: adding ``check_has_mapdl`` \ No newline at end of file From b4a5b50ee670e3621d2c8c67491f83a31a434715 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 25 Nov 2024 21:41:10 +0100 Subject: [PATCH 4/5] fix: test --- tests/test_launcher.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 5fefce37a9..92952a42cc 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -1934,7 +1934,10 @@ def test_args_pass(monkeypatch, arg, value, method): def test_check_has_mapdl(): - assert check_has_mapdl() == ON_LOCAL + if TESTING_MINIMAL: + assert check_has_mapdl() is False + else: + assert check_has_mapdl() == ON_LOCAL def raising(): From 5b0e3b3610aef57731452d6287c8b48f4985d359 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 25 Nov 2024 22:07:40 +0100 Subject: [PATCH 5/5] fix: adding missing import --- tests/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common.py b/tests/common.py index 7187c295d0..0ff9a64632 100644 --- a/tests/common.py +++ b/tests/common.py @@ -24,6 +24,7 @@ from collections import namedtuple import os import subprocess +import time from typing import Dict, List import psutil