403Webshell
Server IP : 127.0.0.1  /  Your IP : 216.73.216.109
Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10
System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64
User : SERVERWEB ( 0)
PHP Version : 8.1.10
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : OFF |  Perl : OFF |  Python : OFF |  Sudo : OFF |  Pkexec : OFF
Directory :  C:/cygwin64/lib/python3.9/site-packages/_pytest/assertion/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : C:/cygwin64/lib/python3.9/site-packages/_pytest/assertion/__pycache__/rewrite.cpython-39.pyc
a

05d��.@szdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl.m0Z0ddl1m2Z2e�r�ddl%m3Z3e
j4dk�r�ej5Z6nej7Z6e2d�Z8e
j9j:�de$��Z;dd �r�d!�p�d"Z<d#e;e<Z=Gd$d%�d%ej>j?ej>j@�ZAeeBejCejDdd&�d'd(�ZEdejDejCeeFd)�d*d+�ZGee+eejCejDfd,�d-d.�ZHd/d0�feeeeIgdfeejDd1�d2d3�ZJdxejKeBeeIee+dd4�d5d6�ZLeMeId7�d8d9�ZNee+eeOd:�d;d<�ZPeMeId7�d=d>�ZQeMeFd7�d?d@�ZReeIeFeIdA�dBdC�ZSeeIeeFeeIeeMeIdD�dEdF�ZTeOeIeIddG�dHdI�ZUeFdJ�dKdL�ZVejWdMejXdNejYdOejZdPiZ[ej\dQej]dRej^dSej_dTej`dUejadVejbdWejcdXejddYejedZejfd[ejgd\ejhd]ejid^ejjd_ejkd`ejldaejmdbejndcejoddejpdeejqdfejrdgiZsejteejtdh�didj�Zuejvdkdl�eBeeOeIfdm�dndo��ZwGdpdq�dqejx�ZyeeFdr�dsdt�Zzeedu�dvdw�Z{dS)yz5Rewrite assertion AST to produce nice error messages.�N)�Path)�PurePath)�Callable)�Dict)�IO)�Iterable)�Iterator)�List)�Optional)�Sequence)�Set)�Tuple)�
TYPE_CHECKING)�Union)�DEFAULT_REPR_MAX_SIZE)�saferepr)�version)�util)�format_explanation)�Config)�Session)�absolutepath)�
fnmatch_ex)�StashKey)�AssertionState���rz-pytest-�.pyT�c�o�.c@sPeZdZdZedd�dd�Zeedd�dd�Ze	j
jjZ
d*eeeeeefeejee	j
jd	�d
d�Ze	j
jeejd�d
d�Zejdd�dd�Zeded�dd�Zeeded�dd�Zeded�dd�Zedd�dd�Zedd�dd �Zeeefed!�d"d#�Zejd$k�rLejd%k�r0d&d'l m!Z!nd&d'l"m!Z!ee!d�d(d)�Z#dS)+�AssertionRewritingHookz1PEP302/PEP451 import hook which rewrites asserts.N��config�returncCsf||_z|�d�|_Wnty2ddg|_Yn0d|_i|_t�|_d|_dh|_	i|_
d|_dS)NZpython_filesz	test_*.pyz	*_test.pyFZconftest)r$�getini�fnpats�
ValueError�session�_rewritten_names�set�
_must_rewrite�_writing_pyc�_basenames_to_check_rewrite�_marked_for_rewrite_cache�_session_paths_checked)�selfr$�r2�=/usr/lib/python3.9/site-packages/_pytest/assertion/rewrite.py�__init__@szAssertionRewritingHook.__init__)r)r%cCs||_d|_dS)NF)r)r0)r1r)r2r2r3�set_sessionPsz"AssertionRewritingHook.set_session)�name�path�targetr%cCs�|jr
dS|jjt}|�||�r&dS|�d|�|�||�}|dusp|jduspt|j	t
jj�rpt
j�|j�stdS|j}|�|||�s�dSt
jj||||jd�S)Nzfind_module called for: %s)�loader�submodule_search_locations)r-r$�stash�assertstate_key�_early_rewrite_bailout�trace�
_find_spec�origin�
isinstancer9�	importlib�	machinery�SourceFileLoader�osr7�exists�_should_rewriter�spec_from_file_locationr:)r1r6r7r8�state�spec�fnr2r2r3�	find_specWs2���	��z AssertionRewritingHook.find_spec)rJr%cCsdS�Nr2)r1rJr2r2r3�
create_modulesz$AssertionRewritingHook.create_module)�moduler%cCs|jdusJ�|jjdusJ�t|jj�}|jjt}||j|j<tj	}t
|�}|rvt|�}|svd}|�d|���|j
dd�t}||}t|||j�}	|	dur�|�d|���t||j�\}
}	|r�d|_zt||	|
|�Wd|_nd|_0n|�d|���t|	|j�dS)NFzread only directory: ���z
rewriting Tzfound cached rewritten pyc for )�__spec__r@rr$r;r<r*�__name__�sys�dont_write_bytecode�
get_cache_dir�try_makedirsr>r6�PYC_TAIL�	_read_pyc�
_rewrite_testr-�
_write_pyc�exec�__dict__)r1rOrKrI�write�	cache_dir�okZ
cache_name�pyc�co�source_statr2r2r3�exec_module�s2
z"AssertionRewritingHook.exec_moduler)r6rIr%cCs�|jdurP|jsPd|_|jjD]0}t|��tj�}|j�tj	�
|d�d�q|�d�}|d|jvrldSt|��d�}|j
D]&}tj	�|�r�dSt||�r�dSq�|�||�r�dS|�d|���dS)	a'A fast way to get out of rewriting modules.

        Profiling has shown that the call to PathFinder.find_spec (inside of
        the find_spec from this class) is a major slowdown, so, this method
        tries to filter what we're sure won't be rewritten before getting to
        it.
        NT���rr!Frz early skip of rewriting module: )r)r0Z
