Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding check_has_mapdl #3576

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading