Skip to content

Commit

Permalink
MAINT: Remove tm.TestCase from testing (#16225)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyoung authored and jreback committed May 4, 2017
1 parent 4a748cc commit 1f5ecc9
Show file tree
Hide file tree
Showing 208 changed files with 446 additions and 491 deletions.
4 changes: 2 additions & 2 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ the expected correct result::
Transitioning to ``pytest``
~~~~~~~~~~~~~~~~~~~~~~~~~~~

*pandas* existing test structure is *mostly* classed based, meaning that you will typically find tests wrapped in a class, inheriting from ``tm.TestCase``.
*pandas* existing test structure is *mostly* classed based, meaning that you will typically find tests wrapped in a class.

.. code-block:: python
class TestReallyCoolFeature(tm.TestCase):
class TestReallyCoolFeature(object):
....
Going forward, we are moving to a more *functional* style using the `pytest <http://doc.pytest.org/en/latest/>`__ framework, which offers a richer testing
Expand Down
7 changes: 7 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def pytest_runtest_setup(item):
pytest.skip("skipping due to --skip-network")


# Configurations for all tests and all test modules

@pytest.fixture(autouse=True)
def configure_tests():
pandas.set_option('chained_assignment', 'raise')


# For running doctests: make np and pd names available

@pytest.fixture(autouse=True)
Expand Down
18 changes: 9 additions & 9 deletions pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def check(self, namespace, expected, ignored=None):
tm.assert_almost_equal(result, expected)


class TestPDApi(Base, tm.TestCase):
class TestPDApi(Base):

# these are optionally imported based on testing
# & need to be ignored
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_api(self):
self.ignored)


class TestApi(Base, tm.TestCase):
class TestApi(Base):

allowed = ['types']

Expand All @@ -137,7 +137,7 @@ def test_testing(self):
self.check(testing, self.funcs)


class TestDatetoolsDeprecation(tm.TestCase):
class TestDatetoolsDeprecation(object):

