Skip to content

Commit 01a50a4

Browse files
fix: missing pool name in test (#3773)
* feat: adding assert and patching exit * fix: syntax error in docstring * refactor: change a bit arguments default * refactor: simplifying code * chore: adding changelog file 3773.fixed.md [dependabot-skip] * refactor: clarify comment and clean up test assertions --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 1b12f7d commit 01a50a4

5 files changed

Lines changed: 31 additions & 18 deletions

File tree

doc/changelog.d/3773.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fix: missing pool name in test

src/ansys/mapdl/core/component.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,15 @@ class ComponentManager:
205205
206206
>>> mapdl.components["mycomp4"] = (1, 2, 3)
207207
/Users/german.ayuso/pymapdl/src/ansys/mapdl/core/component.py:282: UserWarning: Assuming a NODES selection.
208+
209+
This assumes you are doing a NODES selection.
208210
It is recommended you use the following notation to avoid this warning:
209-
\>\>\> mapdl.components['mycomp3'] = 'NODES', (1, 2, 3)
211+
212+
>>> mapdl.components['mycomp3'] = 'NODES', (1, 2, 3)
213+
210214
Alternatively, you disable this warning using:
211-
> mapdl.components.default_entity_warning=False
212-
warnings.warn(
215+
216+
>>> mapdl.components.default_entity_warning=False
213217
214218
You can change the default type by changing
215219
:attr:`Mapdl.components.default_entity <ansys.mapdl.core.Mapdl.components.default_entity>`

src/ansys/mapdl/core/mesh_grpc.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,8 @@ def nnum_all(self) -> np.ndarray:
418418

419419
nnum = self._mapdl.get_array("NODE", item1="NLIST")
420420
nnum = nnum.astype(np.int32)
421-
if nnum.size == 1:
422-
if nnum[0] == 0:
423-
nnum = np.empty(0, np.int32)
421+
if nnum.size == 1 and nnum[0] == 0:
422+
nnum = np.empty(0, np.int32)
424423

425424
self._ignore_cache_reset = False
426425

@@ -441,9 +440,8 @@ def enum_all(self) -> np.ndarray:
441440

442441
enum = self._mapdl.get_array("ELEM", item1="ELIST")
443442
enum = enum.astype(np.int32)
444-
if enum.size == 1:
445-
if enum[0] == 0:
446-
enum = np.empty(0, np.int32)
443+
if enum.size == 1 and enum[0] == 0:
444+
enum = np.empty(0, np.int32)
447445

448446
self._ignore_cache_reset = False
449447
return enum
@@ -551,7 +549,7 @@ def nodes_rotation(self):
551549
"""Returns an array of node rotations"""
552550
return self._mapdl.nlist(kinternal="").to_array()[:, 4:]
553551

554-
def _load_nodes(self, chunk_size=DEFAULT_CHUNKSIZE):
552+
def _load_nodes(self, chunk_size=None):
555553
"""Loads nodes from server.
556554
557555
Parameters
@@ -565,8 +563,8 @@ def _load_nodes(self, chunk_size=DEFAULT_CHUNKSIZE):
565563
np.ndarray
566564
Numpy array of nodes
567565
"""
568-
if self._chunk_size:
569-
chunk_size = self._chunk_size
566+
if not chunk_size:
567+
chunk_size = self._chunk_size or DEFAULT_CHUNKSIZE
570568

571569
request = anskernel.StreamRequest(chunk_size=chunk_size)
572570
chunks = self._mapdl._stub.Nodes(request)
@@ -606,7 +604,7 @@ def _elem_off(self):
606604
def _elem_off(self, value):
607605
self._cache_elem_off = value
608606

609-
def _load_elements_offset(self, chunk_size=DEFAULT_CHUNKSIZE):
607+
def _load_elements_offset(self, chunk_size=None):
610608
"""Loads elements from server
611609
612610
Parameters
@@ -639,8 +637,8 @@ def _load_elements_offset(self, chunk_size=DEFAULT_CHUNKSIZE):
639637
Array of indices indicating the start of each element.
640638
641639
"""
642-
if self._chunk_size:
643-
chunk_size = self._chunk_size
640+
if not chunk_size:
641+
chunk_size = self._chunk_size or DEFAULT_CHUNKSIZE
644642

645643
request = anskernel.StreamRequest(chunk_size=chunk_size)
646644
chunks = self._mapdl._stub.LoadElements(request)
@@ -664,7 +662,7 @@ def _load_elements_offset(self, chunk_size=DEFAULT_CHUNKSIZE):
664662
elems_[indx_elem] = self.enum
665663
return elems_, offset
666664

667-
def _load_element_types(self, chunk_size=DEFAULT_CHUNKSIZE):
665+
def _load_element_types(self, chunk_size=None):
668666
"""Loads element types from the MAPDL server.
669667
670668
Returns
@@ -677,6 +675,9 @@ def _load_element_types(self, chunk_size=DEFAULT_CHUNKSIZE):
677675
int
678676
Size of the chunks to request from the server.
679677
"""
678+
if not chunk_size:
679+
chunk_size = self._chunk_size or DEFAULT_CHUNKSIZE
680+
680681
request = anskernel.StreamRequest(chunk_size=chunk_size)
681682
chunks = self._mapdl._stub.LoadElementTypeDescription(request)
682683
data = parse_chunks(chunks, np.int32)

src/ansys/mapdl/core/pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def __init__(
340340
for i, (ip, port) in enumerate(zip(ips, ports))
341341
]
342342

343-
# Storing
343+
# Storing threads
344344
self._threads = threads
345345

346346
if wait:

tests/test_pool.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ def test_directory_names_custom_string(self, tmpdir):
320320
"ansys.mapdl.core.pool.MapdlPool.__del__",
321321
lambda *args, **kwargs: None,
322322
)
323+
@patch(
324+
"ansys.mapdl.core.pool.MapdlPool.exit",
325+
lambda *args, **kwargs: None,
326+
)
323327
def test_directory_names_function(self, tmpdir):
324328
def myfun(i):
325329
if i == 0:
@@ -336,7 +340,7 @@ def myfun(i):
336340
names=myfun,
337341
run_location=tmpdir,
338342
additional_switches=QUICK_LAUNCH_SWITCHES,
339-
wait=False,
343+
wait=True,
340344
restart_failed=False,
341345
)
342346

@@ -345,6 +349,9 @@ def myfun(i):
345349
assert "instance_one" in dirs_path_pool
346350
assert "Other_instance" in dirs_path_pool
347351

352+
pool.exit()
353+
del pool
354+
348355
def test_num_instances(self):
349356
with pytest.raises(ValueError, match="least 1 instance"):
350357
pool = MapdlPool(

0 commit comments

Comments
 (0)