|
25 | 25 | from iris.analysis import MEAN |
26 | 26 | from iris.aux_factory import HybridHeightFactory |
27 | 27 | from iris.cube import Cube |
28 | | -from iris.coords import AuxCoord, DimCoord, CellMeasure, AncillaryVariable |
| 28 | +from iris.coords import ( |
| 29 | + AuxCoord, |
| 30 | + DimCoord, |
| 31 | + CellMeasure, |
| 32 | + AncillaryVariable, |
| 33 | + CellMethod, |
| 34 | +) |
29 | 35 | from iris.exceptions import ( |
30 | 36 | CoordinateNotFoundError, |
31 | 37 | CellMeasureNotFoundError, |
@@ -1911,13 +1917,13 @@ def test_remove_aux_coord(self): |
1911 | 1917 | def test_remove_cell_measure(self): |
1912 | 1918 | self.cube.remove_cell_measure(self.cube.cell_measure("area")) |
1913 | 1919 | self.assertEqual( |
1914 | | - self.cube._cell_measures_and_dims, [[self.b_cell_measure, (0, 1)]] |
| 1920 | + self.cube._cell_measures_and_dims, [(self.b_cell_measure, (0, 1))] |
1915 | 1921 | ) |
1916 | 1922 |
|
1917 | 1923 | def test_remove_cell_measure_by_name(self): |
1918 | 1924 | self.cube.remove_cell_measure("area") |
1919 | 1925 | self.assertEqual( |
1920 | | - self.cube._cell_measures_and_dims, [[self.b_cell_measure, (0, 1)]] |
| 1926 | + self.cube._cell_measures_and_dims, [(self.b_cell_measure, (0, 1))] |
1921 | 1927 | ) |
1922 | 1928 |
|
1923 | 1929 | def test_fail_remove_cell_measure_by_name(self): |
@@ -2229,5 +2235,99 @@ def test_data_bool_not_eq(self): |
2229 | 2235 | self.assertFalse(cube1 == cube2) |
2230 | 2236 |
|
2231 | 2237 |
|
| 2238 | +class Test__eq__meta(tests.IrisTest): |
| 2239 | + def test_ancillary_fail(self): |
| 2240 | + cube1 = Cube([0, 1]) |
| 2241 | + cube2 = Cube([0, 1]) |
| 2242 | + avr = AncillaryVariable([2, 3], long_name="foo") |
| 2243 | + cube2.add_ancillary_variable(avr, 0) |
| 2244 | + self.assertFalse(cube1 == cube2) |
| 2245 | + |
| 2246 | + def test_ancillary_reorder(self): |
| 2247 | + cube1 = Cube([0, 1]) |
| 2248 | + cube2 = Cube([0, 1]) |
| 2249 | + avr1 = AncillaryVariable([2, 3], long_name="foo") |
| 2250 | + avr2 = AncillaryVariable([4, 5], long_name="bar") |
| 2251 | + # Add the same ancillary variables to cube1 and cube2 in |
| 2252 | + # opposite orders. |
| 2253 | + cube1.add_ancillary_variable(avr1, 0) |
| 2254 | + cube1.add_ancillary_variable(avr2, 0) |
| 2255 | + cube2.add_ancillary_variable(avr2, 0) |
| 2256 | + cube2.add_ancillary_variable(avr1, 0) |
| 2257 | + self.assertTrue(cube1 == cube2) |
| 2258 | + |
| 2259 | + def test_ancillary_diff_data(self): |
| 2260 | + cube1 = Cube([0, 1]) |
| 2261 | + cube2 = Cube([0, 1]) |
| 2262 | + avr1 = AncillaryVariable([2, 3], long_name="foo") |
| 2263 | + avr2 = AncillaryVariable([4, 5], long_name="foo") |
| 2264 | + cube1.add_ancillary_variable(avr1, 0) |
| 2265 | + cube2.add_ancillary_variable(avr2, 0) |
| 2266 | + self.assertFalse(cube1 == cube2) |
| 2267 | + |
| 2268 | + def test_cell_measure_fail(self): |
| 2269 | + cube1 = Cube([0, 1]) |
| 2270 | + cube2 = Cube([0, 1]) |
| 2271 | + cms = CellMeasure([2, 3], measure="area", long_name="foo") |
| 2272 | + cube2.add_cell_measure(cms, 0) |
| 2273 | + self.assertFalse(cube1 == cube2) |
| 2274 | + |
| 2275 | + def test_cell_measure_reorder(self): |
| 2276 | + cube1 = Cube([0, 1]) |
| 2277 | + cube2 = Cube([0, 1]) |
| 2278 | + cms1 = CellMeasure([2, 3], measure="area", long_name="foo") |
| 2279 | + cms2 = CellMeasure([4, 5], measure="area", long_name="bar") |
| 2280 | + # Add the same cell measure to cube1 and cube2 in |
| 2281 | + # opposite orders. |
| 2282 | + cube1.add_cell_measure(cms1, 0) |
| 2283 | + cube1.add_cell_measure(cms2, 0) |
| 2284 | + cube2.add_cell_measure(cms2, 0) |
| 2285 | + cube2.add_cell_measure(cms1, 0) |
| 2286 | + self.assertTrue(cube1 == cube2) |
| 2287 | + |
| 2288 | + def test_cell_measure_diff_data(self): |
| 2289 | + cube1 = Cube([0, 1]) |
| 2290 | + cube2 = Cube([0, 1]) |
| 2291 | + cms1 = CellMeasure([2, 3], measure="area", long_name="foo") |
| 2292 | + cms2 = CellMeasure([4, 5], measure="area", long_name="foo") |
| 2293 | + cube1.add_cell_measure(cms1, 0) |
| 2294 | + cube2.add_cell_measure(cms2, 0) |
| 2295 | + self.assertFalse(cube1 == cube2) |
| 2296 | + |
| 2297 | + def test_cell_method_fail(self): |
| 2298 | + cube1 = Cube([0, 1]) |
| 2299 | + cube2 = Cube([0, 1]) |
| 2300 | + cmth = CellMethod("mean", "time", "6hr") |
| 2301 | + cube2.add_cell_method(cmth) |
| 2302 | + self.assertFalse(cube1 == cube2) |
| 2303 | + |
| 2304 | + # Unlike cell measures, cell methods are order sensitive. |
| 2305 | + def test_cell_method_reorder_fail(self): |
| 2306 | + cube1 = Cube([0, 1]) |
| 2307 | + cube2 = Cube([0, 1]) |
| 2308 | + cmth1 = CellMethod("mean", "time", "6hr") |
| 2309 | + cmth2 = CellMethod("mean", "time", "12hr") |
| 2310 | + # Add the same cell method to cube1 and cube2 in |
| 2311 | + # opposite orders. |
| 2312 | + cube1.add_cell_method(cmth1) |
| 2313 | + cube1.add_cell_method(cmth2) |
| 2314 | + cube2.add_cell_method(cmth2) |
| 2315 | + cube2.add_cell_method(cmth1) |
| 2316 | + self.assertFalse(cube1 == cube2) |
| 2317 | + |
| 2318 | + def test_cell_method_correct_order(self): |
| 2319 | + cube1 = Cube([0, 1]) |
| 2320 | + cube2 = Cube([0, 1]) |
| 2321 | + cmth1 = CellMethod("mean", "time", "6hr") |
| 2322 | + cmth2 = CellMethod("mean", "time", "12hr") |
| 2323 | + # Add the same cell method to cube1 and cube2 in |
| 2324 | + # the same order. |
| 2325 | + cube1.add_cell_method(cmth1) |
| 2326 | + cube1.add_cell_method(cmth2) |
| 2327 | + cube2.add_cell_method(cmth1) |
| 2328 | + cube2.add_cell_method(cmth2) |
| 2329 | + self.assertTrue(cube1 == cube2) |
| 2330 | + |
| 2331 | + |
2232 | 2332 | if __name__ == "__main__": |
2233 | 2333 | tests.main() |
0 commit comments