Skip to content

Commit

Permalink
precommit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HGWright committed Oct 31, 2024
1 parent 50d1c37 commit 20bb1e3
Show file tree
Hide file tree
Showing 47 changed files with 68 additions and 24 deletions.
10 changes: 4 additions & 6 deletions lib/iris/tests/_shared_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import re
import shutil
import subprocess
from typing import AnyStr
from typing import Optional
import warnings
import xml.dom.minidom
import zlib
Expand Down Expand Up @@ -380,7 +380,7 @@ def sort_key(line):

dimension_lines = slice(lines.index("dimensions:") + 1, lines.index("variables:"))
lines[dimension_lines] = sorted(lines[dimension_lines], key=sort_key)
cdl = "\n".join(lines) + "\n"
cdl = "\n".join(lines) + "\n" # type: ignore[assignment]

_check_same(cdl, reference_path, type_comparison_name="CDL")

Expand Down Expand Up @@ -543,9 +543,7 @@ def assert_repr(request: pytest.FixtureRequest, obj, reference_filename):
def _check_same(item, reference_path, type_comparison_name="CML"):
if _check_reference_file(reference_path):
with open(reference_path, "rb") as reference_fh:
reference = "".join(
part.decode("utf-8") for part in reference_fh.readlines()
)
reference = "".join(part.decode("utf-8") for part in reference_fh)
_assert_str_same(reference, item, reference_path, type_comparison_name)
else:
_ensure_folder(reference_path)
Expand Down Expand Up @@ -966,7 +964,7 @@ def wrapped(*args, **kwargs):
return wrapped


def env_bin_path(exe_name: AnyStr = None):
def env_bin_path(exe_name: Optional[str] = None):
"""Return a Path object for (an executable in) the environment bin directory.
Parameters
Expand Down
3 changes: 2 additions & 1 deletion lib/iris/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

from collections import defaultdict
from typing import Callable

import pytest

Expand All @@ -27,7 +28,7 @@ def test_call_counter():


@pytest.fixture
def _unique_id(request: pytest.FixtureRequest, test_call_counter) -> callable:
def _unique_id(request: pytest.FixtureRequest, test_call_counter) -> Callable:
"""Provide a function returning a unique ID of calling test and call number.
Example: ``iris.tests.unit.test_cube.TestCube.test_data.my_param.0``
Expand Down
4 changes: 2 additions & 2 deletions lib/iris/tests/graphics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pathlib import Path
import sys
import threading
from typing import Callable, Dict, Union
from typing import Callable, Dict, Iterator, Union

import filelock
import pytest
Expand Down Expand Up @@ -285,7 +285,7 @@ def skip_plot(fn: Callable) -> Callable:


@pytest.fixture
def _check_graphic_caller(_unique_id) -> callable:
def _check_graphic_caller(_unique_id) -> Iterator[Callable]:
"""Provide a function calling :func:`check_graphic` with safe configuration.
Ensures a safe Matplotlib setup (and tears down afterwards), and generates
Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/integration/plot/test_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 :func:`iris.plot.animate`."""

import numpy as np
import pytest

Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/integration/plot/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`matplotlib.pyplot.colorbar`.
"""

import numpy as np
import pytest

Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/integration/plot/test_netcdftime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 plot of time coord with non-standard calendar."""

from cf_units import Unit
import cftime
import numpy as np
Expand Down
1 change: 0 additions & 1 deletion lib/iris/tests/integration/plot/test_plot_2d_coords.py
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.
"""Test plots with two dimensional coordinates."""


import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
Expand Down
5 changes: 1 addition & 4 deletions lib/iris/tests/unit/common/metadata/test_CubeMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

# Import iris.tests first so that some things can be initialised before
# importing anything else.
from typing import Any, ClassVar

from copy import deepcopy

from copy import deepcopy
from typing import Any, ClassVar

import pytest

Expand Down
1 change: 0 additions & 1 deletion lib/iris/tests/unit/concatenate/test_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_concat_1d_with_same_time_units(self, simple_1d_time_cubes):


class _MessagesMixin:

