Skip to content

Commit

Permalink
feat: adding check_has_mapdl (#3576)
Browse files Browse the repository at this point in the history
* fix: promote to exposed function

* tests: adding tests

* chore: adding changelog file 3576.miscellaneous.md [dependabot-skip]

* fix: test

* fix: adding missing import

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
germa89 and pyansys-ci-bot authored Nov 26, 2024
1 parent 3635824 commit 76d8ee7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3576.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: adding ``check_has_mapdl``
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions src/ansys/mapdl/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from collections import namedtuple
import os
import subprocess
import time
from typing import Dict, List

import psutil
Expand Down
18 changes: 17 additions & 1 deletion tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1931,3 +1931,19 @@ def test_args_pass(monkeypatch, arg, value, method):
mapdl = launch_mapdl(**kwargs)
meth = getattr(mapdl, method)
assert meth == value


def test_check_has_mapdl():
if TESTING_MINIMAL:
assert check_has_mapdl() is False
else:
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

0 comments on commit 76d8ee7

Please sign in to comment.