diff --git a/lib/matplotlib/testing/__init__.py b/lib/matplotlib/testing/__init__.py index 5b9dee44f6eb..3fb88379afe9 100644 --- a/lib/matplotlib/testing/__init__.py +++ b/lib/matplotlib/testing/__init__.py @@ -1,6 +1,7 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) +import functools import inspect import warnings from contextlib import contextmanager @@ -20,34 +21,10 @@ def is_called_from_pytest(): return getattr(matplotlib, '_called_from_pytest', False) -# stolen from pytest -def _getrawcode(obj, trycall=True): - """Return code object for given function.""" - try: - return obj.__code__ - except AttributeError: - obj = getattr(obj, 'im_func', obj) - obj = getattr(obj, 'func_code', obj) - obj = getattr(obj, 'f_code', obj) - obj = getattr(obj, '__code__', obj) - if trycall and not hasattr(obj, 'co_firstlineno'): - if hasattr(obj, '__call__') and not inspect.isclass(obj): - x = getrawcode(obj.__call__, trycall=False) - if hasattr(x, 'co_firstlineno'): - return x - return obj - - def _copy_metadata(src_func, tgt_func): """Replicates metadata of the function. Returns target function.""" - tgt_func.__dict__.update(src_func.__dict__) - tgt_func.__doc__ = src_func.__doc__ - tgt_func.__module__ = src_func.__module__ - tgt_func.__name__ = src_func.__name__ - if hasattr(src_func, '__qualname__'): - tgt_func.__qualname__ = src_func.__qualname__ - if not hasattr(tgt_func, 'compat_co_firstlineno'): - tgt_func.compat_co_firstlineno = _getrawcode(src_func).co_firstlineno + functools.update_wrapper(tgt_func, src_func) + tgt_func.__wrapped__ = src_func # Python2 compatibility. return tgt_func