mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
#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.
This commit is contained in:
1 parent
5e791353b2
commit
ebf75c09a1
28 files changed
+889
-26
No files matched your search
@@ -2,6 +2,8 @@ import sys
|
||||
import os
|
||||
import math
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(1, os.path.join(sys.path[0], "../../"))
|
||||
import rips
|
||||
|
||||
@@ -65,3 +67,67 @@ def test_add_folders_and_polygons(rips_instance, initialize_test):
|
||||
assert [p.name for p in folder_a.polygons()] == ["A poly"]
|
||||
assert [p.name for p in folder_b.polygons()] == []
|
||||
assert [p.name for p in nested.polygons()] == ["nested poly"]
|
||||
|
||||
|
||||
def test_polygon_name_uniqueness(rips_instance, initialize_test):
|
||||
rips_instance.project.open(
|
||||
dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp"
|
||||
)
|
||||
|
||||
root = rips_instance.project.descendants(rips.PolygonCollection)[0]
|
||||
|
||||
coordinates = [
|
||||
[0.0, 0.0, -1000.0],
|
||||
[100.0, 0.0, -1000.0],
|
||||
[100.0, 100.0, -1000.0],
|
||||
[0.0, 100.0, -1000.0],
|
||||
]
|
||||
|
||||
root.create_polygon(name="Fence", coordinates=coordinates)
|
||||
|
||||
# The default policy is to fail on a name already used in the same folder
|
||||
with pytest.raises(rips.RipsError, match="already exists"):
|
||||
root.create_polygon(name="Fence", coordinates=coordinates)
|
||||
|
||||
renamed = root.create_polygon(
|
||||
name="Fence",
|
||||
coordinates=coordinates,
|
||||
on_name_conflict=rips.NameConflictPolicy.AUTO_RENAME,
|
||||
)
|
||||
assert renamed.name == "Fence_1"
|
||||
|
||||
# Names are case sensitive, so this is not a conflict
|
||||
other_case = root.create_polygon(name="fence", coordinates=coordinates)
|
||||
assert other_case.name == "fence"
|
||||
|
||||
overwritten = root.create_polygon(
|
||||
name="Fence",
|
||||
coordinates=coordinates,
|
||||
on_name_conflict=rips.NameConflictPolicy.OVERWRITE,
|
||||
)
|
||||
assert overwritten.name == "Fence"
|
||||
assert [p.name for p in root.polygons()].count("Fence") == 1
|
||||
|
||||
# A different folder is a separate namespace
|
||||
folder = root.add_folder(folder_name="Folder A")
|
||||
in_folder = folder.create_polygon(name="Fence", coordinates=coordinates)
|
||||
assert in_folder.name == "Fence"
|
||||
|
||||
|
||||
def test_folder_name_uniqueness(rips_instance, initialize_test):
|
||||
rips_instance.project.open(
|
||||
dataroot.PATH + "/TEST10K_FLT_LGR_NNC/10KWithWellLog.rsp"
|
||||
)
|
||||
|
||||
root = rips_instance.project.descendants(rips.PolygonCollection)[0]
|
||||
|
||||
root.add_folder(folder_name="Folder A")
|
||||
|
||||
with pytest.raises(rips.RipsError, match="already exists"):
|
||||
root.add_folder(folder_name="Folder A")
|
||||
|
||||
renamed = root.add_folder(
|
||||
folder_name="Folder A",
|
||||
on_name_conflict=rips.NameConflictPolicy.AUTO_RENAME,
|
||||
)
|
||||
assert renamed.polygon_collection_name == "Folder A_1"
|
||||
@@ -16,8 +16,8 @@ import rips
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project(rips_instance):
|
||||
"""Get the current project."""
|
||||
def project(rips_instance, initialize_test):
|
||||
"""Get the current project, reset between tests so each gets a clean polygon collection."""
|
||||
return rips_instance.project
|
||||
|
||||
|
||||
|
||||
@@ -156,3 +156,38 @@ def test_create_regular_surface_invalid_values(rips_instance, initialize_test):
|
||||
|
||||
with pytest.raises(rips.RipsError, match="Invalid rotation."):
|
||||
surface_collection.new_regular_surface(rotation=-1.0)
|
||||
|
||||
|
||||
def test_surface_name_uniqueness(rips_instance, initialize_test):
|
||||
case_path = dataroot.PATH + "/Case_with_10_timesteps/Real0/BRUGGE_0000.EGRID"
|
||||
rips_instance.project.load_case(path=case_path)
|
||||
|
||||
surface_collection = rips_instance.project.descendants(rips.SurfaceCollection)[0]
|
||||
|
||||
surface_collection.new_regular_surface(name="Top")
|
||||
|
||||
# The default policy is to fail on a name already used in the same folder
|
||||
with pytest.raises(rips.RipsError, match="already exists"):
|
||||
surface_collection.new_regular_surface(name="Top")
|
||||
|
||||
renamed = surface_collection.new_regular_surface(
|
||||
name="Top", on_name_conflict=rips.NameConflictPolicy.AUTO_RENAME
|
||||
)
|
||||
assert renamed.surface_user_description == "Top_1"
|
||||
|
||||
# Names are case sensitive, so this is not a conflict
|
||||
other_case = surface_collection.new_regular_surface(name="top")
|
||||
assert other_case.surface_user_description == "top"
|
||||
|
||||
overwritten = surface_collection.new_regular_surface(
|
||||
name="Top", on_name_conflict=rips.NameConflictPolicy.OVERWRITE
|
||||
)
|
||||
assert overwritten.surface_user_description == "Top"
|
||||
|
||||
names = [s.surface_user_description for s in surface_collection.surfaces_field()]
|
||||
assert names.count("Top") == 1
|
||||
|
||||
# A different folder is a separate namespace
|
||||
folder = surface_collection.add_folder(folder_name="Folder A")
|
||||
in_folder = folder.new_regular_surface(name="Top")
|
||||
assert in_folder.surface_user_description == "Top"
|
||||
Reference in new issue
Block a user