Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/iris/tests/_shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,25 +926,25 @@ class MyGeoTiffTests(test.IrisTest):

skip_sample_data = pytest.mark.skipif(
not SAMPLE_DATA_AVAILABLE,
('Test(s) require "iris-sample-data", ' "which is not available."),
reason=('Test(s) require "iris-sample-data", ' "which is not available."),
)


skip_nc_time_axis = pytest.mark.skipif(
not NC_TIME_AXIS_AVAILABLE,
'Test(s) require "nc_time_axis", which is not available.',
reason='Test(s) require "nc_time_axis", which is not available.',
)


skip_inet = pytest.mark.skipif(
not INET_AVAILABLE,
('Test(s) require an "internet connection", ' "which is not available."),
reason=('Test(s) require an "internet connection", ' "which is not available."),
)


skip_stratify = pytest.mark.skipif(
not STRATIFY_AVAILABLE,
'Test(s) require "python-stratify", which is not available.',
reason='Test(s) require "python-stratify", which is not available.',
)


Expand Down
21 changes: 7 additions & 14 deletions lib/iris/tests/integration/plot/test_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Integration tests for :func:`iris.plot.animate`."""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

import numpy as np
import pytest

import iris
from iris.coord_systems import GeogCS
from iris.tests import _shared_utils

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import iris.plot as iplt


@tests.skip_plot
class IntegrationTest(tests.GraphicsTest):
def setUp(self):
super().setUp()
@_shared_utils.skip_plot
class IntegrationTest(_shared_utils.GraphicsTest):
@pytest.fixture(autouse=True)
def _setup(self):
cube = iris.cube.Cube(np.arange(36, dtype=np.int32).reshape((3, 3, 4)))
cs = GeogCS(6371229)

Expand Down Expand Up @@ -68,7 +65,3 @@ def test_cube_animation(self):
for anim, d in zip(ani, data):
anim._draw_next_frame(d, blit=False)
self.check_graphic()


if __name__ == "__main__":
tests.main()
49 changes: 17 additions & 32 deletions lib/iris/tests/integration/plot/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,24 @@
:func:`matplotlib.pyplot.colorbar`.

"""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

import numpy as np
import pytest

from iris.coords import AuxCoord
from iris.tests import _shared_utils
import iris.tests.stock

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import matplotlib.pyplot as plt

from iris.plot import contour, contourf, pcolor, pcolormesh, points, scatter


@tests.skip_plot
class TestColorBarCreation(tests.GraphicsTest):
def setUp(self):
super().setUp()
@_shared_utils.skip_plot
class TestColorBarCreation(_shared_utils.GraphicsTest):
@pytest.fixture(autouse=True)
def _setup(self):
self.draw_functions = (contour, contourf, pcolormesh, pcolor)
self.cube = iris.tests.stock.lat_lon_cube()
self.cube.coord("longitude").guess_bounds()
Expand All @@ -46,49 +43,37 @@ def test_common_draw_functions(self):
for draw_function in self.draw_functions:
mappable = draw_function(self.cube)
cbar = plt.colorbar()
self.assertIs(
cbar.mappable,
mappable,
msg="Problem with draw function iris.plot.{}".format(
draw_function.__name__
),
)
assert (
cbar.mappable is mappable
), "Problem with draw function iris.plot.{}".format(draw_function.__name__)

def test_common_draw_functions_specified_mappable(self):
for draw_function in self.draw_functions:
mappable_initial = draw_function(self.cube, cmap="cool")
_ = draw_function(self.cube)
cbar = plt.colorbar(mappable_initial)
self.assertIs(
cbar.mappable,
mappable_initial,
msg="Problem with draw function iris.plot.{}".format(
draw_function.__name__
),
)
assert (
cbar.mappable is mappable_initial
), "Problem with draw function iris.plot.{}".format(draw_function.__name__)

def test_points_with_c_kwarg(self):
mappable = points(self.cube, c=self.cube.data)
cbar = plt.colorbar()
self.assertIs(cbar.mappable, mappable)
assert cbar.mappable is mappable

def test_points_with_c_kwarg_specified_mappable(self):
mappable_initial = points(self.cube, c=self.cube.data, cmap="cool")
_ = points(self.cube, c=self.cube.data)
cbar = plt.colorbar(mappable_initial)
self.assertIs(cbar.mappable, mappable_initial)
assert cbar.mappable is mappable_initial

def test_scatter_with_c_kwarg(self):
mappable = scatter(self.traj_lon, self.traj_lat, c=self.traj_lon.points)
cbar = plt.colorbar()
self.assertIs(cbar.mappable, mappable)
assert cbar.mappable is mappable

def test_scatter_with_c_kwarg_specified_mappable(self):
mappable_initial = scatter(self.traj_lon, self.traj_lat, c=self.traj_lon.points)
_ = scatter(self.traj_lon, self.traj_lat, c=self.traj_lon.points, cmap="cool")
cbar = plt.colorbar(mappable_initial)
self.assertIs(cbar.mappable, mappable_initial)


