(self, create_test_datatree)
| 462 | assert_identical(expected, actual) |
| 463 | |
| 464 | def test_deepcopy(self, create_test_datatree) -> None: |
| 465 | dt = create_test_datatree() |
| 466 | |
| 467 | for node in dt.root.subtree: |
| 468 | node.attrs["Test"] = [1, 2, 3] |
| 469 | |
| 470 | for copied in [dt.copy(deep=True), deepcopy(dt)]: |
| 471 | assert_identical(dt, copied) |
| 472 | |
| 473 | for node, copied_node in zip( |
| 474 | dt.root.subtree, copied.root.subtree, strict=True |
| 475 | ): |
| 476 | assert node.encoding == copied_node.encoding |
| 477 | # Note: IndexVariable objects with string dtype are always |
| 478 | # copied because of xarray.core.util.safe_cast_to_index. |
| 479 | # Limiting the test to data variables. |
| 480 | for k in node.data_vars: |
| 481 | v0 = node.variables[k] |
| 482 | v1 = copied_node.variables[k] |
| 483 | assert source_ndarray(v0.data) is not source_ndarray(v1.data) |
| 484 | copied_node["foo"] = xr.DataArray(data=np.arange(5), dims="z") |
| 485 | assert "foo" not in node |
| 486 | |
| 487 | copied_node.attrs["foo"] = "bar" |
| 488 | assert "foo" not in node.attrs |
| 489 | assert node.attrs["Test"] is not copied_node.attrs["Test"] |
| 490 | |
| 491 | @pytest.mark.xfail(reason="data argument not yet implemented") |
| 492 | def test_copy_with_data(self, create_test_datatree) -> None: |
nothing calls this directly
no test coverage detected