Skip to content
Open
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
4 changes: 4 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ This document explains the changes made to Iris for this release
Cube/Coord summary to use ``str`` representation instead of ``repr``.
(:pull:`6966`, :issue:`6692`)

#. `@ESadek-MO` and `@pp-mo`_ removed unit test reliance on all optional dependencies
except for mo_pack.
(:issue:`6832`, :pull:`6976`)

.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
core dev names are automatically included by the common_links.inc:
Expand Down
6 changes: 0 additions & 6 deletions lib/iris/tests/_shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,12 +979,6 @@ class MyGeoTiffTests(test.IrisTest):
)


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


def no_warnings(func):
"""Provides a decorator to ensure that there are no warnings raised
within the test, otherwise the test will fail.
Expand Down
5 changes: 5 additions & 0 deletions lib/iris/tests/integration/_shapefiles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Iris contributors
#
# 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 the :mod:`iris._shapefiles` package."""
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris._shapefiles.create_shape_mask`."""
"""Integration tests for :func:`iris._shapefiles.create_shape_mask`."""

import numpy as np
from pyproj import CRS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris._shapefiles._get_weighted_mask`."""
"""Integration tests for :func:`iris._shapefiles._get_weighted_mask`."""

import numpy as np
import pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris._shapefiles.is_geometry_valid`."""
"""Integration tests for :func:`iris._shapefiles.is_geometry_valid`."""

from pyproj import CRS
import pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris._shapefiles._make_raster_cube_transform`."""
"""Integration tests for :func:`iris._shapefiles._make_raster_cube_transform`."""

from affine import Affine
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris._shapefiles._transform_geometry`."""
"""Integration tests for :func:`iris._shapefiles._transform_geometry`."""

import numpy as np
import pyproj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# 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.
"""Unit tests for the :mod:`iris.pandas` module."""
"""Regridding code is tested in this package."""
5 changes: 5 additions & 0 deletions lib/iris/tests/integration/experimental/stratify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Iris contributors
#
# 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 the :mod:`iris.experimental.stratify` package."""
98 changes: 98 additions & 0 deletions lib/iris/tests/integration/experimental/stratify/test_relevel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright Iris contributors
#
# 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 the :func:`iris.experimental.stratify.relevel` function."""

from functools import partial

import numpy as np
import pytest
import stratify

from iris.coords import AuxCoord, DimCoord
from iris.experimental.stratify import relevel
from iris.tests import _shared_utils
import iris.tests.stock as stock


class Test:
@pytest.fixture(autouse=True)
def _setup(self):
cube = stock.simple_3d()[:, :1, :1]
#: The data from which to get the levels.
self.src_levels = cube.copy()
#: The data to interpolate.
self.cube = cube.copy()
self.cube.rename("foobar")
self.cube *= 10
self.coord = self.src_levels.coord("wibble")
self.axes = (self.coord, self.coord.name(), None, 0)

def test_standard_input(self):
for axis in self.axes:
result = relevel(self.cube, self.src_levels, [-1, 0, 5.5], axis=axis)
_shared_utils.assert_array_equal(
result.data.flatten(), np.array([np.nan, 0, 55])
)
expected = DimCoord([-1, 0, 5.5], units=1, long_name="thingness")
assert expected == result.coord("thingness")

def test_non_monotonic(self):
for axis in self.axes:
result = relevel(self.cube, self.src_levels, [2, 3, 2], axis=axis)
_shared_utils.assert_array_equal(
result.data.flatten(), np.array([20, 30, np.nan])
)
expected = AuxCoord([2, 3, 2], units=1, long_name="thingness")
assert result.coord("thingness") == expected

def test_static_level(self):
for axis in self.axes:
result = relevel(self.cube, self.src_levels, [2, 2], axis=axis)
_shared_utils.assert_array_equal(result.data.flatten(), np.array([20, 20]))

def test_coord_input(self):
source = AuxCoord(self.src_levels.data)
metadata = self.src_levels.metadata._asdict()
metadata["coord_system"] = None
metadata["climatological"] = None
source.metadata = metadata

for axis in self.axes:
result = relevel(self.cube, source, [0, 12, 13], axis=axis)
assert result.shape == (3, 1, 1)
_shared_utils.assert_array_equal(result.data.flatten(), [0, 120, np.nan])

def test_custom_interpolator(self):
interpolator = partial(stratify.interpolate, interpolation="nearest")

for axis in self.axes:
result = relevel(
self.cube,
self.src_levels,
[-1, 0, 6.5],
axis=axis,
interpolator=interpolator,
)
_shared_utils.assert_array_equal(
result.data.flatten(), np.array([np.nan, 0, 120])
)

def test_multi_dim_target_levels(self, request):
interpolator = partial(
stratify.interpolate,
interpolation="linear",
extrapolation="linear",
)

for axis in self.axes:
result = relevel(
self.cube,
self.src_levels,
self.src_levels.data,
axis=axis,
interpolator=interpolator,
)
_shared_utils.assert_array_equal(result.data.flatten(), np.array([0, 120]))
_shared_utils.assert_CML(request, result)
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@
# Importing pandas has the side-effect of messing with the formatters
# used by matplotlib for handling dates.
default_units_registry = copy.copy(matplotlib.units.registry)
try:
import pandas as pd
except ImportError:
# Disable all these tests if pandas is not installed.
pd = None
import pandas as pd

