-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_CreateConstantAttributePerRegion.py
More file actions
169 lines (156 loc) · 6.71 KB
/
test_CreateConstantAttributePerRegion.py
File metadata and controls
169 lines (156 loc) · 6.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Romain Baville
# SPDX-License-Identifier: Apache 2.0
# ruff: noqa: E402 # disable Module level import not at top of file
# mypy: disable-error-code="operator"
import pytest
from typing import Union, Any
from vtkmodules.vtkCommonDataModel import ( vtkDataSet, vtkMultiBlockDataSet )
from geos.processing.generic_processing_tools.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion
import numpy as np
@pytest.mark.parametrize(
"meshType, newAttributeName, regionName, dictRegionValues, componentNames, componentNamesTest, valueNpType",
[
# Test the name of the new attribute.
## For vtkDataSet.
( "dataset", "newAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32 ),
( "dataset", "CellAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32 ),
## For vtkMultiBlockDataSet.
( "multiblock", "newAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32 ),
( "multiblock", "CellAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32 ),
( "multiblock", "GLOBAL_IDS_CELLS", "GLOBAL_IDS_POINTS", {}, (), (), np.float32 ),
# Test if the region attribute is on cells or on points.
( "dataset", "newAttribute", "FAULT", {}, (), (), np.float32 ),
# Test the component name.
( "dataset", "newAttribute", "FAULT", {}, ( "X" ), (), np.float32 ),
( "dataset", "newAttribute", "FAULT", {}, (), ( "Component0", "Component1" ), np.float32 ),
( "dataset", "newAttribute", "FAULT", {}, ( "X" ), ( "Component0", "Component1" ), np.float32 ),
( "dataset", "newAttribute", "FAULT", {}, ( "X", "Y" ), ( "X", "Y" ), np.float32 ),
( "dataset", "newAttribute", "FAULT", {}, ( "X", "Y", "Z" ), ( "X", "Y" ), np.float32 ),
# Test the type of value.
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int8 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int16 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int32 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int64 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint8 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint16 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint32 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint64 ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.float64 ),
# Test index/value.
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ],
}, (), (), np.float32 ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ],
101: [ 2 ],
}, (), (), np.float32 ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ],
101: [ 2 ],
2: [ 3 ],
}, (), (), np.float32 ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ],
}, (), ( "Component0", "Component1" ), np.float32 ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ],
101: [ 2, 2 ],
}, (), ( "Component0", "Component1" ), np.float32 ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ],
101: [ 2, 2 ],
2: [ 3, 3 ],
}, (), ( "Component0", "Component1" ), np.float32 ),
] )
def test_CreateConstantAttributePerRegion(
dataSetTest: Union[ vtkMultiBlockDataSet, vtkDataSet ],
meshType: str,
newAttributeName: str,
regionName: str,
dictRegionValues: dict[ Any, Any ],
componentNames: tuple[ str, ...],
componentNamesTest: tuple[ str, ...],
valueNpType: int,
) -> None:
"""Test CreateConstantAttributePerRegion."""
mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] = dataSetTest( meshType )
nbComponents: int = len( componentNamesTest )
if nbComponents == 0: # If the attribute has one component, the component has no name.
nbComponents += 1
createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
regionName,
dictRegionValues,
newAttributeName,
valueNpType=valueNpType,
nbComponents=nbComponents,
componentNames=componentNames,
)
createConstantAttributePerRegionFilter.applyFilter()
@pytest.mark.parametrize(
"meshType, newAttributeName, regionName",
[
( "dataset", "newAttribute", "PERM" ), # Region attribute has too many components
( "multiblock", "newAttribute", "FAULT" ), # Region attribute is partial.
( "dataset", "PERM", "FAULT" ), # The attribute name already exist in the mesh.
] )
def test_CreateConstantAttributePerRegionRaisesAttributeError(
dataSetTest: Union[ vtkMultiBlockDataSet, vtkDataSet ],
meshType: str,
newAttributeName: str,
regionName: str,
) -> None:
"""Test the fails of CreateConstantAttributePerRegion with attributes issues."""
mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] = dataSetTest( meshType )
createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
regionName,
{},
newAttributeName,
)
with pytest.raises( AttributeError ):
createConstantAttributePerRegionFilter.applyFilter()
@pytest.mark.parametrize(
"dictRegionValues, componentNames",
[
( {
0: [ 0 ],
100: [ 1, 1 ],
}, () ), # Number of value inconsistent.
( {
0: [ 0, 0 ],
100: [ 1, 1 ],
}, () ), # More values than components.
( {
0: [ 0 ],
100: [ 1 ],
}, ( "X", "Y" ) ), # More components than value.
] )
def test_CreateConstantAttributePerRegionRaisesValueError(
dataSetTest: vtkDataSet,
dictRegionValues: dict[ Any, Any ],
componentNames: tuple[ str, ...],
) -> None:
"""Test the fails of CreateConstantAttributePerRegion with inputs value issues."""
mesh: vtkDataSet = dataSetTest( 'dataset' )
nbComponents: int = len( componentNames )
if nbComponents == 0: # If the attribute has one component, the component has no name.
nbComponents += 1
createConstantAttributePerRegionFilter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
"FAULT",
dictRegionValues,
"newAttribute",
nbComponents=nbComponents,
componentNames=componentNames,
)
with pytest.raises( ValueError ):
createConstantAttributePerRegionFilter.applyFilter()