Example #1
0
def replace(target, replacement, strict=True):
    """
    A decorator to replace a target object for the duration of a test
    function.
    """
    r = Replacer()
    return wrap(partial(r.__call__, target, replacement, strict), r.restore)
Example #2
0
def tempdir(*args,**kw):
    """
    A decorator for making a :class:`TempDirectory` available for the
    duration of a test function.

    All arguments and parameters are passed through to the
    :class:`TempDirectory` constructor.
    """
    kw['create']=False
    l = TempDirectory(*args,**kw)
    return wrap(l.create,l.cleanup)
Example #3
0
def log_capture(*names, **kw):
    """
    A decorator for making a :class:`LogCapture` installed an
    available for the duration of a test function.

    :param names: An optional sequence of names specifying the loggers
                  to be captured. If not specified, the root logger
                  will be captured.
    """
    level = kw.pop('level',1)
    l = LogCaptureForDecorator(names or None, install=False, level=level)
    return wrap(l.install,l.uninstall)
Example #4
0
def log_capture(*names, **kw):
    """
    A decorator for making a :class:`LogCapture` installed an
    available for the duration of a test function.

    :param names: An optional sequence of names specifying the loggers
                  to be captured. If not specified, the root logger
                  will be captured.

    Keyword parameters other than ``install`` may also be supplied and will be
    passed on to the :class:`LogCapture` constructor.
    """
    l = LogCaptureForDecorator(names or None, install=False, **kw)
    return wrap(l.install, l.uninstall)
Example #5
0
def replace(target,replacement,strict=True):
    """
    A decorator to replace a target object for the duration of a test
    function.

    :param target: A string containing the dotted-path to the
                   object to be replaced. This path may specify a
                   module in a package, an attribute of a module,
                   or any attribute of something contained within
                   a module.

    :param replacement: The object to use as a replacement.

    :param strict: When `True`, an exception will be raised if an
                   attempt is made to replace an object that does
                   not exist.
    """
    r  = Replacer(replace_returns=True)
    return wrap(partial(r.replace,target,replacement,strict),r.restore)
Example #6
0
def log_capture(*names, **kw):
    l = LogCaptureForDecorator((names or None), install=False, **kw)
    return wrap(l.install, l.uninstall)