Skip to content

Commit 1b14680

Browse files
committed
MAINT: Convert test setup/teardown to pytest idiom
* tm.TestCase now just inherits from object * setUpClass renamed to setup_class * tearDownClass renamed to teardown_class * setUp renamed to setup_method * tearDown renamed to teardown_method
1 parent 39cc1d0 commit 1b14680

File tree

102 files changed

+294
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+294
-297
lines changed

pandas/tests/computation/test_eval.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ def _is_py3_complex_incompat(result, expected):
9898
class TestEvalNumexprPandas(tm.TestCase):
9999

100100
@classmethod
101-
def setUpClass(cls):
102-
super(TestEvalNumexprPandas, cls).setUpClass()
101+
def setup_class(cls):
102+
super(TestEvalNumexprPandas, cls).setup_class()
103103
tm.skip_if_no_ne()
104104
import numexpr as ne
105105
cls.ne = ne
106106
cls.engine = 'numexpr'
107107
cls.parser = 'pandas'
108108

109109
@classmethod
110-
def tearDownClass(cls):
111-
super(TestEvalNumexprPandas, cls).tearDownClass()
110+
def teardown_class(cls):
111+
super(TestEvalNumexprPandas, cls).teardown_class()
112112
del cls.engine, cls.parser
113113
if hasattr(cls, 'ne'):
114114
del cls.ne
@@ -137,12 +137,12 @@ def setup_ops(self):
137137
self.arith_ops = _good_arith_ops
138138
self.unary_ops = '-', '~', 'not '
139139

140-
def setUp(self):
140+
def setup_method(self, method):
141141
self.setup_ops()
142142
self.setup_data()
143143
self.current_engines = filter(lambda x: x != self.engine, _engines)
144144

145-
def tearDown(self):
145+
def teardown_method(self, method):
146146
del self.lhses, self.rhses, self.scalar_rhses, self.scalar_lhses
147147
del self.pandas_rhses, self.pandas_lhses, self.current_engines
148148

@@ -723,8 +723,8 @@ def test_float_truncation(self):
723723
class TestEvalNumexprPython(TestEvalNumexprPandas):
724724

725725
@classmethod
726-
def setUpClass(cls):
727-
super(TestEvalNumexprPython, cls).setUpClass()
726+
def setup_class(cls):
727+
super(TestEvalNumexprPython, cls).setup_class()
728728
tm.skip_if_no_ne()
729729
import numexpr as ne
730730
cls.ne = ne
@@ -750,8 +750,8 @@ def check_chained_cmp_op(self, lhs, cmp1, mid, cmp2, rhs):
750750
class TestEvalPythonPython(TestEvalNumexprPython):
751751

752752
@classmethod
753-
def setUpClass(cls):
754-
super(TestEvalPythonPython, cls).setUpClass()
753+
def setup_class(cls):
754+
super(TestEvalPythonPython, cls).setup_class()
755755
cls.engine = 'python'
756756
cls.parser = 'python'
757757

@@ -780,8 +780,8 @@ def check_alignment(self, result, nlhs, ghs, op):
780780
class TestEvalPythonPandas(TestEvalPythonPython):
781781

782782
@classmethod
783-
def setUpClass(cls):
784-
super(TestEvalPythonPandas, cls).setUpClass()
783+
def setup_class(cls):
784+
super(TestEvalPythonPandas, cls).setup_class()
785785
cls.engine = 'python'
786786
cls.parser = 'pandas'
787787

@@ -1070,16 +1070,16 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
10701070
class TestOperationsNumExprPandas(tm.TestCase):
10711071

10721072
@classmethod
1073-
def setUpClass(cls):
1074-
super(TestOperationsNumExprPandas, cls).setUpClass()
1073+
def setup_class(cls):
1074+
super(TestOperationsNumExprPandas, cls).setup_class()
10751075
tm.skip_if_no_ne()
10761076
cls.engine = 'numexpr'
10771077
cls.parser = 'pandas'
10781078
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
10791079

10801080
@classmethod
1081-
def tearDownClass(cls):
1082-
super(TestOperationsNumExprPandas, cls).tearDownClass()
1081+
def teardown_class(cls):
1082+
super(TestOperationsNumExprPandas, cls).teardown_class()
10831083
del cls.engine, cls.parser
10841084

