From 7ae9e2816615d2b10dfac85d5ed81621ee7cbbd9 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Mon, 24 Apr 2017 12:27:01 -0400 Subject: [PATCH 1/2] MAINT: Remove self.assertRaisesRegexp from testing --- pandas/tests/groupby/test_groupby.py | 12 +++---- pandas/tests/groupby/test_transform.py | 8 ++--- pandas/tests/indexes/common.py | 6 ++-- .../indexes/datetimes/test_date_range.py | 32 +++++++++---------- .../tests/indexes/datetimes/test_datetime.py | 12 +++---- .../indexes/datetimes/test_partial_slicing.py | 16 +++++----- pandas/tests/indexes/period/test_indexing.py | 8 ++--- .../indexes/period/test_partial_slicing.py | 12 +++---- pandas/tests/indexes/period/test_period.py | 2 +- pandas/tests/indexes/period/test_tools.py | 6 ++-- pandas/tests/indexes/test_base.py | 4 +-- pandas/tests/indexes/test_interval.py | 4 +-- pandas/tests/indexes/timedeltas/test_ops.py | 2 +- .../timedeltas/test_partial_slicing.py | 12 +++---- pandas/tests/indexing/test_floats.py | 6 ++-- pandas/tests/indexing/test_indexing.py | 12 +++---- pandas/tests/indexing/test_scalar.py | 4 +-- pandas/tests/io/json/test_pandas.py | 2 +- pandas/tests/io/parser/compression.py | 12 +++---- pandas/tests/io/test_pytables.py | 2 +- pandas/tests/scalar/test_interval.py | 2 +- pandas/tests/scalar/test_period.py | 6 ++-- pandas/tests/scalar/test_period_asfreq.py | 18 +++++------ pandas/tests/scalar/test_timestamp.py | 2 +- pandas/tests/series/test_analytics.py | 4 +-- pandas/tests/series/test_api.py | 2 +- pandas/tests/test_panel.py | 4 +-- pandas/tests/test_strings.py | 6 ++-- pandas/tests/tools/test_numeric.py | 4 +-- 29 files changed, 111 insertions(+), 111 deletions(-) diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 2d673b2dac259..8ca8ddded3073 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -1874,16 +1874,16 @@ def test_groupby_args(self): def j(): frame.groupby() - self.assertRaisesRegexp(TypeError, - "You have to supply one of 'by' and 'level'", - j) + tm.assertRaisesRegexp(TypeError, + "You have to supply one of 'by' and 'level'", + j) def k(): frame.groupby(by=None, level=None) - self.assertRaisesRegexp(TypeError, - "You have to supply one of 'by' and 'level'", - k) + tm.assertRaisesRegexp(TypeError, + "You have to supply one of 'by' and 'level'", + k) def test_groupby_level_mapper(self): frame = self.mframe diff --git a/pandas/tests/groupby/test_transform.py b/pandas/tests/groupby/test_transform.py index 57ea8eb067a2b..4624d43df6128 100644 --- a/pandas/tests/groupby/test_transform.py +++ b/pandas/tests/groupby/test_transform.py @@ -556,7 +556,7 @@ def test_transform_with_non_scalar_group(self): df = pd.DataFrame(np.random.randint(1, 10, (4, 12)), columns=cols, index=['A', 'C', 'G', 'T']) - self.assertRaisesRegexp(ValueError, 'transform must return a scalar ' - 'value for each group.*', df.groupby - (axis=1, level=1).transform, - lambda z: z.div(z.sum(axis=1), axis=0)) + tm.assertRaisesRegexp(ValueError, 'transform must return a scalar ' + 'value for each group.*', df.groupby + (axis=1, level=1).transform, + lambda z: z.div(z.sum(axis=1), axis=0)) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index fa1f31ded5f1c..746932b7c2975 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -875,7 +875,7 @@ def test_fillna(self): elif isinstance(index, MultiIndex): idx = index.copy() msg = "isnull is not defined for MultiIndex" - with self.assertRaisesRegexp(NotImplementedError, msg): + with tm.assertRaisesRegexp(NotImplementedError, msg): idx.fillna(idx[0]) else: idx = index.copy() @@ -884,7 +884,7 @@ def test_fillna(self): self.assertFalse(result is idx) msg = "'value' must be a scalar, passed: " - with self.assertRaisesRegexp(TypeError, msg): + with tm.assertRaisesRegexp(TypeError, msg): idx.fillna([idx[0]]) idx = index.copy() @@ -918,7 +918,7 @@ def test_nulls(self): elif isinstance(index, MultiIndex): idx = index.copy() msg = "isnull is not defined for MultiIndex" - with self.assertRaisesRegexp(NotImplementedError, msg): + with tm.assertRaisesRegexp(NotImplementedError, msg): idx.isnull() else: diff --git a/pandas/tests/indexes/datetimes/test_date_range.py b/pandas/tests/indexes/datetimes/test_date_range.py index 665dcc45050f3..6e49b1612b4c5 100644 --- a/pandas/tests/indexes/datetimes/test_date_range.py +++ b/pandas/tests/indexes/datetimes/test_date_range.py @@ -212,31 +212,31 @@ def test_naive_aware_conflicts(self): naive = bdate_range(START, END, freq=BDay(), tz=None) aware = bdate_range(START, END, freq=BDay(), tz="Asia/Hong_Kong") - self.assertRaisesRegexp(TypeError, "tz-naive.*tz-aware", - naive.join, aware) - self.assertRaisesRegexp(TypeError, "tz-naive.*tz-aware", - aware.join, naive) + tm.assertRaisesRegexp(TypeError, "tz-naive.*tz-aware", + naive.join, aware) + tm.assertRaisesRegexp(TypeError, "tz-naive.*tz-aware", + aware.join, naive) def test_cached_range(self): DatetimeIndex._cached_range(START, END, offset=BDay()) DatetimeIndex._cached_range(START, periods=20, offset=BDay()) DatetimeIndex._cached_range(end=START, periods=20, offset=BDay()) - self.assertRaisesRegexp(TypeError, "offset", - DatetimeIndex._cached_range, - START, END) + tm.assertRaisesRegexp(TypeError, "offset", + DatetimeIndex._cached_range, + START, END) - self.assertRaisesRegexp(TypeError, "specify period", - DatetimeIndex._cached_range, START, - offset=BDay()) + tm.assertRaisesRegexp(TypeError, "specify period", + DatetimeIndex._cached_range, START, + offset=BDay()) - self.assertRaisesRegexp(TypeError, "specify period", - DatetimeIndex._cached_range, end=END, - offset=BDay()) + tm.assertRaisesRegexp(TypeError, "specify period", + DatetimeIndex._cached_range, end=END, + offset=BDay()) - self.assertRaisesRegexp(TypeError, "start or end", - DatetimeIndex._cached_range, periods=20, - offset=BDay()) + tm.assertRaisesRegexp(TypeError, "start or end", + DatetimeIndex._cached_range, periods=20, + offset=BDay()) def test_cached_range_bug(self): rng = date_range('2010-09-01 05:00:00', periods=50, diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index 66dcb195611e1..abfc52728ef0f 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -755,12 +755,12 @@ def assert_slices_equivalent(l_slc, i_slc): def test_slice_with_zero_step_raises(self): ts = Series(np.arange(20), date_range('2014-01-01', periods=20, freq='MS')) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) def test_slice_bounds_empty(self): # GH 14354 diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py index 9c41e2d823238..352e066c6c90c 100644 --- a/pandas/tests/indexes/datetimes/test_partial_slicing.py +++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py @@ -122,8 +122,8 @@ def test_partial_slice_second_precision(self): tm.assert_series_equal(s['2005-1-1 00:01:00'], s.iloc[10:]) self.assertEqual(s[Timestamp('2005-1-1 00:00:59.999990')], s.iloc[0]) - self.assertRaisesRegexp(KeyError, '2005-1-1 00:00:00', - lambda: s['2005-1-1 00:00:00']) + tm.assertRaisesRegexp(KeyError, '2005-1-1 00:00:00', + lambda: s['2005-1-1 00:00:00']) def test_partial_slicing_dataframe(self): # GH14856 @@ -249,14 +249,14 @@ def test_partial_slice_doesnt_require_monotonicity(self): timestamp = pd.Timestamp('2014-01-10') tm.assert_series_equal(nonmonotonic['2014-01-10':], expected) - self.assertRaisesRegexp(KeyError, - r"Timestamp\('2014-01-10 00:00:00'\)", - lambda: nonmonotonic[timestamp:]) + tm.assertRaisesRegexp(KeyError, + r"Timestamp\('2014-01-10 00:00:00'\)", + lambda: nonmonotonic[timestamp:]) tm.assert_series_equal(nonmonotonic.loc['2014-01-10':], expected) - self.assertRaisesRegexp(KeyError, - r"Timestamp\('2014-01-10 00:00:00'\)", - lambda: nonmonotonic.loc[timestamp:]) + tm.assertRaisesRegexp(KeyError, + r"Timestamp\('2014-01-10 00:00:00'\)", + lambda: nonmonotonic.loc[timestamp:]) def test_loc_datetime_length_one(self): # GH16071 diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index 79998d5a6ad7f..4d5fdd748219c 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -103,10 +103,10 @@ def test_getitem_partial(self): tm.assert_series_equal(exp, result) ts = ts[10:].append(ts[10:]) - self.assertRaisesRegexp(KeyError, - "left slice bound for non-unique " - "label: '2008'", - ts.__getitem__, slice('2008', '2009')) + tm.assertRaisesRegexp(KeyError, + "left slice bound for non-unique " + "label: '2008'", + ts.__getitem__, slice('2008', '2009')) def test_getitem_datetime(self): rng = period_range(start='2012-01-01', periods=10, freq='W-MON') diff --git a/pandas/tests/indexes/period/test_partial_slicing.py b/pandas/tests/indexes/period/test_partial_slicing.py index a8ac6a3e55fe5..b13e231db6c1c 100644 --- a/pandas/tests/indexes/period/test_partial_slicing.py +++ b/pandas/tests/indexes/period/test_partial_slicing.py @@ -42,12 +42,12 @@ def assert_slices_equivalent(l_slc, i_slc): def test_slice_with_zero_step_raises(self): ts = Series(np.arange(20), period_range('2014-01', periods=20, freq='M')) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) def test_slice_keep_name(self): idx = period_range('20010101', periods=10, freq='D', name='bob') diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index 9f72c10316c90..6036d6c0fb19b 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -151,7 +151,7 @@ def test_get_indexer(self): np.array([0, -1, 1], dtype=np.intp)) msg = 'Input has different freq from PeriodIndex\\(freq=H\\)' - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): idx.get_indexer(target, 'nearest', tolerance='1 minute') tm.assert_numpy_array_equal(idx.get_indexer(target, 'nearest', diff --git a/pandas/tests/indexes/period/test_tools.py b/pandas/tests/indexes/period/test_tools.py index 49bc4a4cabe59..3887463cae827 100644 --- a/pandas/tests/indexes/period/test_tools.py +++ b/pandas/tests/indexes/period/test_tools.py @@ -386,7 +386,7 @@ def test_to_period_monthish(self): self.assertEqual(prng.freq, 'M') msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): date_range('01-Jan-2012', periods=8, freq='EOM') def test_period_dt64_round_trip(self): @@ -439,11 +439,11 @@ def test_searchsorted(self): self.assertEqual(pidx.searchsorted(p2), 3) msg = "Input has different freq=H from PeriodIndex" - with self.assertRaisesRegexp(period.IncompatibleFrequency, msg): + with tm.assertRaisesRegexp(period.IncompatibleFrequency, msg): pidx.searchsorted(pd.Period('2014-01-01', freq='H')) msg = "Input has different freq=5D from PeriodIndex" - with self.assertRaisesRegexp(period.IncompatibleFrequency, msg): + with tm.assertRaisesRegexp(period.IncompatibleFrequency, msg): pidx.searchsorted(pd.Period('2014-01-01', freq='5D')) with tm.assert_produces_warning(FutureWarning): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 2b6d69a90a55f..06f98527deefb 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1450,8 +1450,8 @@ def test_str_attribute(self): MultiIndex.from_tuples([('foo', '1'), ('bar', '3')]), PeriodIndex(start='2000', end='2010', freq='A')] for idx in indices: - with self.assertRaisesRegexp(AttributeError, - 'only use .str accessor'): + with tm.assertRaisesRegexp(AttributeError, + 'only use .str accessor'): idx.str.repeat(2) idx = Index(['a b c', 'd e', 'f']) diff --git a/pandas/tests/indexes/test_interval.py b/pandas/tests/indexes/test_interval.py index c34d93cb21b0f..8e020846f5c50 100644 --- a/pandas/tests/indexes/test_interval.py +++ b/pandas/tests/indexes/test_interval.py @@ -602,9 +602,9 @@ def test_comparison(self): actual = self.index == self.index.left tm.assert_numpy_array_equal(actual, np.array([False, False])) - with self.assertRaisesRegexp(TypeError, 'unorderable types'): + with tm.assertRaisesRegexp(TypeError, 'unorderable types'): self.index > 0 - with self.assertRaisesRegexp(TypeError, 'unorderable types'): + with tm.assertRaisesRegexp(TypeError, 'unorderable types'): self.index <= 0 with pytest.raises(TypeError): self.index > np.arange(2) diff --git a/pandas/tests/indexes/timedeltas/test_ops.py b/pandas/tests/indexes/timedeltas/test_ops.py index 6da6653b752c9..da23f8698f4dc 100644 --- a/pandas/tests/indexes/timedeltas/test_ops.py +++ b/pandas/tests/indexes/timedeltas/test_ops.py @@ -115,7 +115,7 @@ def test_round(self): self.assertEqual(elt.round(freq='H'), expected_elt) msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): td.round(freq='foo') with tm.assertRaisesRegexp(ValueError, msg): elt.round(freq='foo') diff --git a/pandas/tests/indexes/timedeltas/test_partial_slicing.py b/pandas/tests/indexes/timedeltas/test_partial_slicing.py index f7560c37e814b..ccb9a7f1803e7 100644 --- a/pandas/tests/indexes/timedeltas/test_partial_slicing.py +++ b/pandas/tests/indexes/timedeltas/test_partial_slicing.py @@ -75,9 +75,9 @@ def assert_slices_equivalent(l_slc, i_slc): def test_slice_with_zero_step_raises(self): ts = Series(np.arange(20), timedelta_range('0', periods=20, freq='H')) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: ts.loc[::0]) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index ef64c6e0475e9..02df4de010fbe 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -48,9 +48,9 @@ def test_scalar_error(self): def f(): s.iloc[3.0] - self.assertRaisesRegexp(TypeError, - 'cannot do positional indexing', - f) + tm.assertRaisesRegexp(TypeError, + 'cannot do positional indexing', + f) def f(): s.iloc[3.0] = 0 diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index fe934e7b2a7e0..f7a9c9fe59594 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -716,13 +716,13 @@ def assert_slices_equivalent(l_slc, i_slc): def test_slice_with_zero_step_raises(self): s = Series(np.arange(20), index=_mklbl('A', 20)) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: s[::0]) - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: s.loc[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: s[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: s.loc[::0]) with catch_warnings(record=True): - self.assertRaisesRegexp(ValueError, 'slice step cannot be zero', - lambda: s.ix[::0]) + tm.assertRaisesRegexp(ValueError, 'slice step cannot be zero', + lambda: s.ix[::0]) def test_indexing_assignment_dict_already_exists(self): df = pd.DataFrame({'x': [1, 2, 6], diff --git a/pandas/tests/indexing/test_scalar.py b/pandas/tests/indexing/test_scalar.py index 3522974c18061..a583bf1c5ef16 100644 --- a/pandas/tests/indexing/test_scalar.py +++ b/pandas/tests/indexing/test_scalar.py @@ -154,8 +154,8 @@ def test_at_to_fail(self): df.columns = ['x', 'x', 'z'] # Check that we get the correct value in the KeyError - self.assertRaisesRegexp(KeyError, r"\['y'\] not in index", - lambda: df[['x', 'y', 'z']]) + tm.assertRaisesRegexp(KeyError, r"\['y'\] not in index", + lambda: df[['x', 'y', 'z']]) def test_at_with_tz(self): # gh-15822 diff --git a/pandas/tests/io/json/test_pandas.py b/pandas/tests/io/json/test_pandas.py index b152f7bb089de..a8ea76ff9459c 100644 --- a/pandas/tests/io/json/test_pandas.py +++ b/pandas/tests/io/json/test_pandas.py @@ -1036,7 +1036,7 @@ def test_to_jsonl(self): def test_latin_encoding(self): if compat.PY2: - self.assertRaisesRegexp( + tm.assertRaisesRegexp( TypeError, r'\[unicode\] is not implemented as a table column') return diff --git a/pandas/tests/io/parser/compression.py b/pandas/tests/io/parser/compression.py index c7e9401665cdf..26e216cfbcffa 100644 --- a/pandas/tests/io/parser/compression.py +++ b/pandas/tests/io/parser/compression.py @@ -45,18 +45,18 @@ def test_zip(self): tmp.writestr(file_name, data) tmp.close() - self.assertRaisesRegexp(ValueError, 'Multiple files', - self.read_csv, path, compression='zip') + tm.assertRaisesRegexp(ValueError, 'Multiple files', + self.read_csv, path, compression='zip') - self.assertRaisesRegexp(ValueError, 'Multiple files', - self.read_csv, path, compression='infer') + tm.assertRaisesRegexp(ValueError, 'Multiple files', + self.read_csv, path, compression='infer') with tm.ensure_clean() as path: tmp = zipfile.ZipFile(path, mode='w') tmp.close() - self.assertRaisesRegexp(ValueError, 'Zero files', - self.read_csv, path, compression='zip') + tm.assertRaisesRegexp(ValueError, 'Zero files', + self.read_csv, path, compression='zip') with tm.ensure_clean() as path: with open(path, 'wb') as f: diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index ea9911d8ee66c..7d2c7a97fce0a 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -971,7 +971,7 @@ def test_encoding(self): def test_latin_encoding(self): if compat.PY2: - self.assertRaisesRegexp( + tm.assertRaisesRegexp( TypeError, r'\[unicode\] is not implemented as a table column') return diff --git a/pandas/tests/scalar/test_interval.py b/pandas/tests/scalar/test_interval.py index bd73a7d173962..ea267fabd13ed 100644 --- a/pandas/tests/scalar/test_interval.py +++ b/pandas/tests/scalar/test_interval.py @@ -46,7 +46,7 @@ def test_equal(self): self.assertNotEqual(Interval(0, 1), 0) def test_comparison(self): - with self.assertRaisesRegexp(TypeError, 'unorderable types'): + with tm.assertRaisesRegexp(TypeError, 'unorderable types'): Interval(0, 1) < 2 self.assertTrue(Interval(0, 1) < Interval(1, 2)) diff --git a/pandas/tests/scalar/test_period.py b/pandas/tests/scalar/test_period.py index dff954b25f839..f8b103836e9a1 100644 --- a/pandas/tests/scalar/test_period.py +++ b/pandas/tests/scalar/test_period.py @@ -518,9 +518,9 @@ def test_period_deprecated_freq(self): msg = pd.tseries.frequencies._INVALID_FREQ_ERROR for exp, freqs in iteritems(cases): for freq in freqs: - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period('2016-03-01 09:00', freq=freq) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(ordinal=1, freq=freq) # check supported freq-aliases still works @@ -762,7 +762,7 @@ def test_properties_weekly_legacy(self): self.assertEqual(exp.days_in_month, 29) msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK', year=2007, month=1, day=7) def test_properties_daily(self): diff --git a/pandas/tests/scalar/test_period_asfreq.py b/pandas/tests/scalar/test_period_asfreq.py index d311fef8a826d..611a1cc97e9c6 100644 --- a/pandas/tests/scalar/test_period_asfreq.py +++ b/pandas/tests/scalar/test_period_asfreq.py @@ -295,26 +295,26 @@ def test_conv_weekly(self): self.assertEqual(ival_W.asfreq('W'), ival_W) msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): ival_W.asfreq('WK') def test_conv_weekly_legacy(self): # frequency conversion tests: from Weekly Frequency msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK', year=2007, month=1, day=1) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-SAT', year=2007, month=1, day=6) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-FRI', year=2007, month=1, day=5) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-THU', year=2007, month=1, day=4) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-WED', year=2007, month=1, day=3) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-TUE', year=2007, month=1, day=2) - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): Period(freq='WK-MON', year=2007, month=1, day=1) def test_conv_business(self): @@ -712,7 +712,7 @@ def test_asfreq_MS(self): Period('2013-01', 'M')) msg = pd.tseries.frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): initial.asfreq(freq="MS", how="S") with tm.assertRaisesRegexp(ValueError, msg): diff --git a/pandas/tests/scalar/test_timestamp.py b/pandas/tests/scalar/test_timestamp.py index 2b00ac68ee555..b7b1b4c198701 100644 --- a/pandas/tests/scalar/test_timestamp.py +++ b/pandas/tests/scalar/test_timestamp.py @@ -710,7 +710,7 @@ def _check_round(freq, expected): _check_round(freq, expected) msg = frequencies._INVALID_FREQ_ERROR - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): stamp.round('foo') def test_class_ops_pytz(self): diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 63e291836b472..02748aee4628d 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -550,8 +550,8 @@ def testit(): # Unimplemented numeric_only parameter. if 'numeric_only' in compat.signature(f).args: - self.assertRaisesRegexp(NotImplementedError, name, f, - self.series, numeric_only=True) + tm.assertRaisesRegexp(NotImplementedError, name, f, + self.series, numeric_only=True) testit() diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 341d4006c5fcc..f1a904498b727 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -341,7 +341,7 @@ def test_str_attribute(self): # str accessor only valid with string values s = Series(range(5)) - with self.assertRaisesRegexp(AttributeError, 'only use .str accessor'): + with tm.assertRaisesRegexp(AttributeError, 'only use .str accessor'): s.str.repeat(2) def test_empty_method(self): diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 1d0788ae160dd..17bc06b5ee9c7 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -180,8 +180,8 @@ def wrapper(x): # Unimplemented numeric_only parameter. if 'numeric_only' in signature(f).args: - self.assertRaisesRegexp(NotImplementedError, name, f, - numeric_only=True) + tm.assertRaisesRegexp(NotImplementedError, name, f, + numeric_only=True) class SafeForSparse(object): diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 761bfa6bfe29a..a818bf84b8e9b 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -2722,9 +2722,9 @@ def test_index_str_accessor_visibility(self): for values, tp in cases: idx = Index(values) message = 'Can only use .str accessor with string values' - with self.assertRaisesRegexp(AttributeError, message): + with tm.assertRaisesRegexp(AttributeError, message): Series(values).str - with self.assertRaisesRegexp(AttributeError, message): + with tm.assertRaisesRegexp(AttributeError, message): idx.str self.assertEqual(idx.inferred_type, tp) @@ -2732,7 +2732,7 @@ def test_index_str_accessor_visibility(self): idx = MultiIndex.from_tuples([('a', 'b'), ('a', 'b')]) self.assertEqual(idx.inferred_type, 'mixed') message = 'Can only use .str accessor with Index, not MultiIndex' - with self.assertRaisesRegexp(AttributeError, message): + with tm.assertRaisesRegexp(AttributeError, message): idx.str def test_str_accessor_no_new_attributes(self): diff --git a/pandas/tests/tools/test_numeric.py b/pandas/tests/tools/test_numeric.py index 5fa3f38f31ae1..1376101412112 100644 --- a/pandas/tests/tools/test_numeric.py +++ b/pandas/tests/tools/test_numeric.py @@ -253,7 +253,7 @@ def test_non_hashable(self): res = pd.to_numeric(s, errors='ignore') tm.assert_series_equal(res, pd.Series([[10.0, 2], 1.0, 'apple'])) - with self.assertRaisesRegexp(TypeError, "Invalid object type"): + with tm.assertRaisesRegexp(TypeError, "Invalid object type"): pd.to_numeric(s) def test_downcast(self): @@ -274,7 +274,7 @@ def test_downcast(self): smallest_float_dtype = float_32_char for data in (mixed_data, int_data, date_data): - with self.assertRaisesRegexp(ValueError, msg): + with tm.assertRaisesRegexp(ValueError, msg): pd.to_numeric(data, downcast=invalid_downcast) expected = np.array([1, 2, 3], dtype=np.int64) From c29715ff7a9614e3740f9dc3989b74c372419a10 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Mon, 24 Apr 2017 12:52:01 -0400 Subject: [PATCH 2/2] MAINT: Do not add static assert methods to TestCase --- pandas/util/testing.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/util/testing.py b/pandas/util/testing.py index 08b298fabdd57..75d24938ed309 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -2665,12 +2665,6 @@ def use_numexpr(use, min_elements=expr._MIN_ELEMENTS): expr.set_use_numexpr(olduse) -# Also provide all assert_* functions in the TestCase class -for name, obj in inspect.getmembers(sys.modules[__name__]): - if inspect.isfunction(obj) and name.startswith('assert'): - setattr(TestCase, name, staticmethod(obj)) - - def test_parallel(num_threads=2, kwargs_list=None): """Decorator to run the same function multiple times in parallel.