From 4b90c88554ab133dd9b19d7bf8f0938dff75624c Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 11 Jun 2021 16:52:40 +0100 Subject: [PATCH 1/6] test changes --- lib/iris/tests/test_merge.py | 6 +++--- lib/iris/tests/unit/time/__init__.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 lib/iris/tests/unit/time/__init__.py diff --git a/lib/iris/tests/test_merge.py b/lib/iris/tests/test_merge.py index e404216143..b6bbdac8d9 100644 --- a/lib/iris/tests/test_merge.py +++ b/lib/iris/tests/test_merge.py @@ -25,7 +25,7 @@ import iris.tests.stock -class TestMixin: +class MergeMixin: """ Mix-in class for attributes & utilities common to these test cases. @@ -55,7 +55,7 @@ def test_duplication(self): @tests.skip_data -class TestSingleCube(tests.IrisTest, TestMixin): +class TestSingleCube(tests.IrisTest, MergeMixin): def setUp(self): self._data_path = tests.get_data_path(("PP", "globClim1", "theta.pp")) self._num_cubes = 1 @@ -63,7 +63,7 @@ def setUp(self): @tests.skip_data -class TestMultiCube(tests.IrisTest, TestMixin): +class TestMultiCube(tests.IrisTest, MergeMixin): def setUp(self): self._data_path = tests.get_data_path( ("PP", "globClim1", "dec_subset.pp") diff --git a/lib/iris/tests/unit/time/__init__.py b/lib/iris/tests/unit/time/__init__.py new file mode 100644 index 0000000000..3483b92e62 --- /dev/null +++ b/lib/iris/tests/unit/time/__init__.py @@ -0,0 +1,6 @@ +# Copyright Iris contributors +# +# This file is part of Iris and is released under the LGPL license. +# See COPYING and COPYING.LESSER in the root of the repository for full +# licensing details. +"""Unit tests for the :mod:`iris.time` module.""" From 3a46136f82e83d330dcae9ad18e8edba662a49b6 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Tue, 15 Jun 2021 12:34:17 +0100 Subject: [PATCH 2/6] add awol init --- lib/iris/tests/unit/analysis/scipy_interpolate/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 lib/iris/tests/unit/analysis/scipy_interpolate/__init__.py diff --git a/lib/iris/tests/unit/analysis/scipy_interpolate/__init__.py b/lib/iris/tests/unit/analysis/scipy_interpolate/__init__.py new file mode 100644 index 0000000000..67218194c2 --- /dev/null +++ b/lib/iris/tests/unit/analysis/scipy_interpolate/__init__.py @@ -0,0 +1,6 @@ +# Copyright Iris contributors +# +# This file is part of Iris and is released under the LGPL license. +# See COPYING and COPYING.LESSER in the root of the repository for full +# licensing details. +"""Unit tests for the :mod:`iris.analysis.scipy_interpolate` module.""" From 3b27a6bad91e430f13592844c4ee7691cdfdd6a7 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Tue, 15 Jun 2021 18:05:50 +0100 Subject: [PATCH 3/6] rename system test cases --- lib/iris/tests/system_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/iris/tests/system_test.py b/lib/iris/tests/system_test.py index a98a83768a..486c5fc0a2 100644 --- a/lib/iris/tests/system_test.py +++ b/lib/iris/tests/system_test.py @@ -22,7 +22,7 @@ class SystemInitialTest(tests.IrisTest): - def system_test_supported_filetypes(self): + def test_supported_filetypes(self): nx, ny = 60, 60 data = np.arange(nx * ny, dtype=">f4").reshape(nx, ny) @@ -74,7 +74,7 @@ def horiz_cs(): new_cube, ("system", "supported_filetype_%s.cml" % filetype) ) - def system_test_imports_general(self): + def test_imports_general(self): if tests.MPL_AVAILABLE: import matplotlib # noqa import netCDF4 # noqa From 9b5691b1176ac16870be2c4631ca22907de9c7e5 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Wed, 16 Jun 2021 15:21:56 +0100 Subject: [PATCH 4/6] fix PartialDateTime tests --- .../tests/unit/time/test_PartialDateTime.py | 4 ++-- lib/iris/time.py | 22 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/iris/tests/unit/time/test_PartialDateTime.py b/lib/iris/tests/unit/time/test_PartialDateTime.py index a543ff166f..a6cf9cc7ef 100644 --- a/lib/iris/tests/unit/time/test_PartialDateTime.py +++ b/lib/iris/tests/unit/time/test_PartialDateTime.py @@ -224,12 +224,12 @@ def setUp(self): self.expected_value = EQ_EXPECTATIONS def test_cftime_equal(self): - pdt = PartialDateTime(month=3, microsecond=2) + pdt = PartialDateTime(month=3, second=2) other = cftime.datetime(year=2013, month=3, day=20, second=2) self.assertTrue(pdt == other) def test_cftime_not_equal(self): - pdt = PartialDateTime(month=3, microsecond=2) + pdt = PartialDateTime(month=3, second=2) other = cftime.datetime(year=2013, month=4, day=20, second=2) self.assertFalse(pdt == other) diff --git a/lib/iris/time.py b/lib/iris/time.py index cd2b780421..e516314697 100644 --- a/lib/iris/time.py +++ b/lib/iris/time.py @@ -155,8 +155,17 @@ def __eq__(self, other): other_attr = other.microsecond if attr is not None and attr != other_attr: result = False + except AttributeError: - result = NotImplemented + result = other.__eq__(self) + if result is NotImplemented: + # Equaliy is undefined between these objects. We don't + # want Python to fall back to the default `object` + # behaviour (which compares using object IDs), so we raise + # an exception here instead. + fmt = "unable to compare PartialDateTime with {}" + raise TypeError(fmt.format(type(other))) + return result def __ne__(self, other): @@ -164,14 +173,3 @@ def __ne__(self, other): if result is not NotImplemented: result = not result return result - - def __cmp__(self, other): - # Since we've defined all the rich comparison operators (via - # functools.total_ordering), we can only reach this point if - # neither this class nor the other class had a rich comparison - # that could handle the type combination. - # We don't want Python to fall back to the default `object` - # behaviour (which compares using object IDs), so we raise an - # exception here instead. - fmt = "unable to compare PartialDateTime with {}" - raise TypeError(fmt.format(type(other))) From 7b9df303c0d58987765f4ff65c05eafadd1bff45 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Thu, 22 Jul 2021 10:52:24 +0100 Subject: [PATCH 5/6] fix typo --- lib/iris/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/iris/time.py b/lib/iris/time.py index e516314697..51aac3d46d 100644 --- a/lib/iris/time.py +++ b/lib/iris/time.py @@ -159,7 +159,7 @@ def __eq__(self, other): except AttributeError: result = other.__eq__(self) if result is NotImplemented: - # Equaliy is undefined between these objects. We don't + # Equality is undefined between these objects. We don't # want Python to fall back to the default `object` # behaviour (which compares using object IDs), so we raise # an exception here instead. From 7ff16a75b335121d26e11cabb9df810fd596b8a7 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Thu, 22 Jul 2021 16:37:50 +0100 Subject: [PATCH 6/6] add whatsnew --- docs/iris/src/whatsnew/3.0.4.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/iris/src/whatsnew/3.0.4.rst b/docs/iris/src/whatsnew/3.0.4.rst index 47a95a2ce5..de0cec8315 100644 --- a/docs/iris/src/whatsnew/3.0.4.rst +++ b/docs/iris/src/whatsnew/3.0.4.rst @@ -31,6 +31,10 @@ This document explains the changes made to Iris for this release to allow use of the latest versions of `cftime`_, `cf-units`_ and `nc-time-axis`_. (:pull:`4222`) + #. `@rcomer`_ modified test modules so they run consistently under ``pytest`` and + ``nose``, and also fixed some minor issues with :class:`~iris.time.PartialDateTime`. + (:pull:`4249`) + Note that, we are forced to drop support for ``Python 3.6`` in this patch due to the third-party package dependencies required by (:pull:`4222`).