Files
ResInsight/GrpcInterface/Python/rips/tests/test_polygon_appearance.py
T
Magne Sjaastad ebf75c09a1 #14411 Enforce name uniqueness for surfaces, polygons and folders
* #14411 Enforce name uniqueness for surfaces, polygons and folders

Names must be unique among siblings sharing the same parent folder. Items in different folders may keep identical names, and comparison is case sensitive.

Siblings are the objects held by the same caf::PdmChildArrayField. Items and folders live in two distinct child arrays in caf::PdmNestedCollection, so a folder and an item may share a name under the same parent.

The Python API gets an OnNameConflict flag on AddFolder, CreatePolygon, ImportSurface and NewRegularSurface, supporting FAIL (default), AUTO_RENAME and OVERWRITE. NewSurface is left out, as grid case surfaces derive their tree label from the case and K index and carry no name of their own.
2026-08-07 08:34:58 +02:00

121 lines
3.8 KiB
Python

"""
Tests for polygon appearance functionality.
These tests verify that polygon appearance properties can be read and modified
via the Python API.
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import rips
@pytest.fixture
def project(rips_instance, initialize_test):
"""Get the current project, reset between tests so each gets a clean polygon collection."""
return rips_instance.project
class TestPolygonAppearance:
"""Tests for PolygonAppearance functionality."""
@pytest.fixture
def polygon(self, project):
"""Create a test polygon."""
polygon_collection = project.descendants(rips.PolygonCollection)[0]
coordinates = [
[100.0, 200.0, 300.0],
[200.0, 200.0, 300.0],
[200.0, 300.0, 300.0],
[100.0, 300.0, 300.0],
]
p = polygon_collection.create_polygon(
name="Test Polygon", coordinates=coordinates
)
return p
def test_access_appearance(self, polygon):
"""Test that appearance child object is accessible."""
appearance = polygon.appearance()
assert appearance is not None, "Appearance should be accessible"
def test_default_values(self, polygon):
"""Test that default appearance values are correct."""
appearance = polygon.appearance()
assert appearance.is_closed is True
assert appearance.show_lines is True
assert appearance.show_spheres is False
assert appearance.line_thickness == 3
assert appearance.lock_polygon is False
def test_set_line_color(self, polygon):
"""Test setting line color."""
appearance = polygon.appearance()
appearance.line_color = "#ff0000"
appearance.update()
# Re-read to verify persistence
appearance2 = polygon.appearance()
assert appearance2.line_color == "#ff0000"
def test_set_sphere_color(self, polygon):
"""Test setting sphere color."""
appearance = polygon.appearance()
appearance.sphere_color = "#00ff00"
appearance.update()
appearance2 = polygon.appearance()
assert appearance2.sphere_color == "#00ff00"
def test_set_line_thickness(self, polygon):
"""Test setting line thickness."""
appearance = polygon.appearance()
appearance.line_thickness = 5
appearance.update()
appearance2 = polygon.appearance()
assert appearance2.line_thickness == 5
def test_set_show_spheres(self, polygon):
"""Test toggling sphere visibility."""
appearance = polygon.appearance()
appearance.show_spheres = True
appearance.update()
appearance2 = polygon.appearance()
assert appearance2.show_spheres is True
def test_set_sphere_radius_factor(self, polygon):
"""Test setting sphere radius factor."""
appearance = polygon.appearance()
appearance.sphere_radius_factor = 0.5
appearance.update()
appearance2 = polygon.appearance()
assert abs(appearance2.sphere_radius_factor - 0.5) < 1e-6
def test_set_is_closed(self, polygon):
"""Test setting closed polygon state."""
appearance = polygon.appearance()
appearance.is_closed = False
appearance.update()
appearance2 = polygon.appearance()
assert appearance2.is_closed is False
def test_set_lock_polygon(self, polygon):
"""Test setting lock polygon to plane."""
appearance = polygon.appearance()
appearance.lock_polygon = True
appearance.polygon_plane_depth = 500.0
appearance.update()
appearance2 = polygon.appearance()
assert appearance2.lock_polygon is True
assert abs(appearance2.polygon_plane_depth - 500.0) < 1e-6