matplotlib.units.registry = default_units_registry

skip_pandas = pytest.mark.skipif(
pd is None,
reason='Test(s) require "pandas", which is not available.',
)

if pd is not None:
from iris.coords import AncillaryVariable, AuxCoord, CellMeasure, DimCoord
Expand All @@ -48,7 +41,6 @@ def activate_pandas_ndim():
iris.FUTURE.pandas_ndim = False


@skip_pandas
@pytest.mark.filterwarnings(
"ignore:.*as_series has been deprecated.*:iris._deprecation.IrisDeprecation"
)
Expand Down Expand Up @@ -131,7 +123,6 @@ def test_copy_masked_true(self):
assert cube.data[0] == 0


@skip_pandas
@pytest.mark.filterwarnings(
"ignore:You are using legacy 2-dimensional behaviour.*:FutureWarning"
)
Expand Down Expand Up @@ -261,7 +252,6 @@ def test_copy_masked_true(self):
assert cube.data[0, 0] == 0


@skip_pandas
class TestAsDataFrameNDim:
"""Test conversion of n-dimensional cubes to Pandas using as_data_frame()."""

Expand Down Expand Up @@ -565,7 +555,6 @@ def test_instance_error(self):
_ = iris.pandas.as_data_frame(list())


@skip_pandas
@pytest.mark.filterwarnings(
"ignore:.*as_cube has been deprecated.*:iris._deprecation.IrisDeprecation"
)
Expand Down Expand Up @@ -647,7 +636,6 @@ def test_implicit_copy_true(self):
assert series[5] == 0


@skip_pandas
@pytest.mark.filterwarnings(
"ignore:.*as_cube has been deprecated.*:iris._deprecation.IrisDeprecation"
)
Expand Down Expand Up @@ -750,7 +738,6 @@ def test_implicit_copy_true(self):
assert data_frame.iloc[0, 0] == 0


@skip_pandas
class TestFutureAndDeprecation:
def test_as_cube_deprecation_warning(self):
data_frame = pd.DataFrame([[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]])
Expand Down Expand Up @@ -819,7 +806,6 @@ def test_explicit_copy_false_error(self, test_function, test_input):
_ = test_function(test_input, copy=False)


@skip_pandas
class TestPandasAsCubes:
@staticmethod
def _create_pandas(index_levels=0, is_series=False):
Expand Down
5 changes: 5 additions & 0 deletions lib/iris/tests/integration/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright Iris contributors
#
# 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 the :mod:`iris.util` module."""
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# 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.
"""Unit tests for :func:`iris.util.mask_cube_from_shapefile`."""
"""Integration tests for :func:`iris.util.mask_cube_from_shapefile`."""

import numpy as np
import pytest
Expand Down
20 changes: 14 additions & 6 deletions lib/iris/tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,21 @@ def load_match(self, files, constraints):
return cubes


@pytest.fixture
def _skip_sample_data_path():
try:
fname = iris.sample_data_path("atlantic_profiles.nc")
cubes = iris.load(fname)
except ImportError:
cubes = iris.cube.CubeList([stock.simple_pp(), stock.simple_3d()])
return cubes


@_shared_utils.skip_data
class TestCubeExtract__names(ConstraintMixin):
@pytest.fixture(autouse=True)
def _setup(self, _setup_mixin):
fname = iris.sample_data_path("atlantic_profiles.nc")
self.cubes = iris.load(fname)
def _setup(self, _setup_mixin, _skip_sample_data_path):
self.cubes = _skip_sample_data_path
cube = iris.load_cube(self.theta_path)
# Expected names...
self.standard_name = "air_potential_temperature"
Expand Down Expand Up @@ -365,9 +374,8 @@ def test_unknown(self):
@_shared_utils.skip_data
class TestCubeExtract__name_constraint(ConstraintMixin):
@pytest.fixture(autouse=True)
def _setup(self, _setup_mixin):
fname = iris.sample_data_path("atlantic_profiles.nc")
self.cubes = iris.load(fname)
def _setup(self, _setup_mixin, _skip_sample_data_path):
self.cubes = _skip_sample_data_path
cube = iris.load_cube(self.theta_path)
# Expected names...
self.standard_name = "air_potential_temperature"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from typing import ClassVar

from geovista import Transform
import numpy as np
import pytest

Expand Down Expand Up @@ -67,8 +66,8 @@ def cube_with_crs(self, default_cs, cube):

@pytest.fixture
def mocked_operation(self, mocker):
mocking = mocker.Mock()
setattr(Transform, self.MOCKED_OPERATION, mocking)
target = f"geovista.Transform.{self.MOCKED_OPERATION}"
mocking = mocker.patch(target, mocker.Mock())
return mocking

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# See LICENSE in the root of the repository for full licensing details.
"""Unit tests for the `iris.experimental.geovista.extract_unstructured_region` function."""

from geovista.common import VTK_CELL_IDS, VTK_POINT_IDS
import numpy as np
import pytest

Expand All @@ -13,6 +12,9 @@
from iris.tests.stock import sample_2d_latlons
from iris.tests.stock.mesh import sample_mesh_cube

VTK_CELL_IDS = "vtkOriginalCellIds"
VTK_POINT_IDS = "vtkOriginalPointIds"


class TestRegionExtraction:
@pytest.fixture
Expand Down
Loading
Loading