Skip to content

Commit 7d132e7

Browse files
committed
Throw when trying to instantiate a post.Mesh with a None as MeshedRegion
1 parent c3ae713 commit 7d132e7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/ansys/dpf/post/mesh.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class Mesh:
2727

2828
def __init__(self, meshed_region: dpf.MeshedRegion):
2929
"""Initialize this class."""
30+
if meshed_region is None:
31+
raise ValueError("Tried to instantiate an empty Mesh.")
3032
self._meshed_region = meshed_region
3133

3234
def __str__(self):

tests/test_mesh.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import ansys.dpf.core as dpf
22
import numpy as np
3+
import pytest
34
from pytest import fixture
45

5-
from ansys.dpf.post import StaticMechanicalSimulation
6+
from ansys.dpf.post import Mesh, StaticMechanicalSimulation
67

78

89
@fixture
@@ -14,6 +15,8 @@ def mesh(static_rst):
1415
def test_mesh_core_object(mesh):
1516
assert isinstance(mesh._core_object, dpf.MeshedRegion)
1617
assert mesh._core_object.nodes.n_nodes == 81
18+
with pytest.raises(ValueError, match="Tried to instantiate an empty Mesh."):
19+
_ = Mesh(None)
1720

1821

1922
def test_mesh_node_ids(mesh):

0 commit comments

Comments
 (0)