Skip to content
forked from pydata/xarray

Commit

Permalink
Replace the last of unittest with pytest (pydata#2467)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
max-sixty authored Oct 6, 2018
1 parent 4a7a103 commit bb87a94
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 366 deletions.
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

0 comments on commit bb87a94

Please sign in to comment.