Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/testfixtures/__pycache__/replace.cpython-37.pyc

B

R�X,�@s�ddlmZddlmZddlmZmZddlmZm	Z	ddl
Z
dd�ZGdd	�d	�Zddd�Z
Gd
d�de�ZdZe	eejej
e
eg�dS)�)�partial)�	ClassType)�resolve�	not_there)�wrap�extend_docstringNcCst||�ot||�S)N)�
isinstance)�x�yZ
descriptor�r�E/opt/alt/python37/lib/python3.7/site-packages/testfixtures/replace.py�not_same_descriptorsr
c@sVeZdZdZdd�Zddd�Zddd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�Replacerz�
    These are used to manage the mocking out of objects so that units
    of code can be tested without having to rely on their normal
    dependencies.
    cCs
i|_dS)N)�	originals)�selfrrr�__init__szReplacer.__init__TcCsR|tkr*|dkrt||�|dkrN||=n$|dkr>t|||�|dkrN|||<dS)N�a�i)r�delattr�setattr)r�	container�name�method�value�strictrrr�_replaces
zReplacer._replacec	Cs�t|�\}}}}|dkr td��|tkr8|r8td|��|tkrL|tkrLtS|}t|ttf�r�t||t�rtt|�}nt||t	�r�t	|�}|�
|||||�||jkr�||j|<|S)zM
        Replace the specified target with the supplied replacement.
        Nz%target must contain at least one dot!zOriginal %r not found)r�
ValueErrorr�AttributeErrorr�typerr
�classmethod�staticmethodrr)	r�target�replacementrrr�	attributeZt_objZreplacement_to_userrr�__call__&s"


zReplacer.__call__cCs||||�dS)zM
        Replace the specified target with the supplied replacement.
        Nr)rr!r"rrrr�replaceBszReplacer.replacecCsLxFt|j���D]4\}}t|�\}}}}|j||||dd�|j|=qWdS)z�
        Restore all the original objects that have been replaced by
        calls to the :meth:`replace` method of this :class:`Replacer`.
        F)rN)�tupler�itemsrr)rr!�originalrrr#�foundrrr�restoreHszReplacer.restorecCs|S)Nr)rrrr�	__enter__RszReplacer.__enter__cCs|��dS)N)r*)rrr�	tracebackrrr�__exit__UszReplacer.__exit__cCs|jrt�d|j�dS)Nz;Replacer deleted without being restored, originals left: %r)r�warnings�warn)rrrr�__del__XszReplacer.__del__N)T)T)T)�__name__�
__module__�__qualname__�__doc__rrr$r%r*r+r-r0rrrrrs



rTcCst�}tt|j|||�|j�S)zY
    A decorator to replace a target object for the duration of a test
    function.
    )rrrr$r*)r!r"r�rrrrr%bsr%c@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)�ReplacezU
    A context manager that uses a :class:`Replacer` to replace a single target.
    TcCs||_||_||_t�|_dS)N)r!r"rr�	_replacer)rr!r"rrrrrpszReplace.__init__cCs|�|j|j|j�S)N)r7r!r"r)rrrrr+vszReplace.__enter__cCs|j��dS)N)r7r*)r�exc_typeZexc_val�exc_tbrrrr-yszReplace.__exit__N)T)r1r2r3r4rr+r-rrrrr6ks
r6a�
: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.
)T)�	functoolsrZtestfixtures.compatrZtestfixtures.resolverrZtestfixtures.utilsrrr.r
rr%�objectr6Zreplace_params_docr$rrrr�<module>sR