|
25 | 25 | import pyvista as pv |
26 | 26 |
|
27 | 27 | from ansys.health.heart import __version__ |
28 | | -from ansys.health.heart.objects import Cap, Cavity, Mesh, SurfaceMesh |
| 28 | +from ansys.health.heart.objects import Cap, CapType, Cavity, Mesh, SurfaceMesh |
29 | 29 | from ansys.health.heart.parts import ( |
30 | 30 | Artery, |
31 | 31 | Atrium, |
@@ -287,3 +287,51 @@ def test_get_element_ids_returns_empty_if_volume_id_missing(caplog): |
287 | 287 | assert any( |
288 | 288 | "Mesh does not contain '_volume-id' cell data." in m for m in caplog.text.splitlines() |
289 | 289 | ) |
| 290 | + |
| 291 | + |
| 292 | +def test_set_from_dict_caps_with_unknown_type(): |
| 293 | + """Test _set_from_dict can handle caps with unknown/invalid cap types.""" |
| 294 | + # Setup: create a test dictionary with an invalid cap type |
| 295 | + part_name = "Left ventricle" |
| 296 | + test_dict = { |
| 297 | + part_name: { |
| 298 | + "part-id": 42, |
| 299 | + "part-type": "ventricle", |
| 300 | + "surfaces": { |
| 301 | + "Left ventricle endocardium": 1, |
| 302 | + "Left ventricle epicardium": 2, |
| 303 | + }, |
| 304 | + "_version": "0.15.dev0", |
| 305 | + "caps": { |
| 306 | + "unknown_cap_type": 100, # This should trigger the unknown cap handling |
| 307 | + "invalid-cap": 101, # Another invalid cap type |
| 308 | + }, |
| 309 | + } |
| 310 | + } |
| 311 | + |
| 312 | + # Create a mock mesh with the required surfaces and cap surfaces |
| 313 | + mesh = _get_mock_mesh1() |
| 314 | + |
| 315 | + # Add cap surfaces to the mesh for testing |
| 316 | + from pyvista.examples import load_tetbeam |
| 317 | + |
| 318 | + beam = load_tetbeam() |
| 319 | + surface = beam.extract_surface() |
| 320 | + mesh.add_surface(surface, name="unknown_cap_type", id=100) |
| 321 | + mesh.add_surface(surface, name="invalid-cap", id=101) |
| 322 | + |
| 323 | + # Act: reconstruct part from dictionary |
| 324 | + part = Part._set_from_dict(test_dict, mesh=mesh) |
| 325 | + |
| 326 | + # Assert: part should be created successfully |
| 327 | + assert isinstance(part, Ventricle) |
| 328 | + assert part.name == part_name |
| 329 | + assert part.pid == 42 |
| 330 | + |
| 331 | + # Assert: caps should be created with UNKNOWN type |
| 332 | + assert len(part.caps) == 2 |
| 333 | + |
| 334 | + for cap in part.caps: |
| 335 | + assert cap.type == CapType.UNKNOWN |
| 336 | + assert cap._mesh is not None |
| 337 | + assert cap.name in ["unknown_cap_type", "invalid-cap"] |
0 commit comments