Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_tools/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_tools/__pycache__/test_pindent.cpython-35.opt-1.pyc



��Yf�!�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZmZe�Gdd�dej
�Zedkr�ej�dS)	z4Tests for the pindent script in the Tools directory.�N)�support)�assert_python_ok)�
scriptsdir�skip_if_missingc@s�eZdZejjed�Zdd�Zdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�PindentTestsz
pindent.pycCsLt|��9}t|��#}|j|j�|j��WdQRXWdQRXdS)N)�open�assertEqual�	readlines)�selfZfn1Zfn2�f1�f2�r
�A/opt/alt/python35/lib64/python3.5/test/test_tools/test_pindent.py�assertFileEqualszPindentTests.assertFileEqualc	Gsgtjtj|jf|dtjdtjdd��}|j|�\}}WdQRX|j|�|S)N�stdin�stdoutZuniversal_newlinesT)�
subprocess�Popen�sys�
executable�script�PIPEZcommunicateZassertIsNone)r
�source�args�proc�out�errr
r
r�pindents
zPindentTests.pindentcCs$djdd�|j�D��dS)N�
css|]}|j�VqdS)N)�lstrip)�.0�liner
r
r�	<genexpr>!sz+PindentTests.lstriplines.<locals>.<genexpr>)�join�
splitlines)r
�datar
r
r�lstriplines szPindentTests.lstriplinescJCs�d|_tj���}tjj|d�}t|j��}|j�}WdQRXt|d��}|j	|�WdQRXt
|jd|�\}}}|j|d�|j|d�|d}|jtjj
|��t|��}|j|j�|�WdQRXt|��}|j�}	WdQRXt|	dd�|j|j|	d�|�|j|j|d�|	�t
|jd|�\}}}|j|d�|j|d�t|��}|j|j�|	�WdQRXt|��}|j|j�|�WdQRX|j|�}
t|d��}|j	|
�WdQRXt
|jd|�\}}}|j|d�|j|d�t|��}|j|j�|
�WdQRXt|��}|j�}WdQRXt|dd�|j|j|
d�|�WdQRXdS)	Nz_test.py�wz-d��~�execz-cz-r)ZmaxDiffrZtemp_dir�os�pathr#rr�read�writerrZ
assertTrue�exists�compilerr&)r
Z	directoryZ	data_path�f�closed�rcrrZbackup�clean�brokenZindentedr
r
r�
test_selftest#sL	
zPindentTests.test_selftestcCsp|j|j|d�|�|j|j|d�|�|j|�}|j|j|dddd�|�dS)Nz-cz-dz-rz-ez-s�4)rrr&)r
r4r2r5r
r
r�pindent_testNszPindentTests.pindent_testcCs2tjd�}tjd�}|j||�dS)Na:            if a:
                pass

            if a:
                pass
            else:
                pass

            if a:
                pass
            elif:
                pass
            else:
                pass

            while a:
                break

            while a:
                break
            else:
                pass

            for i in a:
                break

            for i in a:
                break
            else:
                pass

            try:
                pass
            finally:
                pass

            try:
                pass
            except TypeError:
                pass
            except ValueError:
                pass
            else:
                pass

            try:
                pass
            except TypeError:
                pass
            except ValueError:
                pass
            finally:
                pass

            with a:
                pass

            class A:
                pass

            def f():
                pass
            a`            if a:
                pass
            # end if

            if a:
                pass
            else:
                pass
            # end if

            if a:
                pass
            elif:
                pass
            else:
                pass
            # end if

            while a:
                break
            # end while

            while a:
                break
            else:
                pass
            # end while

            for i in a:
                break
            # end for

            for i in a:
                break
            else:
                pass
            # end for

            try:
                pass
            finally:
                pass
            # end try

            try:
                pass
            except TypeError:
                pass
            except ValueError:
                pass
            else:
                pass
            # end try

            try:
                pass
            except TypeError:
                pass
            except ValueError:
                pass
            finally:
                pass
            # end try

            with a:
                pass
            # end with

            class A:
                pass
            # end class A

            def f():
                pass
            # end def f
            )�textwrap�dedentr8)r
r4r2r
r
r�test_statementsTs
?	L	zPindentTests.test_statementscCs2tjd�}tjd�}|j||�dS)Nz�            def foobar(a, b):
                if a == b:
                    a = a+1
                elif a < b:
                    b = b-1
                    if b > a: a = a-1
                else:
                    print 'oops!'
            aJ            def foobar(a, b):
                if a == b:
                    a = a+1
                elif a < b:
                    b = b-1
                    if b > a: a = a-1
                    # end if
                else:
                    print 'oops!'
                # end if
            # end def foobar
            )r9r:r8)r
r4r2r
r
r�test_multilevel�s
			zPindentTests.test_multilevelcCstjd�}tjd�}|j|j|d�|�|j|j|d�|�|j|�}|j|j|dddd�|�tjd	�}tjd
�}|j|j|d�|�|j|j|d�|�|j|�}|j|j|d�|�dS)Nz\            if a:
                     if b:
                              pass
            z�            if a:
                     if b:
                              pass
                     # end if
            # end if
            z-cz-dz-rz-ez-s�9zD            if a:
            	if b:
            		pass
            zo            if a:
            	if b:
            		pass
            	# end if
            # end if
            )r9r:rrr&)r
r4r2r5r
r
r�test_preserve_indents�s 		%		z"PindentTests.test_preserve_indentscCsZtjd�}tjd�}|j|j|d�|�|j|j|d�|�dS)Nz�            class\
            \
             A:
               def            \
            f:
                  pass
            z�            class\
            \
             A:
               def            \
            f:
                  pass
               # end def f
            # end class A
            z-cz-d)r9r:rr)r
r4r2r
r
r�test_escaped_newline!s	
	z!PindentTests.test_escaped_newlinecCs2tjd�}tjd�}|j||�dS)Nz4            if a:

                pass
            zI            if a:

                pass
            # end if
            )r9r:r8)r
r4r2r
r
r�test_empty_line9s
		zPindentTests.test_empty_linecCs2tjd�}tjd�}|j||�dS)Nz#            if a: pass
            z8            if a: pass
            # end if
            )r9r:r8)r
r4r2r
r
r�test_onelineGs
		zPindentTests.test_onelineN)�__name__�
__module__�__qualname__r+r,r#rrrrr&r6r8r;r<r>r?r@rAr
r
r
rrs	+�"r�__main__)�__doc__r+rZunittestrr9ZtestrZtest.support.script_helperrZtest.test_toolsrrZTestCaserrB�mainr
r
r
r�<module>s�C