Your IP : 216.73.216.196


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

B

C$�X#�@s�dZddlZddlZddlZddlmZddlZe�d�Zej	dd��Z
dd�Zd	d
�Zdd�Z
Gd
d�d�Ze�ZGdd�d�ZdS)z, monkeypatching and mocking functionality.  �N)�_basestringz^No module named (.*)$ccst�}|V|��dS)a�The returned ``monkeypatch`` fixture provides these
    helper methods to modify objects, dictionaries or os.environ::

        monkeypatch.setattr(obj, name, value, raising=True)
        monkeypatch.delattr(obj, name, raising=True)
        monkeypatch.setitem(mapping, name, value)
        monkeypatch.delitem(obj, name, raising=True)
        monkeypatch.setenv(name, value, prepend=False)
        monkeypatch.delenv(name, value, raising=True)
        monkeypatch.syspath_prepend(path)
        monkeypatch.chdir(path)

    All modifications will be undone after the requesting
    test function or fixture has finished. The ``raising``
    parameter determines if a KeyError or AttributeError
    will be raised if the set/deletion operation has no target.
    N)�MonkeyPatch�undo)Zmpatch�r�D/opt/alt/python37/lib/python3.7/site-packages/_pytest/monkeypatch.py�monkeypatch
srcCs�|�d�}|�d�}t|�}x�|D]�}|d|7}yt||�}Wq"tk
rTYnXq"yt|�WnNtk
r�}z0t|���d}||kr��ntd||f��Wdd}~XYnXt|||�}q"W|S)N�.r���zimport error in %s: %s)�split�pop�
__import__�getattr�AttributeError�ImportError�str�annotated_getattr)�name�parts�used�found�part�exZexpectedrrr�resolve%s(


 rcCs@yt||�}Wn,tk
r:tdt|�j||f��YnX|S)Nz#%r object at %s has no attribute %r)r
r�type�__name__)�objr�annrrrrDsrcCsRt|t�rd|kr td|f��|�dd�\}}t|�}|rJt|||d�||fS)Nrz+must be absolute import path string, not %r�)r)�
isinstancer�	TypeError�rsplitrr)Zimport_path�raising�module�attr�targetrrr�derive_importpathPs
r%c@seZdZdd�ZdS)�NotsetcCsdS)Nz<notset>r)�selfrrr�__repr__\szNotset.__repr__N)r�
__module__�__qualname__r(rrrrr&[sr&c@sreZdZdZdd�Zedfdd�Zedfdd�Zd	d
�Zddd�Z	ddd�Z
ddd�Zdd�Zdd�Z
dd�Zd
S)rzj Object returned by the ``monkeypatch`` fixture keeping a record of setattr/item/env/syspath changes.
    cCsg|_g|_d|_d|_dS)N)�_setattr�_setitem�_cwd�_savesyspath)r'rrr�__init__gszMonkeyPatch.__init__TcCs�d}ddl}|tkr8t|t�s&td��|}t||�\}}t||t�}|r`|tkr`td||f��|�|�rx|j	�
|t�}|j�|||f�t
|||�dS)ak Set attribute value on target, memorizing the old value.
        By default raise AttributeError if the attribute did not exist.

        For convenience you can specify a string as ``target`` which
        will be interpreted as a dotted import path, with the last part
        being the attribute name.  Example:
        ``monkeypatch.setattr("os.getcwd", lambda x: "/")``
        would set the ``getcwd`` function of the ``os`` module.

        The ``raising`` value determines if the setattr should fail
        if the attribute is not already present (defaults to True
        which means it will raise).
        TrNzcuse setattr(target, name, value) or setattr(target, value) with target being a dotted import stringz%r has no attribute %r)�inspect�notsetrrrr%r
r�isclass�__dict__�getr+�append�setattr)r'r$r�valuer!�__tracebackhide__r0Zoldvalrrrr6ms

zMonkeyPatch.setattrcCsld}|tkr,t|t�std��t||�\}}t||�sD|rht|��n$|j�||t	||t�f�t
||�dS)a� Delete attribute ``name`` from ``target``, by default raise
        AttributeError it the attribute did not previously exist.

        If no ``name`` is specified and ``target`` is a string
        it will be interpreted as a dotted import path with the
        last part being the attribute name.

        If ``raising`` is set to False, no exception will be raised if the
        attribute is missing.
        TzUuse delattr(target, name) or delattr(target) with target being a dotted import stringN)r1rrrr%�hasattrrr+r5r
�delattr)r'r$rr!r8rrrr:�s


zMonkeyPatch.delattrcCs&|j�|||�|t�f�|||<dS)z) Set dictionary entry ``name`` to value. N)r,r5r4r1)r'�dicrr7rrr�setitem�szMonkeyPatch.setitemcCs:||kr|r6t|��n |j�|||�|t�f�||=dS)z� Delete ``name`` from dict. Raise KeyError if it doesn't exist.

        If ``raising`` is set to False, no exception will be raised if the
        key is missing.
        N)�KeyErrorr,r5r4r1)r'r;rr!rrr�delitem�s

zMonkeyPatch.delitemNcCs<t|�}|r(|tjkr(||tj|}|�tj||�dS)z� Set environment variable ``name`` to ``value``.  If ``prepend``
        is a character, read the current environment variable value
        and prepend the ``value`` adjoined with the ``prepend`` character.N)r�os�environr<)r'rr7Zprependrrr�setenv�szMonkeyPatch.setenvcCs|jtj||d�dS)z� Delete ``name`` from the environment. Raise KeyError it does not
        exist.

        If ``raising`` is set to False, no exception will be raised if the
        environment variable is missing.
        )r!N)r>r?r@)r'rr!rrr�delenv�szMonkeyPatch.delenvcCs0|jdkrtjdd�|_tj�dt|��dS)z< Prepend ``path`` to ``sys.path`` list of import locations. Nr)r.�sys�path�insertr)r'rDrrr�syspath_prepend�s
zMonkeyPatch.syspath_prependcCs6|jdkrt��|_t|d�r(|��n
t�|�dS)z} Change the current working directory to the specified path.
        Path can be a string or a py.path.local object.
        N�chdir)r-r?�getcwdr9rG)r'rDrrrrG�s




zMonkeyPatch.chdirc	Cs�x8t|j�D]*\}}}|tk	r,t|||�qt||�qWg|jdd�<xJt|j�D]<\}}}|tkr�y
||=Wq�tk
r�Yq�XqT|||<qTWg|jdd�<|jdk	r�|jtj	dd�<d|_|j
dk	r�t�|j
�d|_
dS)aE Undo previous changes.  This call consumes the
        undo stack. Calling it a second time has no effect unless
        you do more monkeypatching after the undo call.

        There is generally no need to call `undo()`, since it is
        called automatically during tear-down.

        Note that the same `monkeypatch` fixture is used across a
        single test function invocation. If `monkeypatch` is used both by
        the test function itself and one of the test fixtures,
        calling `undo()` will undo all of the changes made in
        both functions.
        N)
�reversedr+r1r6r:r,r=r.rCrDr-r?rG)r'rrr7�
dictionaryrrrr�s&


zMonkeyPatch.undo)T)N)T)rr)r*�__doc__r/r1r6r:r<r>rArBrFrGrrrrrrcs#

	
	r)rKr?rC�reZ
py.builtinr�pytest�compileZRE_IMPORT_ERROR_NAMEZfixturerrrr%r&r1rrrrr�<module>s