_initialpaths�str�splitrE�sepr.�addr7�splitextr�with_suffixr'�dirnamer�_is_marked_for_rewriter>)r1r6rIZinitial_path�partsr7�patr2r2r3r=�s$


z-AssertionRewritingHook._early_rewrite_bailout)r6rKrIr%cCs�tj�|�dkr$|�d|���dS|jdurR|j�t|��rR|�d|���dSt|�}|jD]$}t	||�r`|�d|���dSq`|�
||�S)Nzconftest.pyzrewriting conftest file: Tz.matched test file (was specified on cmdline): zmatched test file )rEr7�basenamer>r)Z
isinitpathrrr'rrl)r1r6rKrIZfn_pathrnr2r2r3rG�s


z&AssertionRewritingHook._should_rewritecCs|z|j|WStyv|jD]D}||ks:|�|d�r |�d|�d|�d��d|j|<YdSq d|j|<YdS0dS)Nr!zmatched marked file z (from �)TF)r/�KeyErrorr,�
startswithr>)r1r6rIZmarkedr2r2r3rl�s



z-AssertionRewritingHook._is_marked_for_rewrite)�namesr%cGspt|��tj��|j�}|D]8}tj|}t�|jp6d�st	|j
t|��s|�|�q|j
�|�|j��dS)z�Mark import names as needing to be rewritten.

        The named module or package as well as any nested modules will
        be rewritten on import.
        �N)r+�intersectionrS�modules�
differencer*�AssertionRewriter�is_rewrite_disabled�__doc__rA�
__loader__�type�_warn_already_importedr,�updater/�clear)r1rsZalready_importedr6�modr2r2r3�mark_rewrite�s�
��z#AssertionRewritingHook.mark_rewrite�r6r%cCs(ddlm}|jj|d|�dd�dS)Nr��PytestAssertRewriteWarningz2Module already imported so cannot be rewritten: %s�)�
stacklevel)�_pytest.warning_typesr�r$Zissue_config_time_warning)r1r6r�r2r2r3r}	s��z-AssertionRewritingHook._warn_already_imported)�pathnamer%cCs6t|d��}|��Wd�S1s(0YdS)zOptional PEP302 get_data API.�rbN)�open�read)r1r��fr2r2r3�get_dataszAssertionRewritingHook.get_data�r�
)r�r)�TraversableResourcescCs:tjdkrddlm}nddlm}|tj|j|d��S)N)r�r)�
FileReader)r7)rS�version_infoZimportlib.readersr�Zimportlib.resources.readers�types�SimpleNamespacer*)r1r6r�r2r2r3�get_resource_readers
�z*AssertionRewritingHook.get_resource_reader)NN)$rR�
__module__�__qualname__rzrr4r
rr5rBrC�
PathFinderrLr?rerr�bytesr��
ModuleType�
ModuleSpecrNrc�boolr=rGrlr�r}r�rSr�Zimportlib.resources.abcr��
importlib.abcr�r2r2r2r3r"=s6
�
�)�*'

