Skip to content

Commit 7b544b4

Browse files
germa89pyansys-ci-botgayusopre-commit-ci[bot]
authored
refactor: small improvements to test settings (#3577)
* ci: adding timeout to each test * chore: adding changelog file 3577.dependencies.md [dependabot-skip] * test: avoid checking command output * test: avoid checking command output * fix: unpack * feat: disabling subscription to channel * fix: components typo * chore: adding changelog file 3577.documentation.md [dependabot-skip] * feat: avoid checking on not set channel * ci: automate logging when testing * fix: reading nset when no RST is generated * fix: detecting comments as parameters sets when they have =. * fix: avoid fail on reading rst file * feat: setting verbosity when debug env var * feat: using non-interactive for using iterable in XSEL commands * fix: running post.__repr__ as post1 * feat: logging non_interactive in MAPDL logging and APDL logging * fix: post_processing repr * test: post string * fix: test * feat: showing a warning when rebooting MAPDL. * tests: skip some test Temporary * fix: initial channel state * fix: removing APDL comment so it does not interfere on the last_respone * fix: database tests * fix: path test * feat: stripping spaces from the command output * fix: checking pids when there is no cleanup file. * fix: make sure we are properly comparing paths when MAPDL is also installed on a machine. * ci: auto fixes from pre-commit.com hooks. for more information, see https://pre-commit.ci * fix: small fixes in database tests * fix: skip testing on windows for the moment * ci: auto fixes from pre-commit.com hooks. for more information, see https://pre-commit.ci * fix: precommit * fix: xpl not loading full file * refactor: moving xpl tests to a class * feat: adding apdl output * tests: removing redundant test * chore: merge fix/avoid-error-when-retriving-routine * chore: adding changelog file 3596.miscellaneous.md [dependabot-skip] * revert: "revert: "Merge branches 'feat/piping-MAPDL-output-to-a-given-file', 'main' and 'main' of https://github.com/ansys/pymapdl" (#3607)" This reverts commit afad43e. * chore: adding changelog file 3577.dependencies.md [dependabot-skip] * refactor: reorg allowed arguments order * fix: removing `file` call. * feat: apply suggestions from code review * feat: apply suggestions from code review * chore: adding changelog file 3577.added.md [dependabot-skip] * fix: removing left behind code --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: gayuso <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 841313d commit 7b544b4

File tree

15 files changed

+238
-139
lines changed

15 files changed

+238
-139
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ env:
3535
ON_CI: True
3636
PYTEST_ARGUMENTS: '-vvv -rxXsa --color=yes --durations=10 --random-order --random-order-bucket=class --maxfail=10 --reruns 3 --reruns-delay 4 --cov=ansys.mapdl.core --cov-report=html --timeout=180'
3737

38+
3839
BUILD_CHEATSHEET: True
3940
PYMAPDL_DEBUG_TESTING: True
4041

@@ -63,7 +64,6 @@ permissions:
6364

6465
jobs:
6566

66-
6767
update-changelog:
6868
name: "Update CHANGELOG (on release)"
6969
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')

doc/changelog.d/3577.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
refactor: small improvements to test settings

src/ansys/mapdl/core/database/database.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ def stop(self):
313313

314314
self._mapdl._log.debug("Closing the connection with the MAPDL DB Server")
315315
self._stop()
316-
self._channel.close()
317-
self._channel = None
316+
if self._channel:
317+
self._channel.close()
318+
self._channel = None
318319
self._stub = None
319320
self._state = None
320321

src/ansys/mapdl/core/launcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def version_from_path(*args, **kwargs):
105105
"additional_switches",
106106
"cleanup_on_exit",
107107
"clear_on_connect",
108-
"running_on_hpc",
109108
"exec_file",
110109
"force_intel" "ip",
111110
"ip",
@@ -125,6 +124,7 @@ def version_from_path(*args, **kwargs):
125124
"remove_temp_dir_on_exit",
126125
"replace_env_vars",
127126
"run_location",
127+
"running_on_hpc",
128128
"scheduler_options",
129129
"set_no_abort",
130130
"start_instance",
@@ -554,7 +554,7 @@ def check_mapdl_launch(
554554
MAPDL did not start.
555555
"""
556556
LOG.debug("Generating queue object for stdout")
557-
stdout_queue, _ = _create_queue_for_std(process.stdout)
557+
stdout_queue, thread = _create_queue_for_std(process.stdout)
558558

559559
# Checking connection
560560
try:

src/ansys/mapdl/core/mapdl_core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ def __init__(self, parent):
13961396
self._parent = weakref.ref(parent)
13971397

13981398
def __enter__(self):
1399-
self._parent()._log.debug("Entering non-interactive mode")
1399+
self._parent()._log.debug("Entering in non-interactive mode")
1400+
self._parent().com("Entering in non_interactive mode")
14001401
self._parent()._store_commands = True
14011402

14021403
def __exit__(self, *args):
@@ -2283,6 +2284,7 @@ def run(
22832284
self._before_run(command)
22842285

22852286
short_cmd = parse_to_short_cmd(command)
2287+
self._log.debug(f"Running (verbose: {verbose}, mute={mute}): '{command}'")
22862288
text = self._run(command, verbose=verbose, mute=mute)
22872289

22882290
if (

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,12 @@ def _cache_pids(self):
13341334
pids = set(re.findall(r"-9 (\d+)", raw))
13351335
self._pids = [int(pid) for pid in pids]
13361336

1337-
if not self._pids:
1337+
if not self._pids and not self._mapdl_process:
1338+
self._log.debug(
1339+
f"MAPDL process is not provided. PIDs could not be retrieved."
1340+
)
1341+
return
1342+
elif not self._pids:
13381343
# For the cases where the cleanup file is not generated,
13391344
# we relay on the process.
13401345
parent_pid = self._mapdl_process.pid

src/ansys/mapdl/core/misc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ def wrapper(self, *args, **kwargs):
571571
# assuming you want to select nothing because you supplied an empty list/tuple/array
572572
return original_sel_func(self, "none")
573573

574-
self._perform_entity_list_selection(
575-
entity, original_sel_func, type_, item, comp, vmin, kabs
576-
)
574+
with self.non_interactive: # to speed up
575+
self._perform_entity_list_selection(
576+
entity, original_sel_func, type_, item, comp, vmin, kabs
577+
)
577578

578579
if kwargs.pop("Used_P", False):
579580
# we want to return the

src/ansys/mapdl/core/parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def _get_parameter_array(self, parm_name, shape):
558558
f"that could not be read using '{format_str}'."
559559
)
560560

561-
arr_flat = np.fromstring(output, sep="\n").reshape(shape)
561+
arr_flat = np.fromstring(output.strip(), sep="\n").reshape(shape)
562562

563563
if len(shape) == 3:
564564
if shape[2] == 1:

src/ansys/mapdl/core/post.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,37 @@ def _mapdl(self):
139139
@supress_logging
140140
def __repr__(self):
141141
info = "PyMAPDL PostProcessing Instance\n"
142-
info += "\tActive Result File: %s\n" % self.filename
143-
info += "\tNumber of result sets: %d\n" % self.nsets
144-
info += "\tCurrent load step: %d\n" % self.load_step
145-
info += "\tCurrent sub step: %d\n" % self.sub_step
142+
info += f"\tActive Result File: {self.filename}\n"
143+
144+
# If there is no result file, this fails.
145+
try:
146+
nsets = int(self.nsets)
147+
except MapdlRuntimeError as error:
148+
self._mapdl.logger.debug(
149+
f"Error when obtaining the number of sets:\n{error}"
150+
)
151+
nsets = "NA"
152+
153+
info += f"\tNumber of result sets: {nsets}\n"
154+
info += f"\tCurrent load step: {self.load_step}\n"
155+
info += f"\tCurrent sub step: {self.sub_step}\n"
146156

147157
if self._mapdl.parameters.routine == "POST1":
148-
info += "\n\n" + self._mapdl.set("LIST")
158+
try:
159+
nlist = self._mapdl.set("LIST")
160+
except MapdlRuntimeError as err:
161+
if (
162+
"An error occurred while attempting to open the results file"
163+
in str(err)
164+
):
165+
self._mapdl.logger.debug(
166+
f"List of steps could not be obtained due to error:\n{err}"
167+
)
168+
nlist = "Results file is not available"
169+
else:
170+
raise err
171+
172+
info += "\n\n" + nlist
149173
else:
150174
info += "\n\nEnable routine POST1 to see a table of available results"
151175

tests/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ def is_exited(mapdl: Mapdl):
274274

275275
# we cannot connect.
276276
# Kill the instance
277-
mapdl.exit()
277+
try:
278+
mapdl.exit()
279+
except Exception as e:
280+
LOG.error(f"An error occurred when killing the instance:\n{str(e)}")
278281

279282
# Relaunching MAPDL
280283
mapdl = launch_mapdl(
@@ -285,6 +288,8 @@ def is_exited(mapdl: Mapdl):
285288
log_apdl=log_apdl(),
286289
)
287290

291+
LOG.info("Successfully re-connected to MAPDL")
292+
288293
# Restoring the local configuration
289294
mapdl._local = local_
290295
mapdl._exited = False

0 commit comments

Comments
 (0)