Skip to content

Commit c4165a9

Browse files
committed
Starting tests.
1 parent c8fa1b4 commit c4165a9

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright Iris contributors
2+
#
3+
# This file is part of Iris and is released under the BSD license.
4+
# See LICENSE in the root of the repository for full licensing details.
5+
"""Integration tests for merging with dataless cubes."""
6+
7+
import numpy as np
8+
9+
from iris.coords import AuxCoord, DimCoord
10+
from iris.cube import Cube, CubeList
11+
12+
13+
class TestMergeDataless:
14+
def _testcube(self, z=1, name="this", dataless=False):
15+
# Create a testcube with a scalar Z coord, for merge testing.
16+
cube = Cube(
17+
[1, 2, 3],
18+
dim_coords_and_dims=[(DimCoord([0.0, 1.0, 2], long_name="x"), 0)],
19+
aux_coords_and_dims=[(AuxCoord([z], long_name="z"), ())],
20+
)
21+
if dataless:
22+
cube.data = None
23+
return cube
24+
25+
def test_general_nomerge(self):
26+
# Check that normal merge works OK with dataless cubes included
27+
cubes = CubeList(
28+
[
29+
self._testcube(name="this", dataless=False),
30+
self._testcube(name="that", dataless=True),
31+
]
32+
)
33+
result = cubes.merge()
34+
assert len(result) == 2
35+
cube1, cube2 = [result.extract_cube(name) for name in ("this", "that")]
36+
assert not cube1.is_dataless()
37+
assert cube1.is_dataless()
38+
39+
def test_dataless_merge(self):
40+
# Check that dataless cubes can be merged correctly.
41+
cubes = CubeList(
42+
[
43+
self._testcube(z=1, dataless=True),
44+
self._testcube(z=2, dataless=True),
45+
]
46+
)
47+
cube = cubes.merge_cube()
48+
assert cube.is_dataless()
49+
assert np.all(cube.coord("z").points == [1, 2])
50+
51+
def test_dataless_dataful_merge(self):
52+
# Check that dataless cubes can merge **with** regular ones.
53+
# Check that dataless cubes can be merged correctly.
54+
cubes = CubeList(
55+
[
56+
self._testcube(z=1, dataless=False),
57+
self._testcube(z=2, dataless=True),
58+
]
59+
)
60+
cube = cubes.merge_cube()
61+
assert not cube.is_dataless()
62+
data_z1, data_z2 = cube[0].data, cube[1].data
63+
assert np.all(data_z1 == [1, 2, 3])
64+
assert np.all(np.ma.getmaskarray(data_z2) == True) # noqa: E712

0 commit comments

Comments
 (0)