r")�fprbrar%cCs\|�tjj�d}|�|�t|j�d@}|jd@}|�t�d||��|�t	�
|��dS)N����z<LL)r]rBr�MAGIC_NUMBER�int�st_mtime�st_size�struct�pack�marshal�dumps)r�rbra�flags�mtime�sizer2r2r3�
_write_pyc_fp)s

r�)rIrarbr`r%c
Cs�|�dt����}z:t|d��}t|||�Wd�n1s@0YWn>ty�}z&|�d|�d|j���WYd}~dSd}~00zt�||�Wn<ty�}z$|�d|�d|���WYd}~dSd}~00dS)Nr!�wbzerror writing pyc file at z: errno=Fz: T)rE�getpidr�r��OSErrorr>�errno�replace)rIrarbr`Zproc_pycr��er2r2r3rZ;s.rZ)rKr$r%cCsNt�|�}|��}t|�}tj||d�}t||||�t||ddd�}||fS)z1Read and rewrite *fn* and return the code object.)�filenamer[T)�dont_inherit)rE�stat�
read_bytesre�ast�parse�rewrite_asserts�compile)rKr$r��sourceZstrfnZtreerar2r2r3rYTs
rYcCsdSrMr2)�xr2r2r3�<lambda>`�r�)r�r`r>r%cCsJzt|d�}Wnty"YdS0|��
z(t�|�}t|j�}|j}|�d�}WnFty�}z.|d|�d|���WYd}~Wd�dSd}~00t|�dkr�|d|�Wd�dS|dd�t	j
jk�r�|d|�Wd�dS|dd	�d
k�r$|d|�Wd�dS|d	d�}	t�|	d
�|d@k�rb|d|�Wd�dS|dd�}
t�|
d
�|d@k�r�|d|�Wd�dSzt
�|�}WnHt�y�}z.|d|�d|���WYd}~Wd�dSd}~00t|tj��s"|d|�Wd�dS|Wd�S1�s<0YdS)zsPossibly read a pytest pyc containing rewritten code.

    Return rewritten code if successful or None if not.
    r�N�z
