diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 100eae0ac8..e6c297de0f 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -29,7 +29,7 @@ repos:
- id: no-commit-to-branch
- repo: https://github.com/astral-sh/ruff-pre-commit
- rev: "v0.2.1"
+ rev: "v0.3.3"
hooks:
- id: ruff
types: [file, python]
diff --git a/benchmarks/benchmarks/__init__.py b/benchmarks/benchmarks/__init__.py
index e969b1f23e..14b28b3070 100644
--- a/benchmarks/benchmarks/__init__.py
+++ b/benchmarks/benchmarks/__init__.py
@@ -3,6 +3,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.
"""Common code for benchmarks."""
+
from os import environ
import resource
diff --git a/benchmarks/benchmarks/cperf/__init__.py b/benchmarks/benchmarks/cperf/__init__.py
index eaff9cf5e0..df28a66265 100644
--- a/benchmarks/benchmarks/cperf/__init__.py
+++ b/benchmarks/benchmarks/cperf/__init__.py
@@ -9,6 +9,7 @@
Files available from the UK Met Office:
moo ls moose:/adhoc/projects/avd/asv/data_for_nightly_tests/
"""
+
import numpy as np
from iris import load_cube
diff --git a/benchmarks/benchmarks/cperf/equality.py b/benchmarks/benchmarks/cperf/equality.py
index 16f8c10aab..ffe61ef938 100644
--- a/benchmarks/benchmarks/cperf/equality.py
+++ b/benchmarks/benchmarks/cperf/equality.py
@@ -3,6 +3,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.
"""Equality benchmarks for the CPerf scheme of the UK Met Office's NG-VAT project."""
+
from .. import on_demand_benchmark
from . import SingleDiagnosticMixin
diff --git a/benchmarks/benchmarks/cperf/load.py b/benchmarks/benchmarks/cperf/load.py
index cafc4631c0..07c2de9e79 100644
--- a/benchmarks/benchmarks/cperf/load.py
+++ b/benchmarks/benchmarks/cperf/load.py
@@ -3,6 +3,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.
"""File loading benchmarks for the CPerf scheme of the UK Met Office's NG-VAT project."""
+
from .. import on_demand_benchmark
from . import SingleDiagnosticMixin
diff --git a/benchmarks/benchmarks/experimental/ugrid/regions_combine.py b/benchmarks/benchmarks/experimental/ugrid/regions_combine.py
index f589620aea..6657e70056 100644
--- a/benchmarks/benchmarks/experimental/ugrid/regions_combine.py
+++ b/benchmarks/benchmarks/experimental/ugrid/regions_combine.py
@@ -16,6 +16,7 @@
run-time that scale with data size.
"""
+
import os
import dask.array as da
diff --git a/benchmarks/benchmarks/generate_data/__init__.py b/benchmarks/benchmarks/generate_data/__init__.py
index 4d80429889..bb53e26b2f 100644
--- a/benchmarks/benchmarks/generate_data/__init__.py
+++ b/benchmarks/benchmarks/generate_data/__init__.py
@@ -14,6 +14,7 @@
benchmark sequence runs over two different Python versions.
"""
+
from contextlib import contextmanager
from inspect import getsource
from os import environ
diff --git a/benchmarks/benchmarks/generate_data/ugrid.py b/benchmarks/benchmarks/generate_data/ugrid.py
index 713e5dc7df..de76d63798 100644
--- a/benchmarks/benchmarks/generate_data/ugrid.py
+++ b/benchmarks/benchmarks/generate_data/ugrid.py
@@ -3,6 +3,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.
"""Scripts for generating supporting data for UGRID-related benchmarking."""
+
from iris import load_cube as iris_loadcube
from iris.experimental.ugrid import PARSE_UGRID_ON_LOAD
diff --git a/benchmarks/benchmarks/iterate.py b/benchmarks/benchmarks/iterate.py
index 9353cf42ee..3716602be1 100644
--- a/benchmarks/benchmarks/iterate.py
+++ b/benchmarks/benchmarks/iterate.py
@@ -3,6 +3,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.
"""Iterate benchmark tests."""
+
import numpy as np
from iris import coords, cube, iterate
diff --git a/benchmarks/benchmarks/plot.py b/benchmarks/benchmarks/plot.py
index 9b008ec41c..681d8ef9dd 100644
--- a/benchmarks/benchmarks/plot.py
+++ b/benchmarks/benchmarks/plot.py
@@ -3,6 +3,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.
"""Plot benchmark tests."""
+
import matplotlib as mpl
import numpy as np
diff --git a/benchmarks/benchmarks/save.py b/benchmarks/benchmarks/save.py
index 0c5f79947d..f2a2611eae 100644
--- a/benchmarks/benchmarks/save.py
+++ b/benchmarks/benchmarks/save.py
@@ -11,6 +11,7 @@
run-time that scale with data size.
"""
+
from iris import save
from iris.experimental.ugrid import save_mesh
diff --git a/benchmarks/benchmarks/sperf/__init__.py b/benchmarks/benchmarks/sperf/__init__.py
index 0a87dbb25c..e51bef5ca2 100644
--- a/benchmarks/benchmarks/sperf/__init__.py
+++ b/benchmarks/benchmarks/sperf/__init__.py
@@ -7,6 +7,7 @@
SPerf = assessing performance against a series of increasingly large LFRic
datasets.
"""
+
from iris import load_cube
# TODO: remove uses of PARSE_UGRID_ON_LOAD once UGRID parsing is core behaviour.
diff --git a/benchmarks/benchmarks/sperf/combine_regions.py b/benchmarks/benchmarks/sperf/combine_regions.py
index d5572c58ea..d375f44719 100644
--- a/benchmarks/benchmarks/sperf/combine_regions.py
+++ b/benchmarks/benchmarks/sperf/combine_regions.py
@@ -3,6 +3,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.
"""Region combine benchmarks for the SPerf scheme of the UK Met Office's NG-VAT project."""
+
import os.path
from dask import array as da
diff --git a/benchmarks/benchmarks/sperf/equality.py b/benchmarks/benchmarks/sperf/equality.py
index 339687a22c..3f70c6fd7f 100644
--- a/benchmarks/benchmarks/sperf/equality.py
+++ b/benchmarks/benchmarks/sperf/equality.py
@@ -3,6 +3,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.
"""Equality benchmarks for the SPerf scheme of the UK Met Office's NG-VAT project."""
+
from .. import on_demand_benchmark
from . import FileMixin
diff --git a/benchmarks/benchmarks/sperf/load.py b/benchmarks/benchmarks/sperf/load.py
index f3c5ef1136..d304a30c82 100644
--- a/benchmarks/benchmarks/sperf/load.py
+++ b/benchmarks/benchmarks/sperf/load.py
@@ -3,6 +3,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.
"""File loading benchmarks for the SPerf scheme of the UK Met Office's NG-VAT project."""
+
from .. import on_demand_benchmark
from . import FileMixin
diff --git a/benchmarks/benchmarks/sperf/save.py b/benchmarks/benchmarks/sperf/save.py
index 3fb8133659..8d9a90f7cf 100644
--- a/benchmarks/benchmarks/sperf/save.py
+++ b/benchmarks/benchmarks/sperf/save.py
@@ -3,6 +3,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.
"""File saving benchmarks for the SPerf scheme of the UK Met Office's NG-VAT project."""
+
import os.path
from iris import save
diff --git a/docs/gallery_code/oceanography/plot_load_nemo.py b/docs/gallery_code/oceanography/plot_load_nemo.py
index 36ff363a15..aac89fec0e 100644
--- a/docs/gallery_code/oceanography/plot_load_nemo.py
+++ b/docs/gallery_code/oceanography/plot_load_nemo.py
@@ -45,11 +45,11 @@ def main():
# Include the point's position in the plot's title
lat_point = cube.coord("latitude").points[y_point_index, x_point_index]
- lat_string = "{:.3f}\u00B0 {}".format(
+ lat_string = "{:.3f}\u00b0 {}".format(
abs(lat_point), "N" if lat_point > 0.0 else "S"
)
lon_point = cube.coord("longitude").points[y_point_index, x_point_index]
- lon_string = "{:.3f}\u00B0 {}".format(
+ lon_string = "{:.3f}\u00b0 {}".format(
abs(lon_point), "E" if lon_point > 0.0 else "W"
)
plt.title("{} at {} {}".format(cube.long_name.capitalize(), lat_string, lon_string))
diff --git a/docs/src/userguide/plotting_examples/cube_contour.py b/docs/src/userguide/plotting_examples/cube_contour.py
index 0d8c1e02aa..e338d395ff 100644
--- a/docs/src/userguide/plotting_examples/cube_contour.py
+++ b/docs/src/userguide/plotting_examples/cube_contour.py
@@ -3,6 +3,7 @@
Can use iris.plot.contour() or iris.quicplot.contour().
"""
+
import matplotlib.pyplot as plt
import iris
diff --git a/docs/src/userguide/plotting_examples/cube_contourf.py b/docs/src/userguide/plotting_examples/cube_contourf.py
index 531dd45d25..b76645b380 100644
--- a/docs/src/userguide/plotting_examples/cube_contourf.py
+++ b/docs/src/userguide/plotting_examples/cube_contourf.py
@@ -3,6 +3,7 @@
Can use iris.plot.contour() or iris.quickplot.contour().
"""
+
import matplotlib.pyplot as plt
import iris
diff --git a/docs/src/userguide/plotting_examples/masking_brazil_plot.py b/docs/src/userguide/plotting_examples/masking_brazil_plot.py
index 3dc521d451..d1a75a700f 100644
--- a/docs/src/userguide/plotting_examples/masking_brazil_plot.py
+++ b/docs/src/userguide/plotting_examples/masking_brazil_plot.py
@@ -1,4 +1,5 @@
"""Global cube masked to Brazil and plotted with quickplot."""
+
import cartopy.io.shapereader as shpreader
import matplotlib.pyplot as plt
diff --git a/lib/iris/_representation/cube_printout.py b/lib/iris/_representation/cube_printout.py
index 3c418bde64..1e648b25f6 100644
--- a/lib/iris/_representation/cube_printout.py
+++ b/lib/iris/_representation/cube_printout.py
@@ -3,6 +3,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.
"""Provides text printouts of Iris cubes."""
+
from copy import deepcopy
from iris._representation.cube_summary import CubeSummary
diff --git a/lib/iris/_representation/cube_summary.py b/lib/iris/_representation/cube_summary.py
index 64a6aadbf3..2b0658d4a7 100644
--- a/lib/iris/_representation/cube_summary.py
+++ b/lib/iris/_representation/cube_summary.py
@@ -3,6 +3,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.
"""Provides objects describing cube summaries."""
+
import re
from iris.common.metadata import hexdigest
diff --git a/lib/iris/common/_split_attribute_dicts.py b/lib/iris/common/_split_attribute_dicts.py
index 17b3014fb1..3e9c74cea9 100644
--- a/lib/iris/common/_split_attribute_dicts.py
+++ b/lib/iris/common/_split_attribute_dicts.py
@@ -15,6 +15,7 @@
So, we simply treat "global" and "local" attributes of the same name as entirely
independent. Which happily is also the easiest to code, and to explain.
"""
+
from collections.abc import Mapping, Sequence
from functools import wraps
diff --git a/lib/iris/common/metadata.py b/lib/iris/common/metadata.py
index 3a5f4deede..9b0edf6532 100644
--- a/lib/iris/common/metadata.py
+++ b/lib/iris/common/metadata.py
@@ -4,7 +4,6 @@
# See LICENSE in the root of the repository for full licensing details.
"""Provides the infrastructure to support the common metadata API."""
-
from abc import ABCMeta
from collections import namedtuple
from collections.abc import Iterable, Mapping
diff --git a/lib/iris/experimental/regrid.py b/lib/iris/experimental/regrid.py
index 835aa51368..4ffad43a2c 100644
--- a/lib/iris/experimental/regrid.py
+++ b/lib/iris/experimental/regrid.py
@@ -16,6 +16,7 @@
discuss how to replace it or to retain it.
"""
+
import copy
import functools
import warnings
diff --git a/lib/iris/experimental/ugrid/__init__.py b/lib/iris/experimental/ugrid/__init__.py
index ccdf05a387..f92cf670c4 100644
--- a/lib/iris/experimental/ugrid/__init__.py
+++ b/lib/iris/experimental/ugrid/__init__.py
@@ -13,6 +13,7 @@
definition at :const:`iris.experimental.ugrid.load.PARSE_UGRID_ON_LOAD`.
"""
+
from ...config import get_logger
from .load import PARSE_UGRID_ON_LOAD, load_mesh, load_meshes
from .mesh import Connectivity, Mesh, MeshCoord
diff --git a/lib/iris/experimental/ugrid/cf.py b/lib/iris/experimental/ugrid/cf.py
index 6897b4ca67..9a56045e67 100644
--- a/lib/iris/experimental/ugrid/cf.py
+++ b/lib/iris/experimental/ugrid/cf.py
@@ -8,6 +8,7 @@
Eventual destination: :mod:`iris.fileformats.cf`.
"""
+
import warnings
from ...fileformats import cf
diff --git a/lib/iris/experimental/ugrid/load.py b/lib/iris/experimental/ugrid/load.py
index 630c179fd9..c9d66f5276 100644
--- a/lib/iris/experimental/ugrid/load.py
+++ b/lib/iris/experimental/ugrid/load.py
@@ -11,6 +11,7 @@
Eventual destination: :mod:`iris.fileformats.netcdf`.
"""
+
from contextlib import contextmanager
from itertools import groupby
from pathlib import Path
diff --git a/lib/iris/experimental/ugrid/mesh.py b/lib/iris/experimental/ugrid/mesh.py
index db000b5c73..a9a880813c 100644
--- a/lib/iris/experimental/ugrid/mesh.py
+++ b/lib/iris/experimental/ugrid/mesh.py
@@ -8,6 +8,7 @@
Eventual destination: dedicated module in :mod:`iris` root.
"""
+
from abc import ABC, abstractmethod
from collections import namedtuple
from collections.abc import Container
diff --git a/lib/iris/experimental/ugrid/metadata.py b/lib/iris/experimental/ugrid/metadata.py
index 8969ab72a1..bc7cc677f7 100644
--- a/lib/iris/experimental/ugrid/metadata.py
+++ b/lib/iris/experimental/ugrid/metadata.py
@@ -8,6 +8,7 @@
Eventual destination: :mod:`iris.common.metadata`.
"""
+
from functools import wraps
from ...common import BaseMetadata
diff --git a/lib/iris/experimental/ugrid/save.py b/lib/iris/experimental/ugrid/save.py
index 40d1c42e90..8cfa6ba97a 100644
--- a/lib/iris/experimental/ugrid/save.py
+++ b/lib/iris/experimental/ugrid/save.py
@@ -8,6 +8,7 @@
Eventual destination: :mod:`iris.fileformats.netcdf`.
"""
+
from collections.abc import Iterable
from ...fileformats import netcdf
diff --git a/lib/iris/experimental/ugrid/utils.py b/lib/iris/experimental/ugrid/utils.py
index fce1036c6d..dcf5462ad5 100644
--- a/lib/iris/experimental/ugrid/utils.py
+++ b/lib/iris/experimental/ugrid/utils.py
@@ -4,6 +4,7 @@
# See LICENSE in the root of the repository for full licensing details.
"""Utility operations specific to unstructured data."""
+
from typing import AnyStr, Iterable, Union
import dask.array as da
diff --git a/lib/iris/fileformats/_nc_load_rules/engine.py b/lib/iris/fileformats/_nc_load_rules/engine.py
index 111e8320b6..48092508a4 100644
--- a/lib/iris/fileformats/_nc_load_rules/engine.py
+++ b/lib/iris/fileformats/_nc_load_rules/engine.py
@@ -18,6 +18,7 @@
used in :meth:`iris.fileformats.netcdf._actions_activation_stats`.
"""
+
from .actions import run_actions
diff --git a/lib/iris/fileformats/_nc_load_rules/helpers.py b/lib/iris/fileformats/_nc_load_rules/helpers.py
index f6e3985e37..43eed96fd5 100644
--- a/lib/iris/fileformats/_nc_load_rules/helpers.py
+++ b/lib/iris/fileformats/_nc_load_rules/helpers.py
@@ -13,6 +13,7 @@
build routines, and which it does not use.
"""
+
from __future__ import annotations
import re
diff --git a/lib/iris/fileformats/netcdf/__init__.py b/lib/iris/fileformats/netcdf/__init__.py
index 61b6f74cc6..e92b0ed4f8 100644
--- a/lib/iris/fileformats/netcdf/__init__.py
+++ b/lib/iris/fileformats/netcdf/__init__.py
@@ -10,6 +10,7 @@
Also : `CF Conventions `_.
"""
+
import iris.config
# Note: *must* be done before importing from submodules, as they also use this !
diff --git a/lib/iris/fileformats/netcdf/_dask_locks.py b/lib/iris/fileformats/netcdf/_dask_locks.py
index eb60afcf8a..64d094e060 100644
--- a/lib/iris/fileformats/netcdf/_dask_locks.py
+++ b/lib/iris/fileformats/netcdf/_dask_locks.py
@@ -49,6 +49,7 @@
'distributed.Lock', which requires a distributed scheduler to function.
"""
+
import threading
import dask.array
diff --git a/lib/iris/fileformats/netcdf/_thread_safe_nc.py b/lib/iris/fileformats/netcdf/_thread_safe_nc.py
index b87ffde145..675a151868 100644
--- a/lib/iris/fileformats/netcdf/_thread_safe_nc.py
+++ b/lib/iris/fileformats/netcdf/_thread_safe_nc.py
@@ -7,6 +7,7 @@
Intention is that no other Iris module should import the netCDF4 module.
"""
+
from abc import ABC
from threading import Lock
import typing
diff --git a/lib/iris/fileformats/netcdf/loader.py b/lib/iris/fileformats/netcdf/loader.py
index ca2d830281..8a48fddb37 100644
--- a/lib/iris/fileformats/netcdf/loader.py
+++ b/lib/iris/fileformats/netcdf/loader.py
@@ -10,6 +10,7 @@
Also : `CF Conventions `_.
"""
+
from collections.abc import Iterable, Mapping
from contextlib import contextmanager
from copy import deepcopy
diff --git a/lib/iris/fileformats/netcdf/saver.py b/lib/iris/fileformats/netcdf/saver.py
index 7c24be0a6d..11491de900 100644
--- a/lib/iris/fileformats/netcdf/saver.py
+++ b/lib/iris/fileformats/netcdf/saver.py
@@ -13,6 +13,7 @@
Also : `CF Conventions `_.
"""
+
import collections
from itertools import repeat, zip_longest
import os
diff --git a/lib/iris/fileformats/um/_optimal_array_structuring.py b/lib/iris/fileformats/um/_optimal_array_structuring.py
index 7d006ebeff..f4e0328a42 100644
--- a/lib/iris/fileformats/um/_optimal_array_structuring.py
+++ b/lib/iris/fileformats/um/_optimal_array_structuring.py
@@ -4,7 +4,6 @@
# See LICENSE in the root of the repository for full licensing details.
"""A module to provide an optimal array structure calculation."""
-
from iris.fileformats._structured_array_identification import GroupStructure
diff --git a/lib/iris/pandas.py b/lib/iris/pandas.py
index 2efad54613..434e415f2d 100644
--- a/lib/iris/pandas.py
+++ b/lib/iris/pandas.py
@@ -7,6 +7,7 @@
See also: https://pandas.pydata.org/
"""
+
import datetime
from itertools import chain, combinations
import warnings
diff --git a/lib/iris/tests/integration/experimental/test_ugrid_load.py b/lib/iris/tests/integration/experimental/test_ugrid_load.py
index d513d02497..5735d6b2c1 100644
--- a/lib/iris/tests/integration/experimental/test_ugrid_load.py
+++ b/lib/iris/tests/integration/experimental/test_ugrid_load.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/integration/experimental/test_ugrid_save.py b/lib/iris/tests/integration/experimental/test_ugrid_save.py
index 8350a2004f..85f6024b93 100644
--- a/lib/iris/tests/integration/experimental/test_ugrid_save.py
+++ b/lib/iris/tests/integration/experimental/test_ugrid_save.py
@@ -3,6 +3,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.
"""Integration tests for NetCDF-UGRID file saving."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/integration/netcdf/test__dask_locks.py b/lib/iris/tests/integration/netcdf/test__dask_locks.py
index 6e1026b29f..1aee902195 100644
--- a/lib/iris/tests/integration/netcdf/test__dask_locks.py
+++ b/lib/iris/tests/integration/netcdf/test__dask_locks.py
@@ -11,6 +11,7 @@
and (b) mock-ist testing of the implementation code in isolation would not add anything
of much value.
"""
+
import dask
import dask.config
import distributed
diff --git a/lib/iris/tests/integration/netcdf/test_aux_factories.py b/lib/iris/tests/integration/netcdf/test_aux_factories.py
index a0c2ec5992..4b4976bd18 100644
--- a/lib/iris/tests/integration/netcdf/test_aux_factories.py
+++ b/lib/iris/tests/integration/netcdf/test_aux_factories.py
@@ -75,9 +75,10 @@ def test_save_load_loop(self):
# Tests an issue where the variable names in the formula
# terms changed to the standard_names instead of the variable names
# when loading a previously saved cube.
- with self.temp_filename(suffix=".nc") as filename, self.temp_filename(
- suffix=".nc"
- ) as other_filename:
+ with (
+ self.temp_filename(suffix=".nc") as filename,
+ self.temp_filename(suffix=".nc") as other_filename,
+ ):
iris.save(self.cube, filename)
cube = iris.load_cube(filename, "air_potential_temperature")
iris.save(cube, other_filename)
@@ -117,8 +118,9 @@ def test_shared_primary(self):
)
factory.rename("another altitude")
cube.add_aux_factory(factory)
- with self.temp_filename(suffix=".nc") as filename, self.assertRaisesRegex(
- ValueError, "multiple aux factories"
+ with (
+ self.temp_filename(suffix=".nc") as filename,
+ self.assertRaisesRegex(ValueError, "multiple aux factories"),
):
iris.save(cube, filename)
@@ -141,8 +143,9 @@ def test_hybrid_height_cubes_on_dimension_coordinate(self):
sa = hh2.coord("surface_altitude")
sa.points = sa.points * 10
emsg = "Unable to create dimensonless vertical coordinate."
- with self.temp_filename(".nc") as fname, self.assertRaisesRegex(
- ValueError, emsg
+ with (
+ self.temp_filename(".nc") as fname,
+ self.assertRaisesRegex(ValueError, emsg),
):
iris.save([hh1, hh2], fname)
diff --git a/lib/iris/tests/integration/netcdf/test_delayed_save.py b/lib/iris/tests/integration/netcdf/test_delayed_save.py
index cb375cc592..9322bb9f54 100644
--- a/lib/iris/tests/integration/netcdf/test_delayed_save.py
+++ b/lib/iris/tests/integration/netcdf/test_delayed_save.py
@@ -3,6 +3,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.
"""Integration tests for delayed saving."""
+
import re
import warnings
diff --git a/lib/iris/tests/integration/netcdf/test_general.py b/lib/iris/tests/integration/netcdf/test_general.py
index 1020ddbb96..c505a21af5 100644
--- a/lib/iris/tests/integration/netcdf/test_general.py
+++ b/lib/iris/tests/integration/netcdf/test_general.py
@@ -3,6 +3,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.
"""Integration tests for loading and saving netcdf files."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/integration/netcdf/test_thread_safety.py b/lib/iris/tests/integration/netcdf/test_thread_safety.py
index b2319364c2..53b40dbe85 100644
--- a/lib/iris/tests/integration/netcdf/test_thread_safety.py
+++ b/lib/iris/tests/integration/netcdf/test_thread_safety.py
@@ -17,6 +17,7 @@
a thread safety problem, as this seems to be good testing practice.
"""
+
from pathlib import Path
import dask
diff --git a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py
index 226babc9fb..991f0431a1 100644
--- a/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py
+++ b/lib/iris/tests/integration/test_netcdf__loadsaveattrs.py
@@ -17,6 +17,7 @@
might be recorded either globally or locally.
"""
+
import inspect
import json
import os
diff --git a/lib/iris/tests/integration/test_pp.py b/lib/iris/tests/integration/test_pp.py
index 1ed9dca853..1e71da623a 100644
--- a/lib/iris/tests/integration/test_pp.py
+++ b/lib/iris/tests/integration/test_pp.py
@@ -280,9 +280,10 @@ def test_hybrid_pressure_with_duplicate_references(self):
return_value=iter([data_field, pressure_field, pressure_field])
)
msg = "Multiple reference cubes for surface_air_pressure"
- with mock.patch("iris.fileformats.pp.load", new=load) as load, mock.patch(
- "warnings.warn"
- ) as warn:
+ with (
+ mock.patch("iris.fileformats.pp.load", new=load) as load,
+ mock.patch("warnings.warn") as warn,
+ ):
_, _, _ = iris.fileformats.pp.load_cubes("DUMMY")
warn.assert_called_with(msg, category=IrisUserWarning)
@@ -396,9 +397,10 @@ def test_hybrid_height_round_trip_no_reference(self):
# Convert field to a cube.
load = mock.Mock(return_value=iter([data_field]))
- with mock.patch("iris.fileformats.pp.load", new=load) as load, mock.patch(
- "warnings.warn"
- ) as warn:
+ with (
+ mock.patch("iris.fileformats.pp.load", new=load) as load,
+ mock.patch("warnings.warn") as warn,
+ ):
(data_cube,) = iris.fileformats.pp.load_cubes("DUMMY")
msg = (
diff --git a/lib/iris/tests/stock/__init__.py b/lib/iris/tests/stock/__init__.py
index 8c1154af72..ea513b967f 100644
--- a/lib/iris/tests/stock/__init__.py
+++ b/lib/iris/tests/stock/__init__.py
@@ -3,6 +3,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.
"""A collection of routines which create standard Cubes/files for test purposes."""
+
import iris.tests as tests # isort:skip
from datetime import datetime
diff --git a/lib/iris/tests/stock/mesh.py b/lib/iris/tests/stock/mesh.py
index 3520436f66..4d0e8ae658 100644
--- a/lib/iris/tests/stock/mesh.py
+++ b/lib/iris/tests/stock/mesh.py
@@ -4,7 +4,6 @@
# See LICENSE in the root of the repository for full licensing details.
"""Helper functions making objects for unstructured mesh testing."""
-
import numpy as np
from iris.coords import AuxCoord, DimCoord
diff --git a/lib/iris/tests/unit/conftest.py b/lib/iris/tests/unit/conftest.py
index a4ddb89294..524ca53ce8 100644
--- a/lib/iris/tests/unit/conftest.py
+++ b/lib/iris/tests/unit/conftest.py
@@ -3,6 +3,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 fixture infra-structure."""
+
import pytest
import iris
diff --git a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridAuxiliaryCoordinateVariable.py b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridAuxiliaryCoordinateVariable.py
index 4a45e9a4df..f283dd22db 100644
--- a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridAuxiliaryCoordinateVariable.py
+++ b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridAuxiliaryCoordinateVariable.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridConnectivityVariable.py b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridConnectivityVariable.py
index 5144729c7f..d412b8838a 100644
--- a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridConnectivityVariable.py
+++ b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridConnectivityVariable.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridGroup.py b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridGroup.py
index 9577955f97..6db067fe25 100644
--- a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridGroup.py
+++ b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridGroup.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridMeshVariable.py b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridMeshVariable.py
index ef5447382a..32c96cacbc 100644
--- a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridMeshVariable.py
+++ b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridMeshVariable.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridReader.py b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridReader.py
index cb2ae41d72..14278d3dff 100644
--- a/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridReader.py
+++ b/lib/iris/tests/unit/experimental/ugrid/cf/test_CFUGridReader.py
@@ -8,6 +8,7 @@
standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py b/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py
index 7ccdeee08b..8f85699037 100644
--- a/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py
+++ b/lib/iris/tests/unit/experimental/ugrid/load/test_ParseUgridOnLoad.py
@@ -7,6 +7,7 @@
todo: remove this module when experimental.ugrid is folded into standard behaviour.
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py b/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py
index 382a36fa71..6e78057746 100644
--- a/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py
+++ b/lib/iris/tests/unit/experimental/ugrid/load/test_load_mesh.py
@@ -3,6 +3,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 the :func:`iris.experimental.ugrid.load.load_mesh` function."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py b/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py
index 8932989252..cef142b424 100644
--- a/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py
+++ b/lib/iris/tests/unit/experimental/ugrid/load/test_load_meshes.py
@@ -3,6 +3,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 the :func:`iris.experimental.ugrid.load.load_meshes` function."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py
index 2282bc07b9..78fa39060e 100644
--- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py
+++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py
@@ -3,6 +3,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 the :class:`iris.experimental.ugrid.mesh.MeshCoord`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh__from_coords.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh__from_coords.py
index 31c5dbfcc0..aa45e0be70 100644
--- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh__from_coords.py
+++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_Mesh__from_coords.py
@@ -3,6 +3,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 the :meth:`iris.experimental.ugrid.mesh.Mesh.from_coords`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/metadata/test_ConnectivityMetadata.py b/lib/iris/tests/unit/experimental/ugrid/metadata/test_ConnectivityMetadata.py
index fa62a9f7e2..91637ad20b 100644
--- a/lib/iris/tests/unit/experimental/ugrid/metadata/test_ConnectivityMetadata.py
+++ b/lib/iris/tests/unit/experimental/ugrid/metadata/test_ConnectivityMetadata.py
@@ -3,6 +3,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 the :class:`iris.experimental.ugrid.metadata.ConnectivityMetadata`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshCoordMetadata.py b/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshCoordMetadata.py
index fc9242a8f9..0434149674 100644
--- a/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshCoordMetadata.py
+++ b/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshCoordMetadata.py
@@ -3,6 +3,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 the :class:`iris.experimental.ugrid.metadata.MeshCoordMetadata`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshMetadata.py b/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshMetadata.py
index 080d94c188..abbb4c0304 100644
--- a/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshMetadata.py
+++ b/lib/iris/tests/unit/experimental/ugrid/metadata/test_MeshMetadata.py
@@ -3,6 +3,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 the :class:`iris.experimental.ugrid.metadata.MeshMetadata`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/experimental/ugrid/utils/test_recombine_submeshes.py b/lib/iris/tests/unit/experimental/ugrid/utils/test_recombine_submeshes.py
index f01dc345fa..1c0fafdfc9 100644
--- a/lib/iris/tests/unit/experimental/ugrid/utils/test_recombine_submeshes.py
+++ b/lib/iris/tests/unit/experimental/ugrid/utils/test_recombine_submeshes.py
@@ -3,6 +3,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.experimental.ugrid.utils.recombine_submeshes`."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/fileformats/cf/test_CFReader.py b/lib/iris/tests/unit/fileformats/cf/test_CFReader.py
index 667c679bfb..80338ea71e 100644
--- a/lib/iris/tests/unit/fileformats/cf/test_CFReader.py
+++ b/lib/iris/tests/unit/fileformats/cf/test_CFReader.py
@@ -301,10 +301,13 @@ def test_promote_reference(self):
def test_formula_terms_ignore(self):
self.orography.dimensions = ["lat", "wibble"]
- with mock.patch(
- "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
- return_value=self.dataset,
- ), mock.patch("warnings.warn") as warn:
+ with (
+ mock.patch(
+ "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
+ return_value=self.dataset,
+ ),
+ mock.patch("warnings.warn") as warn,
+ ):
cf_group = CFReader("dummy").cf_group
group = cf_group.promoted
self.assertEqual(list(group.keys()), ["orography"])
@@ -313,10 +316,13 @@ def test_formula_terms_ignore(self):
def test_auxiliary_ignore(self):
self.x.dimensions = ["lat", "wibble"]
- with mock.patch(
- "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
- return_value=self.dataset,
- ), mock.patch("warnings.warn") as warn:
+ with (
+ mock.patch(
+ "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
+ return_value=self.dataset,
+ ),
+ mock.patch("warnings.warn") as warn,
+ ):
cf_group = CFReader("dummy").cf_group
promoted = ["x", "orography"]
group = cf_group.promoted
@@ -329,10 +335,13 @@ def test_promoted_auxiliary_ignore(self):
self.wibble = netcdf_variable("wibble", "lat wibble", np.float64)
self.variables["wibble"] = self.wibble
self.orography.coordinates = "wibble"
- with mock.patch(
- "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
- return_value=self.dataset,
- ), mock.patch("warnings.warn") as warn:
+ with (
+ mock.patch(
+ "iris.fileformats.netcdf._thread_safe_nc.DatasetWrapper",
+ return_value=self.dataset,
+ ),
+ mock.patch("warnings.warn") as warn,
+ ):
cf_group = CFReader("dummy").cf_group.promoted
promoted = ["wibble", "orography"]
self.assertEqual(set(cf_group.keys()), set(promoted))
diff --git a/lib/iris/tests/unit/fileformats/ff/test_FF2PP.py b/lib/iris/tests/unit/fileformats/ff/test_FF2PP.py
index 4d031ac4a6..c21fc39821 100644
--- a/lib/iris/tests/unit/fileformats/ff/test_FF2PP.py
+++ b/lib/iris/tests/unit/fileformats/ff/test_FF2PP.py
@@ -85,13 +85,13 @@ def mock_for_extract_field(self, fields, x=None, y=None):
ff2pp._ff_header.grid = mock.Mock(return_value=grid)
open_func = "builtins.open"
- with mock.patch(
- "iris.fileformats._ff._parse_binary_stream", return_value=[0]
- ), mock.patch(open_func), mock.patch(
- "struct.unpack_from", return_value=[4]
- ), mock.patch(
- "iris.fileformats.pp.make_pp_field", side_effect=fields
- ), mock.patch("iris.fileformats._ff.FF2PP._payload", return_value=(0, 0)):
+ with (
+ mock.patch("iris.fileformats._ff._parse_binary_stream", return_value=[0]),
+ mock.patch(open_func),
+ mock.patch("struct.unpack_from", return_value=[4]),
+ mock.patch("iris.fileformats.pp.make_pp_field", side_effect=fields),
+ mock.patch("iris.fileformats._ff.FF2PP._payload", return_value=(0, 0)),
+ ):
yield ff2pp
def _mock_lbc(self, **kwargs):
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/__init__.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/__init__.py
index 845b88536a..9d1c1d742a 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/__init__.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/__init__.py
@@ -3,6 +3,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 the module :mod:`iris.fileformats._nc_load_rules.actions`."""
+
from pathlib import Path
import shutil
import tempfile
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__grid_mappings.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__grid_mappings.py
index 72e9448255..8c2e30a902 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__grid_mappings.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__grid_mappings.py
@@ -8,6 +8,7 @@
Here, *specifically* testcases relating to grid-mappings and dim-coords.
"""
+
import iris.tests as tests # isort: skip
import iris.coord_systems as ics
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py
index 5af6d6fa1d..65b0ecd94e 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__hybrid_formulae.py
@@ -8,6 +8,7 @@
Test rules activation relating to hybrid vertical coordinates.
"""
+
import iris.tests as tests # isort: skip
import iris.fileformats._nc_load_rules.helpers as hh
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__latlon_dimcoords.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__latlon_dimcoords.py
index e6a2c203b7..499088a802 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__latlon_dimcoords.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__latlon_dimcoords.py
@@ -9,6 +9,7 @@
rotated and non-rotated.
"""
+
import iris.tests as tests # isort: skip
from iris.coord_systems import GeogCS, RotatedGeogCS
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py
index a7d5a10e73..15d8afe880 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py
@@ -12,6 +12,7 @@
* ancillary variables
"""
+
import iris.tests as tests # isort: skip
from iris.coords import AncillaryVariable, AuxCoord, CellMeasure
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__time_coords.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__time_coords.py
index b3c2fe9b0b..c19dffd6e2 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__time_coords.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__time_coords.py
@@ -8,6 +8,7 @@
Tests for rules activation relating to 'time' and 'time_period' coords.
"""
+
import iris.tests as tests # isort: skip
from iris.coords import AuxCoord, DimCoord
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/engine/test_engine.py b/lib/iris/tests/unit/fileformats/nc_load_rules/engine/test_engine.py
index 7aaca67326..71280e5f60 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/engine/test_engine.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/engine/test_engine.py
@@ -3,6 +3,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 the :mod:`iris.fileformats._nc_load_rules.engine` module."""
+
from unittest import mock
from iris.fileformats._nc_load_rules.engine import Engine, FactEntity
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_auxiliary_coordinate.py b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_auxiliary_coordinate.py
index 73533a9c33..b43317901f 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_auxiliary_coordinate.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_auxiliary_coordinate.py
@@ -6,6 +6,7 @@
build_auxilliary_coordinate`.
"""
+
# import iris tests first so that some things can be initialised before
# importing anything else
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_oblique_mercator_coordinate_system.py b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_oblique_mercator_coordinate_system.py
index 3e12e33762..50b171655e 100644
--- a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_oblique_mercator_coordinate_system.py
+++ b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_oblique_mercator_coordinate_system.py
@@ -3,6 +3,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.
"""Test function :func:`iris.fileformats._nc_load_rules.helpers.build_oblique_mercator_coordinate_system`."""
+
from typing import List, NamedTuple, Type
from unittest import mock
diff --git a/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py b/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py
index bc7911578a..bb6bfd4dcc 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/loader/test__chunk_control.py
@@ -133,8 +133,9 @@ def test_invalid_var_name(tmp_filepath, save_cubelist_with_sigma):
def test_control_multiple(tmp_filepath, save_cubelist_with_sigma):
cube_varname, sigma_varname = save_cubelist_with_sigma
- with CHUNK_CONTROL.set(cube_varname, model_level_number=2), CHUNK_CONTROL.set(
- sigma_varname, model_level_number=3
+ with (
+ CHUNK_CONTROL.set(cube_varname, model_level_number=2),
+ CHUNK_CONTROL.set(sigma_varname, model_level_number=3),
):
cubes = CubeList(loader.load_cubes(tmp_filepath))
cube = cubes.extract_cube(cube_varname)
diff --git a/lib/iris/tests/unit/fileformats/netcdf/loader/test__get_cf_var_data.py b/lib/iris/tests/unit/fileformats/netcdf/loader/test__get_cf_var_data.py
index 9aa696bccd..92cb93496e 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/loader/test__get_cf_var_data.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/loader/test__get_cf_var_data.py
@@ -3,6 +3,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 the `iris.fileformats.netcdf._get_cf_var_data` function."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__lazy_stream_data.py b/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__lazy_stream_data.py
index c1bc411564..f252d53a47 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__lazy_stream_data.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__lazy_stream_data.py
@@ -9,6 +9,7 @@
integration tests.
"""
+
from unittest import mock
import warnings
diff --git a/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__ugrid.py b/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__ugrid.py
index 241ff5a5cc..14da76ded8 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__ugrid.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/saver/test_Saver__ugrid.py
@@ -8,6 +8,7 @@
:mod:`iris.tests.unit.fileformats.netcdf.test_Saver__lazy.`
"""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/fileformats/netcdf/saver/test__fillvalue_report.py b/lib/iris/tests/unit/fileformats/netcdf/saver/test__fillvalue_report.py
index 0b37070241..32059bb058 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/saver/test__fillvalue_report.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/saver/test__fillvalue_report.py
@@ -3,6 +3,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.fileformats.netcdf.saver._fillvalue_report`."""
+
import warnings
import numpy as np
diff --git a/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py b/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py
index 1f0a39f050..ae85dc1aab 100644
--- a/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py
+++ b/lib/iris/tests/unit/fileformats/netcdf/saver/test_save.py
@@ -3,6 +3,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 the :func:`iris.fileformats.netcdf.save` function."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/fileformats/pp/test__field_gen.py b/lib/iris/tests/unit/fileformats/pp/test__field_gen.py
index 80b90fc8d2..f1018d8df4 100644
--- a/lib/iris/tests/unit/fileformats/pp/test__field_gen.py
+++ b/lib/iris/tests/unit/fileformats/pp/test__field_gen.py
@@ -34,11 +34,14 @@ def make_pp_field_override(*args):
return result
open_func = "builtins.open"
- with mock.patch("numpy.fromfile", return_value=[0]), mock.patch(
- open_func
- ), mock.patch("struct.unpack_from", return_value=[4]), mock.patch(
- "iris.fileformats.pp.make_pp_field",
- side_effect=make_pp_field_override,
+ with (
+ mock.patch("numpy.fromfile", return_value=[0]),
+ mock.patch(open_func),
+ mock.patch("struct.unpack_from", return_value=[4]),
+ mock.patch(
+ "iris.fileformats.pp.make_pp_field",
+ side_effect=make_pp_field_override,
+ ),
):
yield
diff --git a/lib/iris/tests/unit/plot/test_hist.py b/lib/iris/tests/unit/plot/test_hist.py
index feef8f1062..9c1740587c 100644
--- a/lib/iris/tests/unit/plot/test_hist.py
+++ b/lib/iris/tests/unit/plot/test_hist.py
@@ -3,6 +3,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 the `iris.plot.hist` function."""
+
# Import iris.tests first so that some things can be initialised before
# importing anything else.
import iris.tests as tests # isort:skip
diff --git a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py
index d7b617d848..e3ee535346 100644
--- a/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py
+++ b/lib/iris/tests/unit/representation/cube_printout/test_CubePrintout.py
@@ -3,6 +3,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 :class:`iris._representation.cube_printout.CubePrintout`."""
+
import iris.tests as tests # isort:skip
import numpy as np
@@ -124,9 +125,9 @@ def test_columns_long_coordname(self):
def test_columns_long_attribute(self):
cube = Cube([0], long_name="short", units=1)
- cube.attributes[
- "very_very_very_very_very_long_name"
- ] = "longish string extends beyond dim columns"
+ cube.attributes["very_very_very_very_very_long_name"] = (
+ "longish string extends beyond dim columns"
+ )
rep = cube_replines(cube)
expected = [
"short / (1) (-- : 1)",
diff --git a/lib/iris/tests/unit/representation/cube_printout/test_Table.py b/lib/iris/tests/unit/representation/cube_printout/test_Table.py
index 0e00da7c42..6c765516b1 100644
--- a/lib/iris/tests/unit/representation/cube_printout/test_Table.py
+++ b/lib/iris/tests/unit/representation/cube_printout/test_Table.py
@@ -3,6 +3,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 :class:`iris._representation.cube_printout.Table`."""
+
from iris._representation.cube_printout import Table
import iris.tests as tests
diff --git a/lib/iris/util.py b/lib/iris/util.py
index 87837f6111..045e46d072 100644
--- a/lib/iris/util.py
+++ b/lib/iris/util.py
@@ -3,6 +3,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.
"""Miscellaneous utility functions."""
+
from __future__ import annotations
from abc import ABCMeta, abstractmethod