@pytest.fixture()
def placeholder(self):
# Shim to allow sample_cubes to have identical signature in both parent and subclasses
Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/abf/test_ABFField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.abf.ABFField` class."""

from iris.fileformats.abf import ABFField


Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/cf/test_CFGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.fileformats.cf.CFGroup` class."""

from unittest.mock import MagicMock

import pytest
Expand Down
6 changes: 3 additions & 3 deletions lib/iris/tests/unit/fileformats/cf/test_CFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.cf.CFReader` class."""

from unittest import mock

import numpy as np
Expand Down Expand Up @@ -366,8 +367,8 @@ def _setup_class(self, mocker):
file_format="NetCDF4", variables=self.variables, ncattrs=ncattrs
)

# @pytest.fixture(autouse=True)
# def _setup(self, mocker):
# @pytest.fixture(autouse=True)
# def _setup(self, mocker):
# Restrict the CFReader functionality to only performing
# translations and building first level cf-groups for variables.
mocker.patch("iris.fileformats.cf.CFReader._reset")
Expand Down Expand Up @@ -406,4 +407,3 @@ def test_ugrid_coords(self):

def test_is_cf_ugrid_group(self):
assert isinstance(self.cf_group, CFGroup)

1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/dot/test__dot_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.dot._dot_path`."""

import os.path
import subprocess

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.name_loaders._build_cell_methods`."""

import pytest

import iris.coords
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.analysis.name_loaders._build_lat_lon_for_NAME_timeseries`."""

from iris.fileformats.name_loaders import NAMECoord, _build_lat_lon_for_NAME_timeseries
from iris.tests._shared_utils import assert_array_equal

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.name_loaders.__calc_integration_period`."""

import datetime

from iris.fileformats.name_loaders import _calc_integration_period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
function.
"""

import numpy as np

from iris.coords import AuxCoord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.analysis.name_loaders._generate_cubes`."""

from datetime import datetime, timedelta
from unittest import mock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.nimrod_load_rules.units` function."""

import numpy as np
import pytest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
function.
"""

import pytest

from iris.fileformats.nimrod import NimrodField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.pp_load_rules._all_other_rules` function."""

from unittest import mock

from cf_units import CALENDAR_360_DAY, Unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._collapse_degenerate_points_and_bounds`.
"""

import numpy as np

from iris.fileformats.pp_load_rules import _collapse_degenerate_points_and_bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._convert_pseudo_level_coords`.
"""

from iris.coords import DimCoord
from iris.fileformats.pp_load_rules import _convert_scalar_pseudo_level_coords

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._convert_scalar_realization_coords`.
"""

from iris.coords import DimCoord
from iris.fileformats.pp_load_rules import _convert_scalar_realization_coords

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._convert_time_coords`.
"""

from cf_units import CALENDAR_360_DAY, CALENDAR_STANDARD, Unit
from cftime import datetime as nc_datetime
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._convert_vertical_coords`.
"""

import numpy as np

from iris.aux_factory import HybridHeightFactory, HybridPressureFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.pp_load_rules._dim_or_aux`."""

import pytest

from iris.coords import AuxCoord, DimCoord
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._epoch_date_hours`.
"""

import cf_units
from cf_units import Unit
from cftime import datetime as nc_datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.pp_load_rules._model_level_number`."""

from iris.fileformats.pp_load_rules import _model_level_number


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._reduce_points_and_bounds`.
"""

import numpy as np

from iris.fileformats.pp_load_rules import _reduce_points_and_bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:func:`iris.fileformats.pp_load_rules._reshape_vector_args`.
"""

import numpy as np
import pytest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.pp_load_rules.convert`."""

from types import MethodType
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/rules/test_Loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.fileformats.rules.Loader`."""

from iris.fileformats.rules import Loader
from iris.tests._shared_utils import assert_no_warnings_regexp

Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/rules/test__make_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.rules._make_cube`."""

from unittest import mock

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions lib/iris/tests/unit/fileformats/rules/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 iris.fileformats.rules.py - metadata translation rules."""

import types
from unittest import mock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:mod:`iris.fileformats._structured_array_identification.ArrayStructure` class.
"""

import numpy as np
import pytest

Expand Down
Loading

0 comments on commit 20bb1e3

Please sign in to comment.