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

MAINT: Complete Conversion to Pytest Idiom #16201

Merged
merged 5 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -632,14 +632,6 @@ framework that will facilitate testing and developing. Thus, instead of writing
def test_really_cool_feature():
....

Sometimes, it does make sense to bundle test functions together into a single class, either because the test file is testing multiple functions from a single module, and
using test classes allows for better organization. However, instead of inheriting from ``tm.TestCase``, we should just inherit from ``object``:

.. code-block:: python

class TestReallyCoolFeature(object):
....

Using ``pytest``
~~~~~~~~~~~~~~~~

Expand Down
62 changes: 31 additions & 31 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ def _is_py3_complex_incompat(result, expected):
class TestEvalNumexprPandas(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestEvalNumexprPandas, cls).setUpClass()
def setup_class(cls):
super(TestEvalNumexprPandas, cls).setup_class()
tm.skip_if_no_ne()
import numexpr as ne
cls.ne = ne
cls.engine = 'numexpr'
cls.parser = 'pandas'

@classmethod
def tearDownClass(cls):
super(TestEvalNumexprPandas, cls).tearDownClass()
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 @@ -137,12 +137,12 @@ def setup_ops(self):
self.arith_ops = _good_arith_ops
self.unary_ops = '-', '~', 'not '

def setUp(self):
def setup_method(self, method):
self.setup_ops()
self.setup_data()
self.current_engines = filter(lambda x: x != self.engine, _engines)

def tearDown(self):
def teardown_method(self, method):
del self.lhses, self.rhses, self.scalar_rhses, self.scalar_lhses
del self.pandas_rhses, self.pandas_lhses, self.current_engines

Expand Down Expand Up @@ -723,8 +723,8 @@ def test_float_truncation(self):
class TestEvalNumexprPython(TestEvalNumexprPandas):

@classmethod
def setUpClass(cls):
super(TestEvalNumexprPython, cls).setUpClass()
def setup_class(cls):
super(TestEvalNumexprPython, cls).setup_class()
tm.skip_if_no_ne()
import numexpr as ne
cls.ne = ne
Expand All @@ -750,8 +750,8 @@ def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
class TestEvalPythonPython(TestEvalNumexprPython):

@classmethod
def setUpClass(cls):
super(TestEvalPythonPython, cls).setUpClass()
def setup_class(cls):
super(TestEvalPythonPython, cls).setup_class()
cls.engine = 'python'
cls.parser = 'python'

Expand Down Expand Up @@ -780,8 +780,8 @@ def check_alignment(self, result, nlhs, ghs, op):
class TestEvalPythonPandas(TestEvalPythonPython):

@classmethod
def setUpClass(cls):
super(TestEvalPythonPandas, cls).setUpClass()
def setup_class(cls):
super(TestEvalPythonPandas, cls).setup_class()
cls.engine = 'python'
cls.parser = 'pandas'

Expand Down Expand Up @@ -1070,16 +1070,16 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
class TestOperationsNumExprPandas(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestOperationsNumExprPandas, cls).setUpClass()
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 tearDownClass(cls):
super(TestOperationsNumExprPandas, cls).tearDownClass()
def teardown_class(cls):
super(TestOperationsNumExprPandas, cls).teardown_class()
del cls.engine, cls.parser

def eval(self, *args, **kwargs):
Expand Down Expand Up @@ -1492,8 +1492,8 @@ def test_simple_in_ops(self):
class TestOperationsNumExprPython(TestOperationsNumExprPandas):

@classmethod
def setUpClass(cls):
super(TestOperationsNumExprPython, cls).setUpClass()
def setup_class(cls):
super(TestOperationsNumExprPython, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'python'
tm.skip_if_no_ne(cls.engine)
Expand Down Expand Up @@ -1566,8 +1566,8 @@ def test_simple_bool_ops(self):
class TestOperationsPythonPython(TestOperationsNumExprPython):

@classmethod
def setUpClass(cls):
super(TestOperationsPythonPython, cls).setUpClass()
def setup_class(cls):
super(TestOperationsPythonPython, cls).setup_class()
cls.engine = cls.parser = 'python'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
Expand All @@ -1577,8 +1577,8 @@ def setUpClass(cls):
class TestOperationsPythonPandas(TestOperationsNumExprPandas):

@classmethod
def setUpClass(cls):
super(TestOperationsPythonPandas, cls).setUpClass()
def setup_class(cls):
super(TestOperationsPythonPandas, cls).setup_class()
cls.engine = 'python'
cls.parser = 'pandas'
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
Expand All @@ -1587,16 +1587,16 @@ def setUpClass(cls):
class TestMathPythonPython(tm.TestCase):

@classmethod
def setUpClass(cls):
super(TestMathPythonPython, cls).setUpClass()
def setup_class(cls):
super(TestMathPythonPython, cls).setup_class()
tm.skip_if_no_ne()
cls.engine = 'python'
cls.parser = 'pandas'
cls.unary_fns = _unary_math_ops
cls.binary_fns = _binary_math_ops

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

def eval(self, *args, **kwargs):
Expand Down Expand Up @@ -1694,26 +1694,26 @@ def test_keyword_arg(self):
class TestMathPythonPandas(TestMathPythonPython):

@classmethod
def setUpClass(cls):
super(TestMathPythonPandas, cls).setUpClass()
def setup_class(cls):
super(TestMathPythonPandas, cls).setup_class()
cls.engine = 'python'
cls.parser = 'pandas'


class TestMathNumExprPandas(TestMathPythonPython):

@classmethod
def setUpClass(cls):
super(TestMathNumExprPandas, cls).setUpClass()
def setup_class(cls):
super(TestMathNumExprPandas, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'pandas'


class TestMathNumExprPython(TestMathPythonPython):

@classmethod
def setUpClass(cls):
super(TestMathNumExprPython, cls).setUpClass()
def setup_class(cls):
super(TestMathNumExprPython, cls).setup_class()
cls.engine = 'numexpr'
cls.parser = 'python'

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 @@ -10,7 +10,7 @@


class TestFrameAsof(TestData, tm.TestCase):
def setUp(self):
def setup_method(self, method):
self.N = N = 50
self.rng = date_range('1/1/1990', periods=N, freq='53s')
self.df = DataFrame({'A': np.arange(N), 'B': np.arange(N)},
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2914,7 +2914,7 @@ def test_type_error_multiindex(self):

class TestDataFrameIndexingDatetimeWithTZ(tm.TestCase, TestData):

def setUp(self):
def setup_method(self, method):
self.idx = Index(date_range('20130101', periods=3, tz='US/Eastern'),
name='foo')
self.dr = date_range('20130110', periods=3)
Expand Down Expand Up @@ -2972,7 +2972,7 @@ def test_transpose(self):

class TestDataFrameIndexingUInt64(tm.TestCase, TestData):

def setUp(self):
def setup_method(self, method):
self.ir = Index(np.arange(3), dtype=np.uint64)
self.idx = Index([2**63, 2**63 + 5, 2**63 + 10], name='foo')

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _permute(obj):

class TestPeriodIndex(tm.TestCase):

def setUp(self):
def setup_method(self, method):
pass

def test_as_frame_columns(self):
Expand Down
Loading