10851085
def eval(self, *args, **kwargs):
@@ -1492,8 +1492,8 @@ def test_simple_in_ops(self):
14921492
class TestOperationsNumExprPython(TestOperationsNumExprPandas):
14931493

14941494
@classmethod
1495-
def setUpClass(cls):
1496-
super(TestOperationsNumExprPython, cls).setUpClass()
1495+
def setup_class(cls):
1496+
super(TestOperationsNumExprPython, cls).setup_class()
14971497
cls.engine = 'numexpr'
14981498
cls.parser = 'python'
14991499
tm.skip_if_no_ne(cls.engine)
@@ -1566,8 +1566,8 @@ def test_simple_bool_ops(self):
15661566
class TestOperationsPythonPython(TestOperationsNumExprPython):
15671567

15681568
@classmethod
1569-
def setUpClass(cls):
1570-
super(TestOperationsPythonPython, cls).setUpClass()
1569+
def setup_class(cls):
1570+
super(TestOperationsPythonPython, cls).setup_class()
15711571
cls.engine = cls.parser = 'python'
15721572
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
15731573
cls.arith_ops = filter(lambda x: x not in ('in', 'not in'),
@@ -1577,8 +1577,8 @@ def setUpClass(cls):
15771577
class TestOperationsPythonPandas(TestOperationsNumExprPandas):
15781578

15791579
@classmethod
1580-
def setUpClass(cls):
1581-
super(TestOperationsPythonPandas, cls).setUpClass()
1580+
def setup_class(cls):
1581+
super(TestOperationsPythonPandas, cls).setup_class()
15821582
cls.engine = 'python'
15831583
cls.parser = 'pandas'
15841584
cls.arith_ops = expr._arith_ops_syms + expr._cmp_ops_syms
@@ -1587,16 +1587,16 @@ def setUpClass(cls):
15871587
class TestMathPythonPython(tm.TestCase):
15881588

15891589
@classmethod
1590-
def setUpClass(cls):
1591-
super(TestMathPythonPython, cls).setUpClass()
1590+
def setup_class(cls):
1591+
super(TestMathPythonPython, cls).setup_class()
15921592
tm.skip_if_no_ne()
15931593
cls.engine = 'python'
15941594
cls.parser = 'pandas'
15951595
cls.unary_fns = _unary_math_ops
15961596
cls.binary_fns = _binary_math_ops
15971597

15981598
@classmethod
1599-
def tearDownClass(cls):
1599+
def teardown_class(cls):
16001600
del cls.engine, cls.parser
16011601

16021602
def eval(self, *args, **kwargs):
@@ -1694,26 +1694,26 @@ def test_keyword_arg(self):
16941694
class TestMathPythonPandas(TestMathPythonPython):
16951695

16961696
@classmethod
1697-
def setUpClass(cls):
1698-
super(TestMathPythonPandas, cls).setUpClass()
1697+
def setup_class(cls):
1698+
super(TestMathPythonPandas, cls).setup_class()
16991699
cls.engine = 'python'
17001700
cls.parser = 'pandas'
17011701

17021702

17031703
class TestMathNumExprPandas(TestMathPythonPython):
17041704

17051705
@classmethod
1706-
def setUpClass(cls):
1707-
super(TestMathNumExprPandas, cls).setUpClass()
1706+
def setup_class(cls):
1707+
super(TestMathNumExprPandas, cls).setup_class()
17081708
cls.engine = 'numexpr'
17091709
cls.parser = 'pandas'
17101710

17111711

17121712
class TestMathNumExprPython(TestMathPythonPython):
17131713

17141714
@classmethod
1715-
def setUpClass(cls):
1716-
super(TestMathNumExprPython, cls).setUpClass()
1715+
def setup_class(cls):
1716+
super(TestMathNumExprPython, cls).setup_class()
17171717
cls.engine = 'numexpr'
17181718
cls.parser = 'python'
17191719

pandas/tests/dtypes/test_dtypes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_pickle(self):
4343

4444
class TestCategoricalDtype(Base, tm.TestCase):
4545

46-
def setUp(self):
46+
def setup_method(self, method):
4747
self.dtype = CategoricalDtype()
4848

4949
def test_hash_vs_equality(self):
@@ -95,7 +95,7 @@ def test_basic(self):
9595

9696
class TestDatetimeTZDtype(Base, tm.TestCase):
9797

98-
def setUp(self):
98+
def setup_method(self, method):
9999
self.dtype = DatetimeTZDtype('ns', 'US/Eastern')
100100

101101
def test_hash_vs_equality(self):
@@ -211,7 +211,7 @@ def test_empty(self):
211211

212212
class TestPeriodDtype(Base, tm.TestCase):
213213

214-
def setUp(self):
214+
def setup_method(self, method):
215215
self.dtype = PeriodDtype('D')
216216

217217
def test_construction(self):
@@ -341,7 +341,7 @@ def test_not_string(self):
341341
class TestIntervalDtype(Base, tm.TestCase):
342342

343343
# TODO: placeholder
344-
def setUp(self):
344+
def setup_method(self, method):
345345
self.dtype = IntervalDtype('int64')
346346

347347
def test_construction(self):

pandas/tests/frame/test_asof.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class TestFrameAsof(TestData, tm.TestCase):
13-
def setUp(self):
13+
def setup_method(self, method):
1414
self.N = N = 50
1515
self.rng = date_range('1/1/1990', periods=N, freq='53s')
1616
self.df = DataFrame({'A': np.arange(N), 'B': np.arange(N)},

pandas/tests/frame/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@ def test_type_error_multiindex(self):
29142914

29152915
class TestDataFrameIndexingDatetimeWithTZ(tm.TestCase, TestData):
29162916

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

29732973
class TestDataFrameIndexingUInt64(tm.TestCase, TestData):
29742974

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

pandas/tests/frame/test_period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def _permute(obj):
1414

1515
class TestPeriodIndex(tm.TestCase):
1616

17-
def setUp(self):
17+
def setup_method(self, method):
1818
pass
1919

2020
def test_as_frame_columns(self):

pandas/tests/frame/test_query_eval.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def skip_if_no_ne(engine='numexpr'):
4141

4242
class TestCompat(tm.TestCase):
4343

44-
def setUp(self):
44+
def setup_method(self, method):
4545
self.df = DataFrame({'A': [1, 2, 3]})
4646
self.expected1 = self.df[self.df.A > 0]
4747
self.expected2 = self.df.A + 1
@@ -401,15 +401,15 @@ def check_raise_on_panel4d_with_multiindex(self, parser, engine):
401401
class TestDataFrameQueryNumExprPandas(tm.TestCase):
402402

403403
@classmethod
404-
def setUpClass(cls):
405-
super(TestDataFrameQueryNumExprPandas, cls).setUpClass()
404+
def setup_class(cls):
405+
super(TestDataFrameQueryNumExprPandas, cls).setup_class()
406406
cls.engine = 'numexpr'
407407
cls.parser = 'pandas'
408408
tm.skip_if_no_ne(cls.engine)
409409

410410
@classmethod
411-
def tearDownClass(cls):
412-
super(TestDataFrameQueryNumExprPandas, cls).tearDownClass()
411+
def teardown_class(cls):
412+
super(TestDataFrameQueryNumExprPandas, cls).teardown_class()
413413
del cls.engine, cls.parser
414414

415415
def test_date_query_with_attribute_access(self):
@@ -733,8 +733,8 @@ def test_inf(self):
733733
class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas):
734734

735735
@classmethod
736-
def setUpClass(cls):
737-
super(TestDataFrameQueryNumExprPython, cls).setUpClass()
736+
def setup_class(cls):
737+
super(TestDataFrameQueryNumExprPython, cls).setup_class()
738738
cls.engine = 'numexpr'
739739
cls.parser = 'python'
740740
tm.skip_if_no_ne(cls.engine)
@@ -834,8 +834,8 @@ def test_nested_scope(self):
834834
class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas):
835835

