Skip to content

Commit e395fbc

Browse files
germa89pre-commit-ci[bot]clatapie
authored
Pytest options to envvar and runtime error replacement (#1953)
* Changing runtime error for MapdlRuntimeError * Using an env var for pytest options * Fixing tests * Adding missing import * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Camille <[email protected]>
1 parent 458eaf0 commit e395fbc

File tree

26 files changed

+106
-76
lines changed

26 files changed

+106
-76
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ env:
2121
DOCKER_PACKAGE: ghcr.io/pyansys/pymapdl/mapdl
2222
DOCKER_IMAGE_VERSION_DOCS_BUILD: v22.2.0
2323
ON_CI: True
24+
PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=10 --reruns 7 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html'
25+
2426
# Following env vars when changed will "reset" the mentioned cache,
2527
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
2628
# You should go up in number, if you go down (or repeat a previous value)
@@ -61,7 +63,7 @@ jobs:
6163
matrix:
6264
os: [ubuntu-latest, windows-latest, macos-latest]
6365
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
64-
# Only perform wheelhouse builds for Windows and macOS when releasing
66+
# Only perform wheelhouse builds for macOS when releasing
6567
should-release:
6668
- ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags') }}
6769
exclude:
@@ -328,9 +330,9 @@ jobs:
328330
- name: "Unit testing"
329331
run: |
330332
if [[ "${{ matrix.mapdl-version }}" == *"ubuntu"* ]]; then export ON_UBUNTU=true;fi
331-
xvfb-run pytest -v --durations=10 \
332-
--maxfail=3 --reruns 7 --reruns-delay 5 \
333-
--cov=ansys.mapdl.core --cov-report=xml:centos-${{ matrix.mapdl-version }}-remote.xml --cov-report=html
333+
xvfb-run pytest \
334+
${{ env.PYTEST_ARGUMENTS }} \
335+
--cov-report=xml:centos-${{ matrix.mapdl-version }}-remote.xml
334336
335337
- uses: codecov/codecov-action@v3
336338
name: "Upload coverage to Codecov"
@@ -476,10 +478,9 @@ jobs:
476478
unset PYMAPDL_START_INSTANCE
477479
export ANSYSLMD_LICENSE_FILE=1055@${{ secrets.LICENSE_SERVER }}
478480
export AWP_ROOT222=/ansys_inc
479-
xvfb-run pytest -v -k "not test_database and not test_dpf" \
480-
--durations=10 \
481-
--maxfail=10 --reruns 7 --reruns-delay 5 \
482-
--cov=ansys.mapdl.core --cov-report=xml:ubuntu-v22.2.0-local.xml --cov-report=html
481+
xvfb-run pytest -k "not test_database and not test_dpf" \
482+
${{ env.PYTEST_ARGUMENTS }} \
483+
--cov-report=xml:ubuntu-v22.2.0-local.xml
483484
484485
- uses: codecov/codecov-action@v3
485486
name: "Upload coverage to Codecov"
@@ -546,10 +547,9 @@ jobs:
546547
run: |
547548
set PYMAPDL_PORT=
548549
set PYMAPDL_START_INSTANCE=
549-
python -m pytest -v -k "not test_database and not test_dpf" \
550-
--durations=10 \
551-
--maxfail=3 --reruns 7 --reruns-delay 5 \
552-
--cov=ansys.mapdl.core --cov-report=xml:windows-v22.2.0-local.xml --cov-report=html
550+
python -m pytest -k "not test_database and not test_dpf" \
551+
${{ env.PYTEST_ARGUMENTS }} \
552+
--cov-report=xml:windows-v22.2.0-local.xml
553553
554554
- uses: codecov/codecov-action@v3
555555
name: "Upload coverage to Codecov"

src/ansys/mapdl/core/_commands/apdl/array_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ def vwrite(
14811481
"""
14821482
# cannot be in interactive mode
14831483
if not self._store_commands:
1484-
raise RuntimeError(
1484+
raise MapdlRuntimeError(
14851485
"VWRTIE cannot run interactively. \n\nPlease use "
14861486
"``with mapdl.non_interactive:``"
14871487
)

src/ansys/mapdl/core/_commands/session/run_controls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
session, including the jobname, Graphical User Interface behavior, and
33
file switching.
44
"""
5+
from ansys.mapdl.core.errors import MapdlRuntimeError
56

67

78
class RunControls:
@@ -143,7 +144,7 @@ def cwd(self, dirpath="", **kwargs):
143144
"""
144145
dirpath = str(dirpath)
145146
if not (dirpath.startswith("'") and dirpath.endswith("'")) and "'" in dirpath:
146-
raise RuntimeError(
147+
raise MapdlRuntimeError(
147148
'The CWD command does not accept paths that contain singular quotes "'
148149
)
149150
return self.run(f"/CWD,'{dirpath}'", **kwargs)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from ansys.api.mapdl.v0 import mapdl_db_pb2_grpc
1010
import grpc
1111

12+
from ansys.mapdl.core.errors import MapdlConnectionError
13+
1214
from ..mapdl_grpc import MapdlGrpc
1315

1416
VALID_MAPDL_VERSIONS = [21.1, 21.2, 22.1, 22.2]
@@ -264,7 +266,7 @@ def start(self, timeout=10):
264266
time.sleep(0.01)
265267

266268
if not self._state._matured: # pragma: no cover
267-
raise RuntimeError(
269+
raise MapdlConnectionError(
268270
"Unable to establish connection to MAPDL database server"
269271
)
270272
self._mapdl._log.debug("Established connection to MAPDL database server")

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from ansys.api.mapdl.v0 import mapdl_db_pb2
1010

11+
from ansys.mapdl.core.errors import MapdlRuntimeError
12+
1113
from . import DBDef, MapdlDb, check_mapdl_db_is_alive
1214

1315

@@ -130,7 +132,9 @@ def next(self):
130132
131133
"""
132134
if self._itelm == -1:
133-
raise RuntimeError("You first have to call the `DbElems.first` method.")
135+
raise MapdlRuntimeError(
136+
"You first have to call the `DbElems.first` method."
137+
)
134138

135139
request = mapdl_db_pb2.ElmRequest(next=self._itelm)
136140
result = self._db._stub.ElmNext(request)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import numpy as np
1212
from numpy.lib import recfunctions
1313

14+
from ansys.mapdl.core.errors import MapdlRuntimeError
15+
1416
from ..common_grpc import DEFAULT_CHUNKSIZE
1517
from .database import DBDef, MapdlDb, check_mapdl_db_is_alive
1618

@@ -157,7 +159,9 @@ def next(self):
157159
158160
"""
159161
if self._itnod == -1:
160-
raise RuntimeError("You first have to call the `DbNodes.first` method.")
162+
raise MapdlRuntimeError(
163+
"You first have to call the `DbNodes.first` method."
164+
)
161165

162166
request = mapdl_db_pb2.NodRequest(next=self._itnod)
163167
result = self._db._stub.NodNext(request)

src/ansys/mapdl/core/inline_functions/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _run_query(self, command: str, integer: bool) -> Union[int, float]:
5959

6060
# non_interactive mode won't work with these commands
6161
if self._mapdl._store_commands:
62-
raise RuntimeError(
62+
raise MapdlRuntimeError(
6363
"Inline MAPDL functions are incompatible with the "
6464
"non_interactive mode."
6565
)
@@ -69,7 +69,7 @@ def _run_query(self, command: str, integer: bool) -> Union[int, float]:
6969
if isinstance(self._mapdl, MapdlGrpc):
7070
value = self._mapdl.scalar_param(QUERY_NAME)
7171
if value is None:
72-
raise RuntimeError(resp)
72+
raise MapdlRuntimeError(resp)
7373
if integer:
7474
return int(value)
7575
return value

src/ansys/mapdl/core/launcher.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
from ansys.mapdl import core as pymapdl
2626
from ansys.mapdl.core import LINUX_DEFAULT_DIRS, LOG
2727
from ansys.mapdl.core._version import SUPPORTED_ANSYS_VERSIONS
28-
from ansys.mapdl.core.errors import LockFileException, MapdlDidNotStart, VersionError
28+
from ansys.mapdl.core.errors import (
29+
LockFileException,
30+
MapdlDidNotStart,
31+
MapdlRuntimeError,
32+
VersionError,
33+
)
2934
from ansys.mapdl.core.licensing import ALLOWABLE_LICENSES, LicenseChecker
3035
from ansys.mapdl.core.mapdl import _MapdlCore
3136
from ansys.mapdl.core.mapdl_grpc import MAX_MESSAGE_LENGTH, MapdlGrpc
@@ -141,7 +146,7 @@ def _version_from_path(path):
141146
# replace \\ with / to account for possible windows path
142147
matches = re.findall(r"v(\d\d\d).ansys", path.replace("\\", "/"), re.IGNORECASE)
143148
if not matches:
144-
raise RuntimeError(f"Unable to extract Ansys version from {path}")
149+
raise MapdlRuntimeError(f"Unable to extract Ansys version from {path}")
145150
return int(matches[-1])
146151

147152

@@ -1876,7 +1881,7 @@ def launch_mapdl(
18761881
os.mkdir(run_location)
18771882
LOG.debug("Created run location at %s", run_location)
18781883
except:
1879-
raise RuntimeError(
1884+
raise MapdlRuntimeError(
18801885
"Unable to create the temporary working "
18811886
f'directory "{run_location}"\n'
18821887
"Please specify run_location="

src/ansys/mapdl/core/mapdl.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def solution(self):
503503
>>> mapdl.solution.converged
504504
"""
505505
if self._exited:
506-
raise RuntimeError("MAPDL exited.")
506+
raise MapdlRuntimeError("MAPDL exited.")
507507
return self._solution
508508

509509
@property
@@ -526,7 +526,7 @@ def post_processing(self):
526526
5.70333124e-05, 8.58600402e-05, 1.07445726e-04])
527527
"""
528528
if self._exited:
529-
raise RuntimeError(
529+
raise MapdlRuntimeError(
530530
"MAPDL exited.\n\nCan only postprocess a live " "MAPDL instance."
531531
)
532532
return self._post
@@ -560,7 +560,7 @@ def chain_commands(self):
560560
561561
"""
562562
if self._distributed:
563-
raise RuntimeError(
563+
raise MapdlRuntimeError(
564564
"Chained commands are not permitted in distributed ansys."
565565
)
566566
return self._chain_commands(self)
@@ -972,7 +972,7 @@ def open_apdl_log(self, filename, mode="w"):
972972
>>> mapdl.open_apdl_log("log.inp")
973973
"""
974974
if self._apdl_log is not None:
975-
raise RuntimeError("APDL command logging already enabled")
975+
raise MapdlRuntimeError("APDL command logging already enabled")
976976
self._log.debug("Opening ANSYS log file at %s", filename)
977977

978978
if mode not in ["w", "a", "x"]:
@@ -1041,7 +1041,7 @@ def open_gui(self, include_result=None, inplace=None): # pragma: no cover
10411041
from ansys.mapdl.core.launcher import get_ansys_path
10421042

10431043
if not self._local:
1044-
raise RuntimeError(
1044+
raise MapdlRuntimeError(
10451045
"``open_gui`` can only be called from a local MAPDL instance."
10461046
)
10471047

@@ -2055,7 +2055,9 @@ def result(self) -> "ansys.mapdl.reader.rst.Result":
20552055
result = Result(result_path, read_mesh=False)
20562056
if result._is_cyclic:
20572057
if not os.path.isfile(self._result_file):
2058-
raise RuntimeError("Distributed Cyclic result not supported")
2058+
raise MapdlRuntimeError(
2059+
"Distributed Cyclic result not supported"
2060+
)
20592061
result_path = self._result_file
20602062
else:
20612063
result_path = self._result_file
@@ -2862,13 +2864,13 @@ def run(self, command, write_to_log=True, mute=None, **kwargs) -> str:
28622864
)
28632865

28642866
if command[:3].upper() in INVAL_COMMANDS:
2865-
exception = RuntimeError(
2867+
exception = MapdlRuntimeError(
28662868
'Invalid PyMAPDL command "%s"\n\n%s'
28672869
% (command, INVAL_COMMANDS[command[:3].upper()])
28682870
)
28692871
raise exception
28702872
elif command[:4].upper() in INVAL_COMMANDS:
2871-
exception = RuntimeError(
2873+
exception = MapdlRuntimeError(
28722874
'Invalid PyMAPDL command "%s"\n\n%s'
28732875
% (command, INVAL_COMMANDS[command[:4].upper()])
28742876
)
@@ -3341,7 +3343,7 @@ def get_array(
33413343
while arr.size == 1 and arr[0] == -1:
33423344
arr = self._get_array(entity, entnum, item1, it1num, item2, it2num, kloop)
33433345
if ntry > 5:
3344-
raise RuntimeError("Unable to get array for %s" % entity)
3346+
raise MapdlRuntimeError("Unable to get array for %s" % entity)
33453347
ntry += 1
33463348
return arr
33473349

src/ansys/mapdl/core/mapdl_console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import time
88

9-
from ansys.mapdl.core.errors import MapdlExitedError
9+
from ansys.mapdl.core.errors import MapdlExitedError, MapdlRuntimeError
1010

1111
# from ansys.mapdl.core.misc import kill_process
1212
from ansys.mapdl.core.mapdl import _MapdlCore
@@ -186,7 +186,7 @@ def _run(self, command, **kwargs):
186186
ready_items[i].decode("utf-8"),
187187
)
188188
self._log.info(response + ready_items[i].decode("utf-8"))
189-
raise RuntimeError(
189+
raise MapdlRuntimeError(
190190
"User input expected. " "Try using ``with mapdl.non_interactive``"
191191
)
192192
else: # continue item

0 commit comments

Comments
 (0)