Skip to content

Commit

Permalink
feat: adding-mode-warning (#3574)
Browse files Browse the repository at this point in the history
* feat: adding a warning when no version is given.

* feat: adding test

* fix: avoid recording intended warnings to the stdout (they are caught by pytests)

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

* fix: already entered issue

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Nov 25, 2024
1 parent e2a100c commit 3aa2a73
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3574.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: adding-mode-warning
7 changes: 7 additions & 0 deletions src/ansys/mapdl/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,13 @@ def check_mode(mode: ALLOWABLE_MODES, version: Optional[int] = None):
"""
if not mode and not version:
return "grpc"
elif not version:
warnings.warn(
"PyMAPDL couldn't detect MAPDL version, hence it could not "
f"verify that the provided connection mode '{mode}' is compatible "
"with the current MAPDL installation."
)
return mode

if isinstance(mode, str):
mode = mode.lower()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_defaul_entity_warning(mapdl, cube_geom_and_mesh):
mapdl.components["mycomp"] = (1, 2, 3)

mapdl.components.default_entity_warning = False
with warnings.catch_warnings():
with warnings.catch_warnings(record=True):
mapdl.components["mycomp"] = (1, 2, 3)

mapdl.components.default_entity_warning = True
Expand Down
11 changes: 9 additions & 2 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ def test_ip_and_start_instance(

###################
# Faking MAPDL launching and returning args
with warnings.catch_warnings():
with warnings.catch_warnings(record=True):
options = launch_mapdl(
start_instance=start_instance,
ip=ip,
Expand Down Expand Up @@ -1790,11 +1790,18 @@ def test_get_version_env_var(monkeypatch, version):
pytest.raises(VersionError, match="Running MAPDL as a service requires"),
None,
],
[
"anymode",
None,
"posix",
pytest.warns(UserWarning, match="PyMAPDL couldn't detect MAPDL version"),
"anymode",
],
],
)
def test_check_mode(mode, version, osname, context, res):
with patch("os.name", osname):
with context:
with context as cnt:
assert res == check_mode(mode, version)


Expand Down
6 changes: 3 additions & 3 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2516,14 +2516,14 @@ def test_load_not_raising_warning():

os.remove(FIRST_TIME_FILE)

with catch_warnings():
with catch_warnings(record=True):
reload(pymapdl)


@pytest.mark.parametrize(
"python_version,minimal_version,deprecating,context",
[
((3, 9, 10), (3, 9), False, catch_warnings()), # standard case
((3, 9, 10), (3, 9), False, catch_warnings(record=True)), # standard case
(
(3, 9, 10),
(3, 9),
Expand Down Expand Up @@ -2565,7 +2565,7 @@ def func(*args, **kwargs):
pymapdl.helpers.run_first_time()

# Assert warnings won't be retrigger
with catch_warnings():
with catch_warnings(record=True):
reload(pymapdl)

pymapdl.helpers.run_first_time()

0 comments on commit 3aa2a73

Please sign in to comment.