_read_pyc(z): OSError z&_read_pyc(%s): invalid pyc (too short)�z-_read_pyc(%s): invalid pyc (bad magic number)rr�z._read_pyc(%s): invalid pyc (unsupported flags)r��littler�z_read_pyc(%s): out of datez+_read_pyc(%s): invalid pyc (incorrect size)z): marshal.load error z _read_pyc(%s): not a code object)r�r�rEr�r�r�r�r��lenrBrr��
from_bytesr��load�	ExceptionrAr��CodeType)r�r`r>r��stat_resultr�r��datar�Z
mtime_dataZ	size_datarar2r2r3rX_sN

$$rX)r�r��module_pathr$r%cCst|||��|�dS)z%Rewrite the assert statements in mod.N)rx�run)r�r�r�r$r2r2r3r��sr�)�objr%cCsttj�}t||d��dd�S)a�Get a safe repr of an object for assertion error messages.

    The assertion formatting (util.format_explanation()) requires
    newlines to be escaped since they are a special character for it.
    Normally assertion.util.format_explanation() does this but for a
    custom repr it is possible to contain one of the special escape
    sequences, especially '\n{' and '\n}' are likely to be present in
    JSON reprs.
    ��maxsize�
�\n)�_get_maxsize_for_safereprrZ_configrr�)r�r�r2r2r3�	_saferepr�s

r�r#cCs6|dur|�d�nd}|dkr"dS|dkr2tdStS)zJGet `maxsize` configuration for saferepr based on the given config object.N�verboser��r�)Z	getoptionr)r$�	verbosityr2r2r3r��sr�cCsBddg}t|t�s$t|�}|�d�|D]\}}|�||�}q(|S)z�Format the custom assertion message given.

    For strings this simply replaces newlines with '\n~' so that
    util.format_explanation() will preserve them instead of escaping
    newlines.  For other objects saferepr() is used first.
    )r��
~)�%�%%)r�r�)rArer�appendr�)r�ZreplacesZr1Zr2r2r2r3�_format_assertmsg�s

r�cCs4t|�rdSzt|d�WSty.YdS0dS)NFrRT)�callable�hasattrr�)r�r2r2r3�_should_repr_global_name�sr�)�explanations�is_orr%cCs&d|r
dpd�|�d}|�dd�S)N�(z or z and rpr�r�)�joinr�)r�r��explanationr2r2r3�_format_boolop�sr�)�ops�results�expls�each_objr%c		Cs�ttt|��||�D]4\}}}z
|}Wnty>d}Yn0|rqJqtjdur~t�||||||d�}|dur~|S|S)NTr�)�zip�ranger�r�rZ_reprcompare)	r�r�r�r��i�res�explZdoneZcustomr2r2r3�_call_reprcompare�s


r�)�lineno�origr�r%cCstjdurt�|||�dSrM�rZ_assertion_pass)r�r�r�r2r2r3�_call_assertion_pass�s
r��r%cCstjr
dSdS)z�Check if any plugins implement the pytest_assertion_pass hook
    in order not to generate explanation unnecessarily (might be expensive).TFr�r2r2r2r3�_check_if_assertion_pass_impl�sr�znot %sz~%sz-%sz+%s�|�^�&z<<z>>�+�-�*�/z//r�z==z!=�<z<=�>z>=�**�iszis not�inznot in�@��noder%ccs(|Vt�|�D]}t|�EdHqdS)zARecursively yield node and all its children in depth-first order.N)r�Ziter_child_nodes�
traverse_node)r�childr2r2r3rsrr�r�)�srcr%c
s�i�d�g�d�t��dd������fdd�}t�t�|�j�}|D�]d\}}\}}}}|tjkrr|dkrr|�qF�durF|tjkr�|dvr��d7�n|tjkr�|d	vr��d8��s҈�||d����|�qF�dk�rr|tjk�rr|d
k�rr|�v�r8t	��dk�r8|t	�d�t	|�}	�dd|	��d<n2|�v�rX�dd|��d<n��|d|��|�qF|tj
tjhv�r�|�qF�rF|�vrF��|���|�qF�S)z<Return a mapping from {lineno: "assertion test expression"}.rNr�cs:�dusJ�d������d���<d�g�d�t��dS)Nrt�\r)r��rstripr+r2�Z
assert_lineno�depth�lines�retZ
seen_linesr2r3�_write_and_reset$sz._get_assertion_exprs.<locals>._write_and_reset�assertz([{r�z)]}�,rd)r+�tokenize�io�BytesIO�readline�NAME�OPr�rhr��NEWLINE�	ENDMARKER)
rr�tokens�tpr�r��offset�_�lineZoffset_in_trimmedr2r
r3�_get_assertion_exprss@	
 

rcseZdZdZeeeeedd��fdd�Ze	j
dd�dd�Zeee
d	�d
d��Zed�d
d�Ze	je	jd�dd�Ze	je	jd�dd�Zee	je	jd�dd�Zee	jd�dd�Ze	jed�dd�Zdd�dd�Ze	je	jd�dd �Ze	jee	jefd!�d"d#�Ze	jee	jd$�d%d&�Z e!ee!efd�d'd(�Z"e	jee	jefd�d)d*�Z#e	j$ee	jefd+�d,d-�Z%e	j&ee	jefd.�d/d0�Z'e	j(ee	jefd1�d2d3�Z)e	j*ee	jefd4�d5d6�Z+e	j,ee	j,efd7�d8d9�Z-e	jee	jefd:�d;d<�Z.e	j/ee	jefd=�d>d?�Z0�Z1S)@rxa�
Assertion rewriting implementation.

    The main entrypoint is to call .run() with an ast.Module instance,
    this will then find all the assert statements and rewrite them to
    provide intermediate values and a detailed assertion error.  See
    http://pybites.blogspot.be/2011/07/behind-scenes-of-pytests-new-assertion.html
    for an overview of how this works.

    The entry point here is .run() which will iterate over all the
    statements in an ast.Module and for each ast.Assert statement it
    finds call .visit() with it.  Then .visit_Assert() takes over and
    is responsible for creating new ast statements to replace the
    original assert statement: it rewrites the test of an assertion
    to provide intermediate values and replace it with an if statement
    which raises an assertion error with a detailed explanation in
    case the expression is false and calls pytest_assertion_pass hook
    if expression is true.

    For this .visit_Assert() uses the visitor pattern to visit all the
    AST nodes of the ast.Assert.test field, each visit call returning
    an AST node and the corresponding explanation string.  During this
    state is kept in several instance attributes:

    :statements: All the AST statements which will replace the assert
       statement.

    :variables: This is populated by .variable() with each variable
       used by the statements so that they can all be set to None at
       the end of the statements.

    :variable_counter: Counter to create new unique variables needed
       by statements.  Variables are created using .variable() and
       have the form of "@py_assert0".

    :expl_stmts: The AST statements which will be executed to get
       data from the assertion.  This is the code which will construct
       the detailed assertion message that is used in the AssertionError
       or for the pytest_assertion_pass hook.

    :explanation_specifiers: A dict filled by .explanation_param()
       with %-formatting placeholders and their corresponding
       expressions to use in the building of an assertion message.
       This is used by .pop_format_context() to build a message.

    :stack: A stack of the explanation_specifiers dicts maintained by
       .push_format_context() and .pop_format_context() which allows
       to build another %-formatted string while already building one.

    :variables_overwrite: A dict filled with references to variables
       that change value within an assert. This happens when a variable is
       reassigned with the walrus operator

    This state, except the variables_overwrite,  is reset on every new assert
    statement visited and used by the other visitors.
    N)r�r$r�r%csBt���||_||_|dur,|�d�|_nd|_||_i|_dS)N�enable_assertion_pass_hookF)�superr4r�r$r&rr��variables_overwrite)r1r�r$r���	__class__r2r3r4�s
�zAssertionRewriter.__init__)r�r%cs|js
dSt|dd�}|du}|dur4|�|�r4dSd}d}|jD]n}|r�t|tj�r�t|jtj�r�|jj}|�|�r|dSd}n&t|tj	�r�|j
dkr�|jdkr�nq�|d7}qBt|tj�r�|j
r�|j
dj�n|j�tjdk�r
tjdd	�dd
�tjdd�dd
�g}nt�dd	�t�dd�g}�fd
d�|D�}||j||�<|g}|�r
|��}	t�|	�D]�\}
}t|t��r�g}t|�D]L\}
}t|tj��r�|�|�|��n"|�|�t|tj��r�|�|��q�t|	|
|�n&t|tj��r`t|tj��s`|�|��q`�qHdS)z5Find all assert statements in *mod* and rewrite them.N�	docstringrFZ
__future__r�r��builtins�@py_builtins�r��
col_offsetz_pytest.assertion.rewrite�
@pytest_arcsg|]}tj|g�dd��qS)rr')r�ZImport)�.0�alias�r�r2r3�
<listcomp>�sz)AssertionRewriter.run.<locals>.<listcomp>)�body�getattrryrAr��Expr�value�Str�sZ
ImportFrom�levelrOZFunctionDef�decorator_listr�rSr�r+�popZiter_fields�list�	enumerate�Assert�extend�visitr��AST�setattr�expr)r1r��docZexpect_docstring�pos�item�aliasesZimportsZnodesrr6Zfield�newr�rr2r,r3r��s�
�
��

