|
20 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | 21 | # SOFTWARE. |
22 | 22 |
|
| 23 | +import numpy as np |
23 | 24 | import pytest |
24 | 25 |
|
25 | 26 | from ansys.acp.core import FabricWithAngle, recursive_copy |
@@ -197,3 +198,32 @@ def test_missing_parent_object_raises(minimal_complete_model): |
197 | 198 | msg = str(exc_info.value) |
198 | 199 | assert "Parent object" in msg |
199 | 200 | assert "parent_mapping" in msg |
| 201 | + |
| 202 | + |
| 203 | +def test_copy_lookup_table_with_columns(minimal_complete_model): |
| 204 | + """Test copying lookup tables with columns and their data. |
| 205 | +
|
| 206 | + This case is special because LUT implement a check for the shape |
| 207 | + of the data in their columns, which is determined by the "Location" |
| 208 | + column. |
| 209 | + """ |
| 210 | + # GIVEN: a model which has objects with sub-attributes |
| 211 | + # (here: a lookup table with columns) |
| 212 | + model = minimal_complete_model |
| 213 | + lut = model.create_lookup_table_1d() |
| 214 | + lut.columns["Location"].data = [1.0, 2.0, 3.0] |
| 215 | + lut.create_column(name="column1", data=[4.0, 5.0, 6.0]) |
| 216 | + |
| 217 | + # WHEN: recursively copying the lookup table |
| 218 | + new_objects = recursive_copy(source_objects=[lut], parent_mapping=[(model, model)]) |
| 219 | + |
| 220 | + # THEN: the expected new objects are created, but the sub-attributes are |
| 221 | + # not explicitly copied |
| 222 | + assert len(new_objects) == 2 |
| 223 | + assert {obj.id for obj in new_objects} == { # type: ignore |
| 224 | + "LookUpTable1D.2", |
| 225 | + "column1", |
| 226 | + } |
| 227 | + new_lut = model.lookup_tables_1d["LookUpTable1D.2"] |
| 228 | + assert np.allclose(new_lut.columns["Location"].data, [1.0, 2.0, 3.0]) |
| 229 | + assert np.allclose(new_lut.columns["column1"].data, [4.0, 5.0, 6.0]) |
0 commit comments