Skip to content

Commit 78946e8

Browse files
germa89pyansys-ci-botCopilot
authored
fix: reducing the amount of gRPC calls in get and add test for get command (#4184)
* fix: reducing the amount of gRPC calls in get and add test for get command * chore: adding changelog file 4184.miscellaneous.md [dependabot-skip] * Update src/ansys/mapdl/core/mapdl_extended.py Co-authored-by: Copilot <[email protected]> * fix: improve test_get_not_muted by mocking wrinqr and asserting call * fix: remove mute parameter from command execution in _MapdlCommandExtended * fix: correct condition in force-output mode entry check * fix: enhance test_get_not_muted to verify muted and unmuted states * fix: correct assertion in test_get_not_muted to use 'mute' property --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent cb066e3 commit 78946e8

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix: reducing the amount of gRPC calls in get and add test for get command

src/ansys/mapdl/core/mapdl_core.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,8 +3096,7 @@ def __init__(self, parent: "MapdlBase"):
30963096

30973097
def __enter__(self):
30983098
self._parent()._log.debug("Entering force-output mode")
3099-
3100-
if self._parent().wrinqr(1) != 1: # using wrinqr is more reliable than *get
3099+
if self._parent().wrinqr(1) == 0: # using wrinqr is more reliable than *get
31013100
self._in_nopr = True
31023101
self._parent()._run("/gopr") # Going to PR mode
31033102
else:

src/ansys/mapdl/core/mapdl_extended.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,11 +2123,13 @@ def get(
21232123
self._check_parameter_name(par)
21242124

21252125
command = f"*GET,{par},{entity},{entnum},{item1},{it1num},{item2},{it2num},{item3},{it3num},{item4},{it4num}"
2126-
kwargs["mute"] = False
21272126

2128-
# Checking printout is not suppressed by checking "wrinqr" flag.
2129-
with self.force_output:
2130-
response = self.run(command, **kwargs)
2127+
response = self.run(command, **kwargs)
2128+
2129+
if not response:
2130+
# If no response is received, re-run the command with force_output to ensure output is captured.
2131+
with self.force_output:
2132+
response = self.run(command, **kwargs)
21312133

21322134
if self._store_commands:
21332135
# Return early in non_interactive

tests/test_mapdl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,7 @@ def test_force_output(mapdl, cleared):
20192019
assert mapdl.prep7()
20202020
assert not mapdl.prep7()
20212021

2022+
with mapdl.muted:
20222023
mapdl._run("nopr")
20232024
with mapdl.force_output:
20242025
assert mapdl.prep7()
@@ -2034,6 +2035,23 @@ def test_force_output(mapdl, cleared):
20342035
assert mapdl.prep7()
20352036

20362037

2038+
def test_get_not_muted(mapdl, cleared):
2039+
mapdl.gopr()
2040+
assert not mapdl.mute
2041+
2042+
with patch.object(mapdl, "wrinqr", wraps=mapdl.wrinqr) as mock_muted:
2043+
with mapdl.muted:
2044+
assert mapdl.get("line1", "LINE", 0, "NUM", "MAX") is not None
2045+
2046+
mock_muted.assert_called_once()
2047+
2048+
assert mapdl.mute is False
2049+
with patch.object(mapdl, "wrinqr", wraps=mapdl.wrinqr) as mock_not_muted:
2050+
assert mapdl.get("line1", "LINE", 0, "NUM", "MAX") is not None
2051+
2052+
mock_not_muted.assert_not_called()
2053+
2054+
20372055
def test_session_id(mapdl, cleared, running_test):
20382056
mapdl._strict_session_id_check = True
20392057
assert mapdl._session_id is not None

0 commit comments

Comments
 (0)