Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/Cython/__pycache__/TestUtils.cpython-35.opt-1.pyc



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�S)�NodeTypeWritercs)tt|�j�d|_g|_dS)Nr)�superr�__init__�_indents�result)�self)�	__class__��C/opt/alt/python35/lib64/python3.5/site-packages/Cython/TestUtils.pyr
s	zNodeTypeWriter.__init__cCs�|jsd}n>|jd}|ddk	rFd|dd�}n
|d}|jjd|jd||jjf�|jd7_|j|�|jd8_dS)	Nz(root)r�z%s[%d]�z  z%s: %s���)Zaccess_pathr�appendrr�__name__�
visitchildren)r�node�nameZtiprrr�
visit_Nodes		


zNodeTypeWriter.visit_Node)r�
__module__�__qualname__r
rrr)rrrsrcCs4t�}|j|�djdg|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@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dddd�Z
dd�Zedd�Z
dd�ZdS)�
CythonTestcCs,tj|_tj|_dt_t_dS)N)r�listing_file�	echo_file)rrrr�setUp1szCythonTest.setUpcCs|jt_|jt_dS)N)r&rr')rrrr�tearDown6szCythonTest.tearDowncCs�t|t�s|jd�}t|t�s<|jd�}xItt||��D]2\}\}}|j||d|||f�qRW|jt|�t|�ddj|�dj|�f�dS)zHChecks that the given strings or lists of strings are equal line by linerzLine %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.assertLinescCs t�}|j|�|jjS)N)r�writer�lines)r�tree�writerrrr�codeToLinesFs	
zCythonTest.codeToLinescCsdj|j|��S)Nr)r!r9)rr7rrr�codeToStringKszCythonTest.codeToStringcCs�|j|�}t|jd��}xItt||��D]2\}\}}|j||d|||f�q:W|jt|�t|�ddj|�|f�dS)NrzLine %d:
Got: %s
Exp: %sz%Unmatched lines. Got:
%s
Expected:
%s)r9rr,r-r.r/r0r!)rr1�result_treeZresult_linesZexpected_linesr2�liner3rrr�
assertCodeNs(zCythonTest.assertCodecCs'|jtj||�dd|�dS)Nz"Path '%s' not found in result tree)ZassertNotEqualr
�
find_first)r�pathr;rrr�assertNodeExistsYszCythonTest.assertNodeExistsNcCs}|dkri}|dkr$g}|j�}|jd�rU|td�d�}|jdd�}t|||d|�S)zNSimply create a tree fragment using the name of the test-case in parse errors.Nz	__main__.�.�_�pipeline)�id�
startswithr0�replacer)r�code�pxdsrCrrrr�fragment]szCythonTest.fragmentcCs
t|�S)N)r$)rr"rrrr$iszCythonTest.treetypescCsby|�|jd|�Wn?|k
r]}z|jt||��|SWYdd}~XnXdS)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_failcCsJy|�SWn8tk
rE}z|jt|��WYdd}~XnXdS)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)�	ExceptionrJ�str)rrK�excrrr�should_not_failwszCythonTest.should_not_fail)rrrr(r)r4r9r:r=r@rIr$rOrNrRrrrrr%/sr%c@s%eZdZdZddd�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.
    NcCsH|dkri}|j||�j}x|D]}||�}q.W|S)N)rIr")rrCZpyxrHr7�Trrr�run_pipeline�s
zTransformTest.run_pipeline)rrr�__doc__rUrrrrrS�srSc@s%eZdZdd�ZejZdS)�TreeAssertVisitorcCs�|j}d|krYxA|dD]5}tj||�dkr tj|jd|�q Wd|kr�xA|dD]5}tj||�dk	rptj|jd|�qpW|j|�|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)rrrXr?rrr�visit_CompilerDirectivesNode�s	
z.TreeAssertVisitor.visit_CompilerDirectivesNodeN)rrrr[r	Zrecurse_to_childrenrrrrrrW�srWc	Cs�|dkrtj�}g}d}t|�}z|j�}Wd|j�X~z6x/|D]'}|dd�dkr%|j�jd�j�jdtjj	�}tjj
||�}tjjtjj|��s�tj
tjj|��|dk	r|d}}|j�t|d�}q[|dk	rA|j|�q[|j�r[|j�jd�r[|j�d	kr[|j|�q[WWd|dk	r�|j�X|dj
|�fS)
N�z#####�#�/r#�"""�'''r )r_r`)�tempfileZmkdtemp�open�	readlines�close�striprF�osr?�sepr!�exists�dirname�makedirsr5�lstriprEr)	Z	tree_file�dir�headerZcur_file�fr6r<�filenamer?rrr�unpack_source_tree�s8
-

"rp)Z
__future__rrfZunittestraZCompilerrrZCompiler.TreeFragmentrrZCompiler.Visitorrr	r
rr$ZTestCaser%rSrWrprrrr�<module>s
R"