Skip to content

Commit 1af2060

Browse files
authored
Test wrangling vs v3.0.x (#4249)
* test changes * add awol init * rename system test cases * fix PartialDateTime tests * fix typo * add whatsnew
1 parent dd91f04 commit 1af2060

File tree

7 files changed

+33
-19
lines changed

7 files changed

+33
-19
lines changed

docs/iris/src/whatsnew/3.0.4.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ This document explains the changes made to Iris for this release
3131
to allow use of the latest versions of `cftime`_, `cf-units`_ and `nc-time-axis`_.
3232
(:pull:`4222`)
3333

34+
#. `@rcomer`_ modified test modules so they run consistently under ``pytest`` and
35+
``nose``, and also fixed some minor issues with :class:`~iris.time.PartialDateTime`.
36+
(:pull:`4249`)
37+
3438
Note that, we are forced to drop support for ``Python 3.6`` in this patch due to
3539
the third-party package dependencies required by (:pull:`4222`).
3640

lib/iris/tests/system_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
class SystemInitialTest(tests.IrisTest):
25-
def system_test_supported_filetypes(self):
25+
def test_supported_filetypes(self):
2626
nx, ny = 60, 60
2727
data = np.arange(nx * ny, dtype=">f4").reshape(nx, ny)
2828

@@ -74,7 +74,7 @@ def horiz_cs():
7474
new_cube, ("system", "supported_filetype_%s.cml" % filetype)
7575
)
7676

77-
def system_test_imports_general(self):
77+
def test_imports_general(self):
7878
if tests.MPL_AVAILABLE:
7979
import matplotlib # noqa
8080
import netCDF4 # noqa

lib/iris/tests/test_merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import iris.tests.stock
2626

2727

28-
class TestMixin:
28+
class MergeMixin:
2929
"""
3030
Mix-in class for attributes & utilities common to these test cases.
3131
@@ -55,15 +55,15 @@ def test_duplication(self):
5555

5656

5757
@tests.skip_data
58-
class TestSingleCube(tests.IrisTest, TestMixin):
58+
class TestSingleCube(tests.IrisTest, MergeMixin):
5959
def setUp(self):
6060
self._data_path = tests.get_data_path(("PP", "globClim1", "theta.pp"))
6161
self._num_cubes = 1
6262
self._prefix = "theta"
6363

6464

6565
@tests.skip_data
66-
class TestMultiCube(tests.IrisTest, TestMixin):
66+
class TestMultiCube(tests.IrisTest, MergeMixin):
6767
def setUp(self):
6868
self._data_path = tests.get_data_path(
6969
("PP", "globClim1", "dec_subset.pp")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright Iris contributors
2+
#
3+
# This file is part of Iris and is released under the LGPL license.
4+
# See COPYING and COPYING.LESSER in the root of the repository for full
5+
# licensing details.
6+
"""Unit tests for the :mod:`iris.analysis.scipy_interpolate` module."""
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright Iris contributors
2+
#
3+
# This file is part of Iris and is released under the LGPL license.
4+
# See COPYING and COPYING.LESSER in the root of the repository for full
5+
# licensing details.
6+
"""Unit tests for the :mod:`iris.time` module."""

lib/iris/tests/unit/time/test_PartialDateTime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ def setUp(self):
224224
self.expected_value = EQ_EXPECTATIONS
225225

226226
def test_cftime_equal(self):
227-
pdt = PartialDateTime(month=3, microsecond=2)
227+
pdt = PartialDateTime(month=3, second=2)
228228
other = cftime.datetime(year=2013, month=3, day=20, second=2)
229229
self.assertTrue(pdt == other)
230230

231231
def test_cftime_not_equal(self):
232-
pdt = PartialDateTime(month=3, microsecond=2)
232+
pdt = PartialDateTime(month=3, second=2)
233233
other = cftime.datetime(year=2013, month=4, day=20, second=2)
234234
self.assertFalse(pdt == other)
235235

lib/iris/time.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,21 @@ def __eq__(self, other):
155155
other_attr = other.microsecond
156156
if attr is not None and attr != other_attr:
157157
result = False
158+
158159
except AttributeError:
159-
result = NotImplemented
160+
result = other.__eq__(self)
161+
if result is NotImplemented:
162+
# Equality is undefined between these objects. We don't
163+
# want Python to fall back to the default `object`
164+
# behaviour (which compares using object IDs), so we raise
165+
# an exception here instead.
166+
fmt = "unable to compare PartialDateTime with {}"
167+
raise TypeError(fmt.format(type(other)))
168+
160169
return result
161170

162171
def __ne__(self, other):
163172
result = self.__eq__(other)
164173
if result is not NotImplemented:
165174
result = not result
166175
return result
167-
168-
def __cmp__(self, other):
169-
# Since we've defined all the rich comparison operators (via
170-
# functools.total_ordering), we can only reach this point if
171-
# neither this class nor the other class had a rich comparison
172-
# that could handle the type combination.
173-
# We don't want Python to fall back to the default `object`
174-
# behaviour (which compares using object IDs), so we raise an
175-
# exception here instead.
176-
fmt = "unable to compare PartialDateTime with {}"
177-
raise TypeError(fmt.format(type(other)))

0 commit comments

Comments
 (0)