���
��

�
�

�
�zAssertionRewriter.run)r$r%cCsd|vS)NZPYTEST_DONT_REWRITEr2)r$r2r2r3ry�sz%AssertionRewriter.is_rewrite_disabledr�cCs"dtt|j��}|j�|�|S)zGet a new variable.z
@py_assert)re�next�variable_counter�	variablesr�)r1r6r2r2r3�variable�szAssertionRewriter.variable)r>r%c	Cs:|��}|j�t�t�|t���g|��t�|t���S)zGive *expr* a name.)rG�
statementsr�r��Assign�Name�Store�Load)r1r>r6r2r2r3�assign�s"zAssertionRewriter.assigncCs|�d|�S)z Call saferepr on the expression.r�)�helper)r1r>r2r2r3�display�szAssertionRewriter.display)r6�argsr%cGs4t�dt���}t�||t���}t�|t|�g�S)zCall a helper in this module.r))r�rJrL�	Attribute�Callr7)r1r6rPZpy_name�attrr2r2r3rNszAssertionRewriter.helperr�cCs"t�dt���}t�||t���S)z!Return the builtin called *name*.r&)r�rJrLrQ)r1r6�builtin_namer2r2r3�builtinszAssertionRewriter.builtincCs(dtt|j��}||j|<d|dS)aJReturn a new named %-formatting placeholder for expr.

        This creates a %-formatting placeholder for expr in the
        current formatting context, e.g. ``%(py0)s``.  The placeholder
        and expr are placed in the current format context so that it
        can be used on the next call to .pop_format_context().
        �pyz%(z)s)rerDrE�explanation_specifiers)r1r>Z	specifierr2r2r3�explanation_param