def test_deprecation_access_func(self):
with tm.assert_produces_warning(FutureWarning,
Expand All @@ -150,7 +150,7 @@ def test_deprecation_access_obj(self):
pd.datetools.monthEnd


class TestTopLevelDeprecations(tm.TestCase):
class TestTopLevelDeprecations(object):

# top-level API deprecations
# GH 13790
Expand Down Expand Up @@ -191,35 +191,35 @@ def test_get_store(self):
s.close()


class TestJson(tm.TestCase):
class TestJson(object):

def test_deprecation_access_func(self):
with catch_warnings(record=True):
pd.json.dumps([])


class TestParser(tm.TestCase):
class TestParser(object):

def test_deprecation_access_func(self):
with catch_warnings(record=True):
pd.parser.na_values


class TestLib(tm.TestCase):
class TestLib(object):

def test_deprecation_access_func(self):
with catch_warnings(record=True):
pd.lib.infer_dtype('foo')


class TestTSLib(tm.TestCase):
class TestTSLib(object):

def test_deprecation_access_func(self):
with catch_warnings(record=True):
pd.tslib.Timestamp('20160101')


class TestTypes(tm.TestCase):
class TestTypes(object):

def test_deprecation_access_func(self):
with tm.assert_produces_warning(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/api/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .test_api import Base


class TestTypes(Base, tm.TestCase):
class TestTypes(Base):

allowed = ['is_bool', 'is_bool_dtype',
'is_categorical', 'is_categorical_dtype', 'is_complex',
Expand Down
13 changes: 4 additions & 9 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ def _is_py3_complex_incompat(result, expected):
_good_arith_ops = com.difference(_arith_ops_syms, _special_case_arith_ops_syms)


class TestEvalNumexprPandas(tm.TestCase):
class TestEvalNumexprPandas(object):

@classmethod
def setup_class(cls):
super(TestEvalNumexprPandas, cls).setup_class()
tm.skip_if_no_ne()
import numexpr as ne
cls.ne = ne
Expand All @@ -108,7 +107,6 @@ def setup_class(cls):

@classmethod
def teardown_class(cls):
super(TestEvalNumexprPandas, cls).teardown_class()
del cls.engine, cls.parser
if hasattr(cls, 'ne'):
del cls.ne
Expand Down Expand Up @@ -1067,19 +1065,17 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
# ------------------------------------
# Slightly more complex ops

class TestOperationsNumExprPandas(tm.TestCase):
class TestOperationsNumExprPandas(object):

@classmethod
def setup_class(cls):
super(TestOperationsNumExprPandas, cls).setup_class()
tm.skip_if_no_ne()
cls.engine = 'numexpr'
cls.parser = 'pandas'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms

@classmethod
def teardown_class(cls):
super(TestOperationsNumExprPandas, cls).teardown_class()
del cls.engine, cls.parser

def eval(self, *args, **kwargs):
Expand Down Expand Up @@ -1584,11 +1580,10 @@ def setup_class(cls):
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms


class TestMathPythonPython(tm.TestCase):
class TestMathPythonPython(object):

@classmethod
def setup_class(cls):
super(TestMathPythonPython, cls).setup_class()
tm.skip_if_no_ne()
cls.engine = 'python'
cls.parser = 'pandas'
Expand Down Expand Up @@ -1873,7 +1868,7 @@ def test_negate_lt_eq_le(engine, parser):
tm.assert_frame_equal(result, expected)


class TestValidate(tm.TestCase):
class TestValidate(object):

def test_validate_bool_args(self):
invalid_values = [1, "True", [1, 2, 3], 5.0]
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/dtypes/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pandas.util import testing as tm


class TestMaybeDowncast(tm.TestCase):
class TestMaybeDowncast(object):

def test_downcast_conv(self):
# test downcasting
Expand Down Expand Up @@ -156,7 +156,7 @@ def test_infer_dtype_from_array(self, arr, expected):
assert dtype == expected


class TestMaybe(tm.TestCase):
class TestMaybe(object):

def test_maybe_convert_string_to_array(self):
result = maybe_convert_string_to_object('x')
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_maybe_convert_scalar(self):
assert result == Timedelta('1 day 1 min').value


class TestConvert(tm.TestCase):
class TestConvert(object):

def test_maybe_convert_objects_copy(self):
values = np.array([1, 2])
Expand All @@ -233,7 +233,7 @@ def test_maybe_convert_objects_copy(self):
assert values is not out


class TestCommonTypes(tm.TestCase):
class TestCommonTypes(object):

def test_numpy_dtypes(self):
# (source_types, destination_type)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import pandas.util.testing as tm


class TestPandasDtype(tm.TestCase):
class TestPandasDtype(object):

# Passing invalid dtype, both as a string or object, must raise TypeError
# Per issue GH15520
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/dtypes/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import pandas as pd
import pandas.core.dtypes.concat as _concat
import pandas.util.testing as tm


class TestConcatCompat(tm.TestCase):
class TestConcatCompat(object):

def check_concat(self, to_concat, exp):
for klass in [pd.Index, pd.Series]:
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from warnings import catch_warnings
import numpy as np
import pandas as pd
import pandas.util.testing as tm
from pandas.core.dtypes import generic as gt


class TestABCClasses(tm.TestCase):
class TestABCClasses(object):
tuples = [[1, 2, 2], ['red', 'blue', 'red']]
multi_index = pd.MultiIndex.from_arrays(tuples, names=('number', 'color'))
datetime_index = pd.to_datetime(['2000/1/1', '2010/1/1'])
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_is_recompilable():
assert not inference.is_re_compilable(f)


class TestInference(tm.TestCase):
class TestInference(object):

def test_infer_dtype_bytes(self):
compare = 'string' if PY2 else 'bytes'
Expand Down Expand Up @@ -405,7 +405,7 @@ def test_mixed_dtypes_remain_object_array(self):
tm.assert_numpy_array_equal(result, array)


class TestTypeInference(tm.TestCase):
class TestTypeInference(object):

def test_length_zero(self):
result = lib.infer_dtype(np.array([], dtype='i4'))
Expand Down Expand Up @@ -774,7 +774,7 @@ def test_categorical(self):
assert result == 'categorical'


class TestNumberScalar(tm.TestCase):
class TestNumberScalar(object):

def test_is_number(self):

Expand Down Expand Up @@ -917,7 +917,7 @@ def test_is_timedelta(self):
assert not is_timedelta64_ns_dtype(tdi.astype('timedelta64[h]'))


class Testisscalar(tm.TestCase):
class Testisscalar(object):

def test_isscalar_builtin_scalars(self):
assert is_scalar(None)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pandas.compat import long, u


class TestParseSQL(tm.TestCase):
class TestParseSQL(object):

def test_convert_sql_column_floats(self):
arr = np.array([1.5, None, 3, 4.2], dtype=object)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_notnull():
assert (isinstance(isnull(s), Series))


class TestIsNull(tm.TestCase):
class TestIsNull(object):

def test_0d_array(self):
assert isnull(np.array(np.nan))
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pandas.tests.frame.common import TestData


class TestDataFrameAlterAxes(tm.TestCase, TestData):
class TestDataFrameAlterAxes(TestData):

def test_set_index(self):
idx = Index(np.arange(len(self.mixed_frame)))
Expand Down Expand Up @@ -806,7 +806,7 @@ def test_set_index_preserve_categorical_dtype(self):
tm.assert_frame_equal(result, df)


class TestIntervalIndex(tm.TestCase):
class TestIntervalIndex(object):

def test_setitem(self):

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pandas.tests.frame.common import TestData


class TestDataFrameAnalytics(tm.TestCase, TestData):
class TestDataFrameAnalytics(TestData):

# ---------------------------------------------------------------------=
# Correlation and covariance
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_add_prefix_suffix(self):
tm.assert_index_equal(with_suffix.columns, expected)


class TestDataFrameMisc(tm.TestCase, SharedWithSparse, TestData):
class TestDataFrameMisc(SharedWithSparse, TestData):

klass = DataFrame

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pandas.tests.frame.common import TestData


class TestDataFrameApply(tm.TestCase, TestData):
class TestDataFrameApply(TestData):

def test_apply(self):
with np.errstate(all='ignore'):
Expand Down Expand Up @@ -482,7 +482,7 @@ def zip_frames(*frames):
return pd.concat(zipped, axis=1)


class TestDataFrameAggregate(tm.TestCase, TestData):
class TestDataFrameAggregate(TestData):

_multiprocess_can_split_ = True

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_asof.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .common import TestData


class TestFrameAsof(TestData, tm.TestCase):
class TestFrameAsof(TestData):
def setup_method(self, method):
self.N = N = 50
self.rng = date_range('1/1/1990', periods=N, freq='53s')
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pandas.tests.frame.common import TestData


class TestDataFrameSelectReindex(tm.TestCase, TestData):
class TestDataFrameSelectReindex(TestData):
# These are specific reindex-based tests; other indexing tests should go in
# test_indexing

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_block_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# structure


class TestDataFrameBlockInternals(tm.TestCase, TestData):
class TestDataFrameBlockInternals(TestData):

def test_cast_internals(self):
casted = DataFrame(self.frame._data, dtype=int)
Expand Down
Loading

0 comments on commit 1f5ecc9

Please sign in to comment.