|
| 1 | +# Copyright Iris contributors |
| 2 | +# |
| 3 | +# This file is part of Iris and is released under the LGPL license. |
| 4 | +# See COPYING and COPYING.LESSER in the root of the repository for full |
| 5 | +# licensing details. |
| 6 | +"""Unit tests for the `iris.plot._get_plot_objects` function.""" |
| 7 | + |
| 8 | +# Import iris.tests first so that some things can be initialised before |
| 9 | +# importing anything else. |
| 10 | +import iris.tests as tests # isort:skip |
| 11 | + |
| 12 | +import iris.cube |
| 13 | + |
| 14 | +if tests.MPL_AVAILABLE: |
| 15 | + from iris.plot import _get_plot_objects |
| 16 | + |
| 17 | + |
| 18 | +@tests.skip_plot |
| 19 | +class Test__get_plot_objects(tests.IrisTest): |
| 20 | + def test_scalar(self): |
| 21 | + cube1 = iris.cube.Cube(1) |
| 22 | + cube2 = iris.cube.Cube(1) |
| 23 | + expected = (cube1, cube2, 1, 1, ()) |
| 24 | + result = _get_plot_objects((cube1, cube2)) |
| 25 | + self.assertTupleEqual(expected, result) |
| 26 | + |
| 27 | + def test_mismatched_size_first_scalar(self): |
| 28 | + cube1 = iris.cube.Cube(1) |
| 29 | + cube2 = iris.cube.Cube([1, 42]) |
| 30 | + with self.assertRaisesRegex( |
| 31 | + ValueError, "x and y-axis objects are not compatible" |
| 32 | + ): |
| 33 | + _get_plot_objects((cube1, cube2)) |
| 34 | + |
| 35 | + def test_mismatched_size_second_scalar(self): |
| 36 | + cube1 = iris.cube.Cube(1) |
| 37 | + cube2 = iris.cube.Cube([1, 42]) |
| 38 | + with self.assertRaisesRegex( |
| 39 | + ValueError, "x and y-axis objects are not compatible" |
| 40 | + ): |
| 41 | + _get_plot_objects((cube2, cube1)) |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + tests.main() |
0 commit comments