836836
@classmethod
837-
def setUpClass(cls):
838-
super(TestDataFrameQueryPythonPandas, cls).setUpClass()
837+
def setup_class(cls):
838+
super(TestDataFrameQueryPythonPandas, cls).setup_class()
839839
cls.engine = 'python'
840840
cls.parser = 'pandas'
841841
cls.frame = TestData().frame
@@ -855,8 +855,8 @@ def test_query_builtin(self):
855855
class TestDataFrameQueryPythonPython(TestDataFrameQueryNumExprPython):
856856

857857
@classmethod
858-
def setUpClass(cls):
859-
super(TestDataFrameQueryPythonPython, cls).setUpClass()
858+
def setup_class(cls):
859+
super(TestDataFrameQueryPythonPython, cls).setup_class()
860860
cls.engine = cls.parser = 'python'
861861
cls.frame = TestData().frame
862862

@@ -1092,16 +1092,16 @@ def test_query_string_scalar_variable(self):
10921092
class TestDataFrameEvalNumExprPandas(tm.TestCase):
10931093

10941094
@classmethod
1095-
def setUpClass(cls):
1096-
super(TestDataFrameEvalNumExprPandas, cls).setUpClass()
1095+
def setup_class(cls):
1096+
super(TestDataFrameEvalNumExprPandas, cls).setup_class()
10971097
cls.engine = 'numexpr'
10981098
cls.parser = 'pandas'
10991099
tm.skip_if_no_ne()
11001100

