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-mode-warning #3574

Merged
merged 5 commits into from
Nov 25, 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/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()
Loading