Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the last of unittest with pytest #2467

Merged
merged 16 commits into from
Oct 6, 2018
40 changes: 1 addition & 39 deletions xarray/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

import numpy as np
from numpy.testing import assert_array_equal # noqa: F401
from xarray.core.duck_array_ops import allclose_or_equiv
from xarray.core.duck_array_ops import allclose_or_equiv # noqa
import pytest

from xarray.core import utils
from xarray.core.pycompat import PY3
from xarray.core.indexing import ExplicitlyIndexed
from xarray.testing import (assert_equal, assert_identical, # noqa: F401
assert_allclose)
Expand All @@ -25,10 +24,6 @@
# old location, for pandas < 0.20
from pandas.util.testing import assert_frame_equal # noqa: F401

try:
import unittest2 as unittest
except ImportError:
import unittest

try:
from unittest import mock
Expand Down Expand Up @@ -117,39 +112,6 @@ def _importorskip(modname, minversion=None):
"internet connection")


class TestCase(unittest.TestCase):
"""
These functions are all deprecated. Instead, use functions in xr.testing
"""
if PY3:
# Python 3 assertCountEqual is roughly equivalent to Python 2
# assertItemsEqual
def assertItemsEqual(self, first, second, msg=None):
__tracebackhide__ = True # noqa: F841
return self.assertCountEqual(first, second, msg)

@contextmanager
def assertWarns(self, message):
__tracebackhide__ = True # noqa: F841
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', message)
yield
assert len(w) > 0
assert any(message in str(wi.message) for wi in w)

def assertVariableNotEqual(self, v1, v2):
__tracebackhide__ = True # noqa: F841
assert not v1.equals(v2)

def assertEqual(self, a1, a2):
__tracebackhide__ = True # noqa: F841
assert a1 == a2 or (a1 != a1 and a2 != a2)

def assertAllClose(self, a1, a2, rtol=1e-05, atol=1e-8):
__tracebackhide__ = True # noqa: F841
assert allclose_or_equiv(a1, a2, rtol=rtol, atol=atol)


@contextmanager
def raises_regex(error, pattern):
__tracebackhide__ = True # noqa: F841
Expand Down
9 changes: 5 additions & 4 deletions xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import xarray as xr

from . import (
TestCase, assert_array_equal, assert_equal, raises_regex, requires_dask,
has_cftime, has_dask, has_cftime_or_netCDF4)
assert_array_equal, assert_equal, has_cftime, has_cftime_or_netCDF4,
has_dask, raises_regex, requires_dask)


class TestDatetimeAccessor(TestCase):
def setUp(self):
class TestDatetimeAccessor(object):
@pytest.fixture(autouse=True)
def setup(self):
nt = 100
data = np.random.rand(10, 10, nt)
lons = np.linspace(0, 11, 10)
Expand Down
Loading