s
z#AssertionRewriter.explanation_paramcCsi|_|j�|j�dS)a�Create a new formatting context.

        The format context is used for when an explanation wants to
        have a variable value formatted in the assertion message.  In
        this case the value required can be added using
        .explanation_param().  Finally .pop_format_context() is used
        to format a string of %-formatted values as added by
        .explanation_param().
        N)rW�stackr��r1r2r2r3�push_format_contexts
z%AssertionRewriter.push_format_context)�	expl_exprr%c	Cs�|j��}|jr|jd|_dd�|��D�}t�|t|����}t�|t�	�|�}dt
t|j��}|j
rx|j�|�|j�t�t�|t���g|��t�|t���S)aZFormat the %-formatted string with current format context.

        The expl_expr should be an str ast.expr instance constructed from
        the %-placeholders created by .explanation_param().  This will
        add the required code to format said string to .expl_stmts and
        return the ast.Name instance of the formatted string.
        rdcSsg|]}t�|��qSr2)r�r2)r*�keyr2r2r3r-1r�z8AssertionRewriter.pop_format_context.<locals>.<listcomp>z
@py_format)rYr6rW�keysr�rr7�values�BinOp�ModrerDrEr�format_variablesr��
expl_stmtsrIrJrKrL)r1r\�currentr^Zformat_dictZformr6r2r2r3�pop_format_context&s
"z$AssertionRewriter.pop_format_contextrcCs.t|tj�sJ�|�|�}||�|�|��fS)z1Handle expressions we don't have custom code for.)rAr�r>rMrXrO)r1rr�r2r2r3�
generic_visit:s
zAssertionRewriter.generic_visit)�assert_r%c	Cs8t|jtj�rZt|jj�dkrZddlm}ddl}|j	dus@J�|j
|d�d|j	|jd�g|_g|_
t��|_|jr|g|_g|_g|_|��|�|j�\}}t�t��|�}|j�r |�t�|��}|jr�|�d|j�}d}	nt�d	�}d
}	t�t�|	�t��|�}
t�|t��|
�}t�dt� ��}|�d|�}
t�!||
gg�}t�"|d�}g}|�#|j�|�$|�|�d|�}t%|j&�|j}t�'|�d
t�(|j�t�|�|��}t�)|�d�|j|gg�}|g}t�)|||�}|j�$|�|j�r�dd�|jD�}t�*|t�+d��}|j�$|�n�|j}|j�$t�)||g��|j�r\|�d|j�}d|}nt�d	�}d
|}t�|t��t�|��}|�|�}|�d|�}
t�dt� ��}t�!||
gg�}t�"|d�}|�$|�|j
�rdd�|j
D�}t�*|t�+d��}|j�$|�|jD]"}t,|�D]}t�-||��q�q|jS)a.Return the AST statements to replace the ast.Assert instance.

        This rewrites the test of an assertion to provide
        intermediate values and replace it with an if statement which
        raises an assertion error with a detailed explanation in case
        the expression is false.
        r�rr�Nz5assertion is always true, perhaps remove parentheses?)�categoryr�r�r�z	
