Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/__pycache__/TestUtils.cpython-37.opt-1.pyc

B

Z��Z+�@s�ddlmZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZGd	d
�d
e�Zdd�ZGd
d�dej�ZGdd�de�ZGdd�de
�Zddd�ZdS)�)�absolute_importN�)�Errors)�
CodeWriter)�TreeFragment�strip_common_indent)�TreeVisitor�VisitorTransform)�TreePathcs$eZdZ�fdd�Zdd�Z�ZS)�NodeTypeWritercstt|���d|_g|_dS)Nr)�superr�__init__�_indents�result)�self)�	__class__��C/opt/alt/python37/lib64/python3.7/site-packages/Cython/TestUtils.pyr
szNodeTypeWriter.__init__cCs�|jsd}n0|jd}|ddk	r4d|dd�}n|d}|j�d|jd||jjf�|jd7_|�|�|jd8_dS)	Nz(root)����z%s[%d]r�z  z%s: %s)Zaccess_pathr�appendrr�__name__�
visitchildren)r�node�nameZtiprrr�
visit_Nodes

zNodeTypeWriter.visit_Node)r�
__module__�__qualname__r
r�
__classcell__rr)rrrsrcCs(t�}|�|�d�dg|jdg�S)z�Returns a string representing the tree by class names.
    There's a leading and trailing whitespace so that it can be
    compared by simple string comparison while still making test
    cases look ok.�
�)rZvisit�joinr)�root�wrrr�	treetypes%s
r%c@sjeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�Zefdd�Z
dd�ZdS)�
CythonTestcCs tj|_tj|_dt_t_dS)N)r�listing_file�	echo_file)rrrr�setUp1szCythonTest.setUpcCs|jt_|jt_dS)N)r'rr()rrrr�tearDown6szCythonTest.tearDownc	Cs�t|t�s|�d�}t|t�s(|�d�}x6tt||��D]$\}\}}|�||d|||f�q8W|�t|�t|�dd�|�d�|�f�dS)zHChecks that the given strings or lists of strings are equal line by liner zLine %d:
Exp: %s
Got: %sz%Unmatched lines. Got:
%s
Expected:
%sN)�
isinstance�list�split�	enumerate�zip�assertEqual�lenr")r�expectedr�idx�
expected_lineZresult_linerrr�assertLines:s



zCythonTest.assertLinescCst�}|�|�|jjS)N)r�writer�lines)r�tree�writerrrr�codeToLinesFs
zCythonTest.codeToLinescCsd�|�|��S)Nr )r"r:)rr8rrr�codeToStringKszCythonTest.codeToStringc	Csx|�|�}t|�d��}x6tt||��D]$\}\}}|�||d|||f�q(W|�t|�t|�dd�|�|f�dS)Nr zLine %d:
Got: %s
Exp: %sz%Unmatched lines. Got:
%s
Expected:
%s)r:rr-r.r/r0r1r")rr2�result_treeZresult_linesZexpected_linesr3�liner4rrr�
assertCodeNs
zCythonTest.assertCodecCs|�t�||�dd|�dS)Nz"Path '%s' not found in result tree)ZassertNotEqualr
�
find_first)r�pathr<rrr�assertNodeExistsYszCythonTest.assertNodeExistsNcCsV|dkri}|dkrg}|��}|�d�r:|td�d�}|�dd�}t||||d�S)zNSimply create a tree fragment using the name of the test-case in parse errors.Nz	__main__.�.�_)�pipeline)�id�
startswithr1�replacer)r�code�pxdsrDrrrr�fragment]s
zCythonTest.fragmentcCst|�S)N)r%)rr#rrrr%iszCythonTest.treetypesc
CsPy|�|�d|�Wn2|k
rJ}z|�t||��|Sd}~XYnXdS)z�Calls "func" and fails if it doesn't raise the right exception
        (any exception by default). Also returns the exception in question.
        z Expected an exception of type %rN)�failZ
assertTruer+)r�func�exc_type�errr�should_faillszCythonTest.should_failc
Cs<y|�Stk
r6}z|�t|��Wdd}~XYnXdS)z�Calls func and succeeds if and only if no exception is raised
        (i.e. converts exception raising into a failed testcase). Returns
        the return value of func.N)�	ExceptionrK�str)rrL�excrrr�should_not_failwszCythonTest.should_not_fail)NN)rrrr)r*r5r:r;r>rArJr%rPrOrSrrrrr&/s
r&c@seZdZdZddd�ZdS)�
TransformTesta.
    Utility base class for transform unit tests. It is based around constructing
    test trees (either explicitly or by parsing a Cython code string); running
    the transform, serialize it using a customized Cython serializer (with
    special markup for nodes that cannot be represented in Cython),
    and do a string-comparison line-by-line of the result.

    To create a test case:
     - Call run_pipeline. The pipeline should at least contain the transform you
       are testing; pyx should be either a string (passed to the parser to
       create a post-parse tree) or a node representing input to pipeline.
       The result will be a transformed result.

     - Check that the tree is correct. If wanted, assertCode can be used, which
       takes a code string as expected, and a ModuleNode in result_tree
       (it serializes the ModuleNode to a string and compares line-by-line).

    All code strings are first stripped for whitespace lines and then common
    indentation.

    Plans: One could have a pxd dictionary parameter to run_pipeline.
    NcCs4|dkri}|�||�j}x|D]}||�}q W|S)N)rJr#)rrDZpyxrIr8�Trrr�run_pipeline�s
zTransformTest.run_pipeline)N)rrr�__doc__rVrrrrrT�srTc@seZdZdd�ZejZdS)�TreeAssertVisitorcCs�|j}d|krBx2|dD]&}t�||�dkrt�|jd|�qWd|kr~x2|dD]&}t�||�dk	rTt�|jd|�qTW|�|�|S)NZtest_assert_path_existsz+Expected path '%s' not found in result treeZtest_fail_if_path_existsz)Unexpected path '%s' found in result tree)�
directivesr
r?r�error�posr)rrrYr@rrr�visit_CompilerDirectivesNode�s
z.TreeAssertVisitor.visit_CompilerDirectivesNodeN)rrrr\r	Zrecurse_to_childrenrrrrrrX�srXc	Cs8|dkrt��}g}d}t|�}z|��}Wd|��X~z�x�|D]�}|dd�dkr�|���d����dtjj	�}tj�
||�}tj�tj�|��s�t�
tj�|��|dk	r�|d}}|��t|d�}qB|dk	r�|�|�qB|��rB|���d�sB|��dkrB|�|�qBWWd|dk	�r(|��X|d�
|�fS)N�z#####�#�/r$)z"""z'''r!)�tempfileZmkdtemp�open�	readlines�close�striprG�osr@�sepr"�exists�dirname�makedirsr6�lstriprFr)	Z	tree_file�dir�headerZcur_file�fr7r=�filenamer@rrr�unpack_source_tree�s8




ro)N)Z
__future__rreZunittestr`ZCompilerrrZCompiler.TreeFragmentrrZCompiler.Visitorrr	r
rr%ZTestCaser&rTrXrorrrr�<module>s
R"