if __name__ == "__main__":
tests.main()
assert cbar.mappable is mappable_initial
20 changes: 6 additions & 14 deletions lib/iris/tests/integration/plot/test_netcdftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Test plot of time coord with non-standard calendar."""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

from cf_units import Unit
import cftime
import numpy as np

from iris.coords import AuxCoord
from iris.tests import _shared_utils

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import iris.plot as iplt


@tests.skip_nc_time_axis
@tests.skip_plot
class Test(tests.GraphicsTest):
@_shared_utils.skip_nc_time_axis
@_shared_utils.skip_plot
class Test(_shared_utils.GraphicsTest):
def test_360_day_calendar(self):
n = 360
calendar = "360_day"
Expand All @@ -44,8 +40,4 @@ def test_360_day_calendar(self):
expected_ydata = times
(line1,) = iplt.plot(time_coord)
result_ydata = line1.get_ydata()
self.assertArrayEqual(expected_ydata, result_ydata)


if __name__ == "__main__":
tests.main()
_shared_utils.assert_array_equal(expected_ydata, result_ydata)
24 changes: 8 additions & 16 deletions lib/iris/tests/integration/plot/test_nzdateline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@
# See LICENSE in the root of the repository for full licensing details.
"""Test set up of limited area map extents which bridge the date line."""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

import iris
from iris.tests import _shared_utils

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import matplotlib.pyplot as plt

from iris.plot import pcolormesh


@tests.skip_plot
@tests.skip_data
class TestExtent(tests.IrisTest):
@_shared_utils.skip_plot
@_shared_utils.skip_data
class TestExtent:
def test_dateline(self):
dpath = tests.get_data_path(["PP", "nzgust.pp"])
dpath = _shared_utils.get_data_path(["PP", "nzgust.pp"])
cube = iris.load_cube(dpath)
pcolormesh(cube)
# Ensure that the limited area expected for NZ is set.
# This is set in longitudes with the datum set to the
# International Date Line.
self.assertTrue(
-10 < plt.gca().get_xlim()[0] < -5 and 5 < plt.gca().get_xlim()[1] < 10
)


if __name__ == "__main__":
tests.main()
assert -10 < plt.gca().get_xlim()[0] < -5
assert 5 < plt.gca().get_xlim()[1] < 10
24 changes: 9 additions & 15 deletions lib/iris/tests/integration/plot/test_plot_2d_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# See LICENSE in the root of the repository for full licensing details.
"""Test plots with two dimensional coordinates."""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
Expand All @@ -16,22 +13,23 @@
from iris.analysis.cartography import unrotate_pole
from iris.coords import AuxCoord
from iris.cube import Cube
from iris.tests import _shared_utils

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import iris.quickplot as qplt


@tests.skip_data
@_shared_utils.skip_data
def simple_cube_w_2d_coords():
path = tests.get_data_path(("NetCDF", "ORCA2", "votemper.nc"))
path = _shared_utils.get_data_path(("NetCDF", "ORCA2", "votemper.nc"))
cube = iris.load_cube(path)
return cube


@tests.skip_plot
@tests.skip_data
class Test(tests.GraphicsTest):
@_shared_utils.skip_plot
@_shared_utils.skip_data
class Test(_shared_utils.GraphicsTest):
def test_2d_coord_bounds_platecarree(self):
# To avoid a problem with Cartopy smearing the data where the
# longitude wraps, we set the central_longitude.
Expand All @@ -56,8 +54,8 @@ def test_2d_coord_bounds_northpolarstereo(self):
self.check_graphic()


@tests.skip_plot
class Test2dContour(tests.GraphicsTest):
@_shared_utils.skip_plot
class Test2dContour(_shared_utils.GraphicsTest):
def test_2d_coords_contour(self):
ny, nx = 4, 6
x1 = np.linspace(-20, 70, nx)
Expand All @@ -77,7 +75,3 @@ def test_2d_coords_contour(self):
ax.gridlines(draw_labels=True)
ax.set_extent((0, 180, 0, 90))
self.check_graphic()


if __name__ == "__main__":
tests.main()
26 changes: 7 additions & 19 deletions lib/iris/tests/integration/plot/test_vector_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@
# See LICENSE in the root of the repository for full licensing details.
"""Test some key usages of :func:`iris.plot.quiver`."""

# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip

import cartopy.crs as ccrs
import numpy as np
import pytest

from iris.coord_systems import Mercator
from iris.coords import AuxCoord, DimCoord
from iris.cube import Cube
from iris.tests import _shared_utils
from iris.tests.stock import sample_2d_latlons

# Run tests in no graphics mode if matplotlib is not available.
if tests.MPL_AVAILABLE:
if _shared_utils.MPL_AVAILABLE:
import matplotlib.pyplot as plt

from iris.plot import barbs, quiver


@tests.skip_plot
@_shared_utils.skip_plot
class MixinVectorPlotCases:
"""Test examples mixin, used by separate barb, quiver + streamplot classes.

Expand Down Expand Up @@ -147,7 +145,7 @@ def test_fail_unsupported_coord_system(self):
r"Can only plot .* lat-lon projection, .* "
r"This .* translates as Cartopy \+proj=merc .*"
)
with self.assertRaisesRegex(ValueError, re_msg):
with pytest.raises(ValueError, match=re_msg):
self.plot("2d_rotated", u_cube, v_cube, coords=("longitude", "latitude"))

def test_circular_longitude(self):
Expand Down Expand Up @@ -178,10 +176,7 @@ def test_circular_longitude(self):
self.plot("circular", u_cube, v_cube, coords=("longitude", "latitude"))


class TestBarbs(MixinVectorPlotCases, tests.GraphicsTest):
def setUp(self):
super().setUp()

class TestBarbs(MixinVectorPlotCases, _shared_utils.GraphicsTest):
@staticmethod
def _nonlatlon_xyuv():
# Increase the range of wind speeds used in the barbs test to test more
Expand All @@ -206,13 +201,6 @@ def plot_function_to_test(self):
return barbs


class TestQuiver(MixinVectorPlotCases, tests.GraphicsTest):
def setUp(self):
super().setUp()

class TestQuiver(MixinVectorPlotCases, _shared_utils.GraphicsTest):
def plot_function_to_test(self):
return quiver


if __name__ == "__main__":
tests.main()
Loading