>assert rtzassert �AssertionError�_format_explanationr�r�cSsg|]}t�|t����qSr2�r�rJrK�r*r6r2r2r3r-�sz2AssertionRewriter.visit_Assert.<locals>.<listcomp>cSsg|]}t�|t����qSr2rkrlr2r2r3r-�r�).rA�testr�r
r��eltsr�r��warningsr��
warn_explicitr�rHrF�	itertools�countrErrbrYrcr[r;�UnaryOp�Notrer2�msgrNr`�AddrJrLrRZRaiser:r�rr�r0�Num�IfrIZNameConstantrZ
copy_location)r1rgr�roZ
top_conditionr�ZnegationruZ	assertmsgZgluestrZerr_explanation�err_msgZerr_nameZfmt�excZraise_Zstatements_failZfmt_passr�Zhook_call_passZhook_impl_testZstatements_passZ	main_testrFZclear_formatr.�templater�stmtrr2r2r3�visit_Assert@s���	



��	
��




zAssertionRewriter.visit_AssertcCs�t�|�d�gg�}|jj}t�t�|�t��g|g�}|�d|�}t�	t�
�||g�}t�||�|�t�|��}||�
|�fS�N�localsr�)r�rRrUr8�id�Comparer2�InrN�BoolOp�Or�IfExprOrX)r1r6�locsZ	target_id�inlocs�doreprrmr>r2r2r3�visit_NamedExpr�sz!AssertionRewriter.visit_NamedExprcCs|t�|�d�gg�}t�t�|j�t��g|g�}|�d|�}t�t�	�||g�}t�
||�|�t�|j��}||�|�fSr~)
r�rRrUr�r2r�r�rNr�r�r�rOrX)r1r6r�r�r�rmr>r2r2r3�
visit_Name�szAssertionRewriter.visit_Name)�boolopr%c
Cs�|��}|�t�gt����}t�|dt���}tt|jtj	��}|j
}}|j}t|j
�d}	|��t|j
�D�]6\}
}|
r�g}|j�t�|
|g��||_t|tj�r�t|jt�r�|jjjdd�|j
d|
�D�vr�|��}||j|jjj<||jj_|��|�|�\}}|�t�t�|t���g|��|�t�|��}t�||gg�}|j�t�|��|
|	krr|}
|�r�t� t�!�|
�}
g}|j
�t�|
|g��||_
}qr||_
||_|�"d|t�#|��}|�|�}t�|t���|�$|�fS)Nr�r�cSsg|]}t|d�r|j�qS)r�)r�r�)r*Zast_exprr2r2r3r-�s
�z2AssertionRewriter.visit_BoolOp.<locals>.<listcomp>r�)%rGrMr�r	rLrQr�rA�opr�rHrcr�r_r[r8r�rxr��left�	namedExprr8r�r!r;rIrJrKrer2rRr0rsrtrNrwrX)r1r�Zres_varZ	expl_listZappr�r.ZsaveZ	fail_saveZlevelsr��vZ
fail_innerZcondZpytest_tempr�r�Zexpl_format�call�innerZ
expl_templater2r2r3�visit_BoolOp�sX

�
����

 
zAssertionRewriter.visit_BoolOp)�unaryr%cCs>t|jj}|�|j�\}}|�t�|j|��}|||ffSrM)�	UNARY_MAPr�r#r;�operandrMr�rs)r1r��patternZoperand_resZoperand_explr�r2r2r3�
visit_UnaryOp�szAssertionRewriter.visit_UnaryOp)�binopr%c	Csbt|jj}|�|j�\}}|�|j�\}}d|�d|�d|�d�}|�t�||j|��}||fS)Nr�� rp)	�	BINOP_MAPr�r#r;r��rightrMr�r`)	r1r��symbolZ	left_expr�	left_explZ
right_exprZ
right_explr�r�r2r2r3�visit_BinOpszAssertionRewriter.visit_BinOp)r�r%cCs�|�|j�\}}g}g}g}|jD]&}|�|�\}}	|�|	�|�|�q"|jD]R}
|�|
j�\}}	|�t�|
j|��|
jr�|�|
jd|	�qP|�d|	�qPd�	|d�
|��}	t�|||�}|�|�}|�
|�|��}|�d|�d|	�d�}
||
fS)N�=r�z{}({})z, z
{z = z
})r;�funcrPr��keywordsr1r��keyword�arg�formatr�rRrMrXrO)r1r��new_funcZ	func_explZ	arg_expls�new_argsZ
new_kwargsr�r�r�r�Znew_call�res_explZ
outer_explr2r2r3�
visit_Call
s(



zAssertionRewriter.visit_Call)�starredr%cCs*|�|j�\}}t�||j�}|d|fS)Nr�)r;r1r��Starred�ctx)r1r�r�r�Znew_starredr2r2r3�
visit_Starred"szAssertionRewriter.visit_Starred)rSr%cCspt|jtj�s|�|�S|�|j�\}}|�t�||j	t����}|�
|�|��}d}|||||j	f}||fS)Nz%s
{%s = %s.%s
})rAr�r�rLrfr;r1rMrQrSrXrO)r1rSr1Z
value_explr�r�rnr�r2r2r3�visit_Attribute(s
z!AssertionRewriter.visit_Attribute)�compr%csH���t|jtj�r6|jj�jvr6�j|jj|j_��|j�\}}t|jtjtj	f�rfd|�d�}�fdd�t
t|j��D�}dd�|D�}dd�|D�}t
t
t|j��|j|j�}g}g}	|g}
|D]�\}}}
t|
t��rt|tj��r|
jj|jk�r���|
j_|
jj�j|j<��|
�\}}t|
tjtj	f��rHd|�d�}|
�|�t|j}|	�t�|��|�d|�d|��}|�t�|��t�||g|g�}�j�t�||g|��||}}qʈ�dt�|	t���t�|t���t�|t���t�|
t����}t|j�d	k�r,t�	t��|�}n|d
}|����|��fS)Nr�rpcsg|]}����qSr2)rG)r*r�rZr2r3r-:r�z3AssertionRewriter.visit_Compare.<locals>.<listcomp>cSsg|]}t�|t����qSr2)r�rJrL�r*r�r2r2r3r-;r�cSsg|]}t�|t����qSr2rkr�r2r2r3r-<r�r�r�r�r)r[rAr�r�rJr�r!r;r�r�r�r�r�r��comparatorsr�r8rGr�r�r#r2rHrIrNr
rLZAndrXre)r1r�Zleft_resr�Z
res_variablesZ
load_namesZstore_names�itr�Zsymsr�r�r�Znext_operandZnext_resZ	next_explZsymr�Zres_exprZ	expl_callr�r2rZr3�
visit_Compare2sX�
��

