From 3aa2a735851e23ab89f50b963dff80ddf650fe78 Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:19:46 +0100 Subject: [PATCH] feat: adding-mode-warning (#3574) * 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 <92810346+pyansys-ci-bot@users.noreply.github.com> --- doc/changelog.d/3574.miscellaneous.md | 1 + src/ansys/mapdl/core/launcher.py | 7 +++++++ tests/test_component.py | 2 +- tests/test_launcher.py | 11 +++++++++-- tests/test_mapdl.py | 6 +++--- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 doc/changelog.d/3574.miscellaneous.md diff --git a/doc/changelog.d/3574.miscellaneous.md b/doc/changelog.d/3574.miscellaneous.md new file mode 100644 index 0000000000..6f733033c0 --- /dev/null +++ b/doc/changelog.d/3574.miscellaneous.md @@ -0,0 +1 @@ +feat: adding-mode-warning \ No newline at end of file diff --git a/src/ansys/mapdl/core/launcher.py b/src/ansys/mapdl/core/launcher.py index 170307d231..8af6f46ec2 100644 --- a/src/ansys/mapdl/core/launcher.py +++ b/src/ansys/mapdl/core/launcher.py @@ -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() diff --git a/tests/test_component.py b/tests/test_component.py index 6b2a293cde..da5ebd91f6 100644 --- a/tests/test_component.py +++ b/tests/test_component.py @@ -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 diff --git a/tests/test_launcher.py b/tests/test_launcher.py index 15e1b07958..e890cfc1bc 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -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, @@ -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) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index 1197a647c9..2c2634a401 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -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), @@ -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()