Skip to content

Commit bb87a94

Browse files
authored
Replace the last of unittest with pytest (#2467)
* cleaning * remove assertEqual * remove assertItems * more removing assertitems * remove assertequal * remove TestCase * straggler * pep8replies * pep8replies2 * small flups * pytest.warns requires Warning class * tuple list comparisons * disable test check * set / list * the last unittest survivor, and automated formatting changes where possible
1 parent 4a7a103 commit bb87a94

17 files changed

+346
-366
lines changed

xarray/tests/__init__.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010
import numpy as np
1111
from numpy.testing import assert_array_equal # noqa: F401
12-
from xarray.core.duck_array_ops import allclose_or_equiv
12+
from xarray.core.duck_array_ops import allclose_or_equiv # noqa
1313
import pytest
1414

1515
from xarray.core import utils
16-
from xarray.core.pycompat import PY3
1716
from xarray.core.indexing import ExplicitlyIndexed
1817
from xarray.testing import (assert_equal, assert_identical, # noqa: F401
1918
assert_allclose)
@@ -25,10 +24,6 @@
2524
# old location, for pandas < 0.20
2625
from pandas.util.testing import assert_frame_equal # noqa: F401
2726

28-
try:
29-
import unittest2 as unittest
30-
except ImportError:
31-
import unittest
3227

3328
try:
3429
from unittest import mock
@@ -117,39 +112,6 @@ def _importorskip(modname, minversion=None):
117112
"internet connection")
118113

119114

120-
class TestCase(unittest.TestCase):
121-
"""
122-
These functions are all deprecated. Instead, use functions in xr.testing
123-
"""
124-
if PY3:
125-
# Python 3 assertCountEqual is roughly equivalent to Python 2
126-
# assertItemsEqual
127-
def assertItemsEqual(self, first, second, msg=None):
128-
__tracebackhide__ = True # noqa: F841
129-
return self.assertCountEqual(first, second, msg)
130-
131-
@contextmanager
132-
def assertWarns(self, message):
133-
__tracebackhide__ = True # noqa: F841
134-
with warnings.catch_warnings(record=True) as w:
135-
warnings.filterwarnings('always', message)
136-
yield
137-
assert len(w) > 0
138-
assert any(message in str(wi.message) for wi in w)
139-
140-
def assertVariableNotEqual(self, v1, v2):
141-
__tracebackhide__ = True # noqa: F841
142-
assert not v1.equals(v2)
143-
144-
def assertEqual(self, a1, a2):
145-
__tracebackhide__ = True # noqa: F841
146-
assert a1 == a2 or (a1 != a1 and a2 != a2)
147-
148-
def assertAllClose(self, a1, a2, rtol=1e-05, atol=1e-8):
149-
__tracebackhide__ = True # noqa: F841
150-
assert allclose_or_equiv(a1, a2, rtol=rtol, atol=atol)
151-
152-
153115
@contextmanager
154116
def raises_regex(error, pattern):
155117
__tracebackhide__ = True # noqa: F841

xarray/tests/test_accessors.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import xarray as xr
88

99
from . import (
10-
TestCase, assert_array_equal, assert_equal, raises_regex, requires_dask,
11-
has_cftime, has_dask, has_cftime_or_netCDF4)
10+
assert_array_equal, assert_equal, has_cftime, has_cftime_or_netCDF4,
11+
has_dask, raises_regex, requires_dask)
1212

1313

14-
class TestDatetimeAccessor(TestCase):
15-
def setUp(self):
14+
class TestDatetimeAccessor(object):
15+
@pytest.fixture(autouse=True)
16+
def setup(self):
1617
nt = 100
1718
data = np.random.rand(10, 10, nt)
1819
lons = np.linspace(0, 11, 10)

0 commit comments

Comments
 (0)