Skip to content

Commit 5f93e7d

Browse files
jbrockmendeltm9k1
authored andcommitted
TST: Use __tracebackhide__ to suppress unnecessary parts of tm assertions (pandas-dev#23307)
1 parent 0d4decd commit 5f93e7d

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

pandas/util/testing.py

+27-17
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ def get_locales(prefix=None, normalize=True,
480480
if prefix is None:
481481
return _valid_locales(out_locales, normalize)
482482

483-
found = re.compile('{prefix}.*'.format(prefix=prefix)) \
484-
.findall('\n'.join(out_locales))
483+
pattern = re.compile('{prefix}.*'.format(prefix=prefix))
484+
found = pattern.findall('\n'.join(out_locales))
485485
return _valid_locales(found, normalize)
486486

487487

@@ -895,6 +895,7 @@ def _get_ilevel_values(index, level):
895895

896896
def assert_class_equal(left, right, exact=True, obj='Input'):
897897
"""checks classes are equal."""
898+
__tracebackhide__ = True
898899

899900
def repr_class(x):
900901
if isinstance(x, Index):
@@ -934,6 +935,7 @@ def assert_attr_equal(attr, left, right, obj='Attributes'):
934935
Specify object name being compared, internally used to show appropriate
935936
assertion message
936937
"""
938+
__tracebackhide__ = True
937939

938940
left_attr = getattr(left, attr)
939941
right_attr = getattr(right, attr)
@@ -964,14 +966,14 @@ def assert_is_valid_plot_return_object(objs):
964966
import matplotlib.pyplot as plt
965967
if isinstance(objs, (pd.Series, np.ndarray)):
966968
for el in objs.ravel():
967-
msg = ('one of \'objs\' is not a matplotlib Axes instance, type '
968-
'encountered {name!r}').format(name=el.__class__.__name__)
969+
msg = ("one of 'objs' is not a matplotlib Axes instance, type "
970+
"encountered {name!r}").format(name=el.__class__.__name__)
969971
assert isinstance(el, (plt.Axes, dict)), msg
970972
else:
971-
assert isinstance(objs, (plt.Artist, tuple, dict)), \
972-
('objs is neither an ndarray of Artist instances nor a '
973-
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
974-
).format(name=objs.__class__.__name__)
973+
assert isinstance(objs, (plt.Artist, tuple, dict)), (
974+
'objs is neither an ndarray of Artist instances nor a '
975+
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
976+
.format(name=objs.__class__.__name__))
975977

976978

977979
def isiterable(obj):
@@ -1102,6 +1104,7 @@ def assert_numpy_array_equal(left, right, strict_nan=False,
11021104
Specify object name being compared, internally used to show appropriate
11031105
assertion message
11041106
"""
1107+
__tracebackhide__ = True
11051108

11061109
# instance validation
11071110
# Show a detailed error message when classes are different
@@ -1222,6 +1225,7 @@ def assert_series_equal(left, right, check_dtype=True,
12221225
Specify object name being compared, internally used to show appropriate
12231226
assertion message
12241227
"""
1228+
__tracebackhide__ = True
12251229

12261230
# instance validation
12271231
_check_isinstance(left, right, Series)
@@ -1395,6 +1399,7 @@ def assert_frame_equal(left, right, check_dtype=True,
13951399
Ignore differing dtypes in columns with check_dtype.
13961400
>>> assert_frame_equal(df1, df2, check_dtype=False)
13971401
"""
1402+
__tracebackhide__ = True
13981403

13991404
# instance validation
14001405
_check_isinstance(left, right, DataFrame)
@@ -1530,6 +1535,8 @@ def assert_equal(left, right, **kwargs):
15301535
right : Index, Series, DataFrame, ExtensionArray, or np.ndarray
15311536
**kwargs
15321537
"""
1538+
__tracebackhide__ = True
1539+
15331540
if isinstance(left, pd.Index):
15341541
assert_index_equal(left, right, **kwargs)
15351542
elif isinstance(left, pd.Series):
@@ -2017,8 +2024,9 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,
20172024
assert (is_sequence(ndupe_l) and len(ndupe_l) <= nlevels)
20182025
assert (names is None or names is False or
20192026
names is True or len(names) is nlevels)
2020-
assert idx_type is None or \
2021-
(idx_type in ('i', 'f', 's', 'u', 'dt', 'p', 'td') and nlevels == 1)
2027+
assert idx_type is None or (idx_type in ('i', 'f', 's', 'u',
2028+
'dt', 'p', 'td')
2029+
and nlevels == 1)
20222030

20232031
if names is True:
20242032
# build default names
@@ -2145,12 +2153,12 @@ def makeCustomDataframe(nrows, ncols, c_idx_names=True, r_idx_names=True,
21452153

21462154
assert c_idx_nlevels > 0
21472155
assert r_idx_nlevels > 0
2148-
assert r_idx_type is None or \
2149-
(r_idx_type in ('i', 'f', 's',
2150-
'u', 'dt', 'p', 'td') and r_idx_nlevels == 1)
2151-
assert c_idx_type is None or \
2152-
(c_idx_type in ('i', 'f', 's',
2153-
'u', 'dt', 'p', 'td') and c_idx_nlevels == 1)
2156+
assert r_idx_type is None or (r_idx_type in ('i', 'f', 's',
2157+
'u', 'dt', 'p', 'td')
2158+
and r_idx_nlevels == 1)
2159+
assert c_idx_type is None or (c_idx_type in ('i', 'f', 's',
2160+
'u', 'dt', 'p', 'td')
2161+
and c_idx_nlevels == 1)
21542162

21552163
columns = makeCustomIndex(ncols, nlevels=c_idx_nlevels, prefix='C',
21562164
names=c_idx_names, ndupe_l=c_ndupe_l,
@@ -2483,7 +2491,7 @@ def wrapper(*args, **kwargs):
24832491

24842492
def assert_raises_regex(_exception, _regexp, _callable=None,
24852493
*args, **kwargs):
2486-
"""
2494+
r"""
24872495
Check that the specified Exception is raised and that the error message
24882496
matches a given regular expression pattern. This may be a regular
24892497
expression object or a string containing a regular expression suitable
@@ -2665,6 +2673,8 @@ class for all warnings. To check that no warning is returned,
26652673
26662674
..warn:: This is *not* thread-safe.
26672675
"""
2676+
__tracebackhide__ = True
2677+
26682678
with warnings.catch_warnings(record=True) as w:
26692679

26702680
if clear is not None:

0 commit comments

Comments
 (0)