1101-
def setUp(self):
1101+
def setup_method(self, method):
11021102
self.frame = DataFrame(randn(10, 3), columns=list('abc'))
11031103

1104-
def tearDown(self):
1104+
def teardown_method(self, method):
11051105
del self.frame
11061106

11071107
def test_simple_expr(self):
@@ -1129,8 +1129,8 @@ def test_invalid_type_for_operator_raises(self):
11291129
class TestDataFrameEvalNumExprPython(TestDataFrameEvalNumExprPandas):
11301130

11311131
@classmethod
1132-
def setUpClass(cls):
1133-
super(TestDataFrameEvalNumExprPython, cls).setUpClass()
1132+
def setup_class(cls):
1133+
super(TestDataFrameEvalNumExprPython, cls).setup_class()
11341134
cls.engine = 'numexpr'
11351135
cls.parser = 'python'
11361136
tm.skip_if_no_ne(cls.engine)
@@ -1139,15 +1139,15 @@ def setUpClass(cls):
11391139
class TestDataFrameEvalPythonPandas(TestDataFrameEvalNumExprPandas):
11401140

11411141
@classmethod
1142-
def setUpClass(cls):
1143-
super(TestDataFrameEvalPythonPandas, cls).setUpClass()
1142+
def setup_class(cls):
1143+
super(TestDataFrameEvalPythonPandas, cls).setup_class()
11441144
cls.engine = 'python'
11451145
cls.parser = 'pandas'
11461146

11471147

11481148
class TestDataFrameEvalPythonPython(TestDataFrameEvalNumExprPython):
11491149

11501150
@classmethod
1151-
def setUpClass(cls):
1152-
super(TestDataFrameEvalPythonPython, cls).tearDownClass()
1151+
def setup_class(cls):
1152+
super(TestDataFrameEvalPythonPython, cls).teardown_class()
11531153
cls.engine = cls.parser = 'python'

pandas/tests/groupby/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def df():
2828

2929
class MixIn(object):
3030

31-
def setUp(self):
31+
def setup_method(self, method):
3232
self.ts = tm.makeTimeSeries()
3333

3434
self.seriesd = tm.getSeriesData()

pandas/tests/groupby/test_aggregate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
class TestGroupByAggregate(tm.TestCase):
2929

30-
def setUp(self):
30+
def setup_method(self, method):
3131
self.ts = tm.makeTimeSeries()
3232

3333
self.seriesd = tm.getSeriesData()

pandas/tests/groupby/test_bin_groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_series_bin_grouper():
4848

4949
class TestBinGroupers(tm.TestCase):
5050

51-
def setUp(self):
51+
def setup_method(self, method):
5252
self.obj = np.random.randn(10, 1)
5353
self.labels = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 2], dtype=np.int64)
5454
self.bins = np.array([3, 6], dtype=np.int64)

pandas/tests/groupby/test_filters.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
class TestGroupByFilter(tm.TestCase):
2727

28-
def setUp(self):
28+
def setup_method(self, method):
2929
self.ts = tm.makeTimeSeries()
3030

3131
self.seriesd = tm.getSeriesData()

0 commit comments

Comments
 (0)