Skip to content

Commit ad97ab1

Browse files
fix: prevent the creation of empty named selections (#2063)
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
1 parent 33a3df2 commit ad97ab1

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

doc/changelog.d/2063.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prevent the creation of empty named selections

src/ansys/geometry/core/designer/design.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,20 @@ def create_named_selection(
629629
-------
630630
NamedSelection
631631
Newly created named selection that maintains references to all target entities.
632+
633+
Raises
634+
------
635+
ValueError
636+
If no entities are provided for the named selection. At least
637+
one of the optional parameters must be provided.
632638
"""
639+
# Verify that at least one entity is provided
640+
if not any([bodies, faces, edges, beams, design_points]):
641+
raise ValueError(
642+
"At least one of the following must be provided: "
643+
"bodies, faces, edges, beams, or design_points."
644+
)
645+
633646
named_selection = NamedSelection(
634647
name,
635648
self,

tests/integration/test_design.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,22 @@ def test_named_selections(modeler: Modeler):
490490
assert len(design.named_selections) == 3
491491

492492

493+
def test_empty_named_selection(modeler: Modeler):
494+
"""Test for verifying the creation of an empty ``NamedSelection``."""
495+
# Create your design on the server side
496+
design = modeler.create_design("EmptyNamedSelection_Test")
497+
498+
# Attempting to create an empty NamedSelection raises an error
499+
with pytest.raises(ValueError, match="At least one of the following must be provided:"):
500+
design.create_named_selection("EmptyNS")
501+
502+
# Make sure that passing empty lists also raises an error
503+
with pytest.raises(ValueError, match="At least one of the following must be provided:"):
504+
design.create_named_selection(
505+
"EmptyNS2", bodies=[], faces=[], edges=[], beams=[], design_points=[]
506+
)
507+
508+
493509
def test_named_selection_contents(modeler: Modeler):
494510
"""Test for verifying the correct contents of a ``NamedSelection``."""
495511
# Create your design on the server side

0 commit comments

Comments
 (0)