�zAssertionRewriter.visit_Compare)2rRr�r�rzr
rerr�r4r��Moduler��staticmethodr�ryrGr>rJrMrOrNrQrUrXr[rer<r
rfr9r	r|r}r�r�r�r�r�rsr�r`r�rRr�r�r�r�r�r��
__classcell__r2r2r"r3rxQs49�T
u
1
rx)r^r%c
Cs�ztj|dd�Wnjtttfy,YdSty>YdSty|}z(|jtjkrfWYd}~dS�WYd}~n
d}~00dS)z~Attempt to create the given directory and sub-directories exist.

    Returns True if successful or if it already exists.
    T)�exist_okFN)	rE�makedirs�FileNotFoundError�NotADirectoryError�FileExistsError�PermissionErrorr�r�ZEROFS)r^r�r2r2r3rVdsrV)�	file_pathr%cCs:tjdkr,tjr,ttj�t|jdd��S|jdSdS)zKReturn the cache directory to write .pyc files for the given .py file path.rr�rd�__pycache__N)rSr��pycache_prefixrrm�parent)r�r2r2r3rUzsrU)NN)|rzr�r��	functoolsr�rBZimportlib.machinery�importlib.utilrrqr�rEr�rSrr��pathlibrr�typingrrrrrr	r
rrr
rrZ_pytest._io.safereprrrZ_pytest._versionrZ_pytest.assertionrZ_pytest.assertion.utilrrjZ_pytest.configrZ_pytest.mainrZ_pytest.pathlibrrZ
_pytest.stashrrr�Z	NamedExprr�r0r<�implementation�	cache_tagZ
PYTEST_TAGZPYC_EXTrW�abc�MetaPathFinder�Loaderr"r�r�r�r�r�rZrYrerXr�r��objectr�r�r�r�r�r�r�r�r�rtZInvertZUSubZUAddr�ZBitOrZBitXorZBitAndZLShiftZRShiftrvZSubZMultZDivZFloorDivraZEqZNotEqZLtZLtEZGtZGtEZPowZIsZIsNotr�ZNotInZMatMultr�r<r�	lru_cacherZNodeVisitorrxrVrUr2r2r2r3�<module>s�
n����4��


��
6

Youez - 2016 - github.com/yon3zu
LinuXploit