Skip to content

TST: Use __tracebackhide__ to suppress unnecessary parts of tm assertions #23307

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

Merged
merged 2 commits into from
Oct 24, 2018
Merged
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
44 changes: 27 additions & 17 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ def get_locales(prefix=None, normalize=True,
if prefix is None:
return _valid_locales(out_locales, normalize)

found = re.compile('{prefix}.*'.format(prefix=prefix)) \
.findall('\n'.join(out_locales))
pattern = re.compile('{prefix}.*'.format(prefix=prefix))
found = pattern.findall('\n'.join(out_locales))
return _valid_locales(found, normalize)


Expand Down Expand Up @@ -895,6 +895,7 @@ def _get_ilevel_values(index, level):

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

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

left_attr = getattr(left, attr)
right_attr = getattr(right, attr)
Expand Down Expand Up @@ -964,14 +966,14 @@ def assert_is_valid_plot_return_object(objs):
import matplotlib.pyplot as plt
if isinstance(objs, (pd.Series, np.ndarray)):
for el in objs.ravel():
msg = ('one of \'objs\' is not a matplotlib Axes instance, type '
'encountered {name!r}').format(name=el.__class__.__name__)
msg = ("one of 'objs' is not a matplotlib Axes instance, type "
"encountered {name!r}").format(name=el.__class__.__name__)
assert isinstance(el, (plt.Axes, dict)), msg
else:
assert isinstance(objs, (plt.Artist, tuple, dict)), \
('objs is neither an ndarray of Artist instances nor a '
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
).format(name=objs.__class__.__name__)
assert isinstance(objs, (plt.Artist, tuple, dict)), (
'objs is neither an ndarray of Artist instances nor a '
'single Artist instance, tuple, or dict, "objs" is a {name!r}'
.format(name=objs.__class__.__name__))


def isiterable(obj):
Expand Down Expand Up @@ -1102,6 +1104,7 @@ def assert_numpy_array_equal(left, right, strict_nan=False,
Specify object name being compared, internally used to show appropriate
assertion message
"""
__tracebackhide__ = True

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

# instance validation
_check_isinstance(left, right, Series)
Expand Down Expand Up @@ -1395,6 +1399,7 @@ def assert_frame_equal(left, right, check_dtype=True,
Ignore differing dtypes in columns with check_dtype.
>>> assert_frame_equal(df1, df2, check_dtype=False)
"""
__tracebackhide__ = True

# instance validation
_check_isinstance(left, right, DataFrame)
Expand Down Expand Up @@ -1530,6 +1535,8 @@ def assert_equal(left, right, **kwargs):
right : Index, Series, DataFrame, ExtensionArray, or np.ndarray
**kwargs
"""
__tracebackhide__ = True

if isinstance(left, pd.Index):
assert_index_equal(left, right, **kwargs)
elif isinstance(left, pd.Series):
Expand Down Expand Up @@ -2017,8 +2024,9 @@ def makeCustomIndex(nentries, nlevels, prefix='#', names=False, ndupe_l=None,
assert (is_sequence(ndupe_l) and len(ndupe_l) <= nlevels)
assert (names is None or names is False or
names is True or len(names) is nlevels)
assert idx_type is None or \
(idx_type in ('i', 'f', 's', 'u', 'dt', 'p', 'td') and nlevels == 1)
assert idx_type is None or (idx_type in ('i', 'f', 's', 'u',
'dt', 'p', 'td')
and nlevels == 1)

if names is True:
# build default names
Expand Down Expand Up @@ -2145,12 +2153,12 @@ def makeCustomDataframe(nrows, ncols, c_idx_names=True, r_idx_names=True,

assert c_idx_nlevels > 0
assert r_idx_nlevels > 0
assert r_idx_type is None or \
(r_idx_type in ('i', 'f', 's',
'u', 'dt', 'p', 'td') and r_idx_nlevels == 1)
assert c_idx_type is None or \
(c_idx_type in ('i', 'f', 's',
'u', 'dt', 'p', 'td') and c_idx_nlevels == 1)
assert r_idx_type is None or (r_idx_type in ('i', 'f', 's',
'u', 'dt', 'p', 'td')
and r_idx_nlevels == 1)
assert c_idx_type is None or (c_idx_type in ('i', 'f', 's',
'u', 'dt', 'p', 'td')
and c_idx_nlevels == 1)

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

def assert_raises_regex(_exception, _regexp, _callable=None,
*args, **kwargs):
"""
r"""
Check that the specified Exception is raised and that the error message
matches a given regular expression pattern. This may be a regular
expression object or a string containing a regular expression suitable
Expand Down Expand Up @@ -2665,6 +2673,8 @@ class for all warnings. To check that no warning is returned,

..warn:: This is *not* thread-safe.
"""
__tracebackhide__ = True

with warnings.catch_warnings(record=True) as w:

if clear is not None:
Expand Down