Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_tabnanny.cpython-38.pyc

U

i�f�5�@s�dZddlmZmZddlmZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZmZdddd	d
dd�ZGd
d�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)zfTesting `tabnanny` module.

Glossary:
    * errored    : Whitespace related problems present in file.
�)�TestCase�mock)rN)�captured_stderr�captured_stdout�
script_helper�findfile�unlinkzCfruits = [
    "Apple",
    "Orange",
    "Banana",

print(fruits)
zLif True:
    print("hello")
  print("world")
else:
    print("else called")
zIif True:
 	print("hello")
	print("world")
else:
    print("else called")
zNif True:
    print("hello")
    print("world")
else:
    print("else called")
zGdef my_func():
	  print("hello world")
	  if True:
		print("If called")zLdef my_func():
		print("Hello world")
		if True:
	        print("If called"))�incomplete_expression�wrong_indented�nannynag_errored�
error_free�tab_space_errored_1�tab_space_errored_2c@s*eZdZdZd
dd�Zdd�Zdd	�ZdS)�TemporaryPyFilez+Create a temporary python source code file.�NcCs||_||_dS�N)�source_code�dir)�selfr�	directory�r�7/opt/alt/python38/lib64/python3.8/test/test_tabnanny.py�__init__BszTemporaryPyFile.__init__c	Cs:tjd|jddd��}|�|j�W5QRX|j|_|jS)N�wz.pyF)�moder�suffix�delete)�tempfileZNamedTemporaryFiler�writer�name�	file_path)r�frrr�	__enter__Fs�zTemporaryPyFile.__enter__cCst|j�dSr)rr )r�exc_type�	exc_value�
exc_tracebackrrr�__exit__NszTemporaryPyFile.__exit__)rN)�__name__�
__module__�__qualname__�__doc__rr"r&rrrrr?s
rc@seZdZdZdd�ZdS)�TestFormatWitnessesz&Testing `tabnanny.format_witnesses()`.c
CsJddddg}|D]4\}}|j||d��|�t�|�|�W5QRXqdS)z;Asserting formatter result by giving various input samples.)ZTestzat tab sizes T, e, s, t)rzat tab size )�tz
at tab size t)z  t  zat tab sizes  ,  , t,  ,  )�words�expectedN)�subTest�assertEqual�tabnannyZformat_witnesses)r�testsr-r.rrr�test_format_witnessesUs�z)TestFormatWitnesses.test_format_witnessesN)r'r(r)r*r3rrrrr+Rsr+c@seZdZdZdd�ZdS)�TestErrPrintzTesting `tabnanny.errprint()`.cCs�ddgdfdgdfdddgdfgd	fg}|D]N\}}|j||d
��2t��}tj|�W5QRX|�|��|�W5QRXq,dS)zBAsserting result of `tabnanny.errprint()` by giving sample inputs.�first�secondz
first second
zfirst
���z1 2 3
�
)Z	argumentsr.N)r/rr1Zerrprintr0�getvalue)rr2�argsr.�stderrrrr�
test_errprintfs
�zTestErrPrint.test_errprintN)r'r(r)r*r>rrrrr4csr4c@seZdZdd�ZdS)�TestNannyNagc
Cs�t�ddd�dddd�ft�ddd�dddd�fg}|D]�\}}|��}|��}|��}|j||dd	��|�|d|�W5QRX|j||d
d��|�|d
|�W5QRX|j||dd
��|�|d|�W5QRXq8dS)z5Asserting behaviour of `tabnanny.NannyNag` exception.rZfooZbar)�lineno�msg�line�ZtestmsgZtestliner@)�line_numberr.rA)rAr.rB)rBr.N)r1�NannyNagZ
get_linenoZget_msgZget_liner/r0)rr2Znannyr.rDrArBrrr�test_all_methodsws(
�
��
�zTestNannyNag.test_all_methodsN)r'r(r)rFrrrrr?vsr?c@sjeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�	TestCheckzTesting tabnanny.check().cCs|�ttdtj�dt_dS)N�verboser)Z
addCleanup�setattrr1rH)rrrr�setUp�szTestCheck.setUprc
CsRt��"}t��}t�|�W5QRXW5QRX|�|��|�|�|��|�dS)aRCommon verification for tabnanny.check().

        Use this method to assert expected values of `stdout` and `stderr` after
        running tabnanny.check() on given `dir` or `file` path. Because
        tabnanny.check() captures exceptions and writes to `stdout` and
        `stderr`, asserting standard outputs is the only way.
        N)rrr1�checkr0r;)rZdir_or_file�out�err�stdoutr=rrr�verify_tabnanny_check�szTestCheck.verify_tabnanny_checkc	Cs&ttd��}|�|�W5QRXdS)z-A python source code file without any errors.rN�r�SOURCE_CODESrO�rr rrr�test_correct_file�szTestCheck.test_correct_filec
Cs�t����}|�d�g}ttd|d�}ttd|d�}|��}|��}||fD]}|�|�d��qJdt_t��"}t��}	t�	|�W5QRXW5QRX|�
�}|D](}
|j|
d��|�|
|�W5QRXq�|�
|	�
�d�W5QRXW5QRXW5QRXdS)	aDirectory containing few error free python source code files.

        Because order of files returned by `os.lsdir()` is not fixed, verify the
        existence of each output lines at `stdout` using `in` operator.
        `verbose` mode of `tabnanny.verbose` asserts `stdout`.
        z: listing directory
r�rz: Clean bill of health.
r7)rBrN)r�TemporaryDirectoryrrQ�appendr1rHrrrKr;r/�assertInr0)r�tmp_dir�linesZfile1Zfile2Z
file1_pathZ
file2_pathr rNr=rBrrr�test_correct_directory_verbose�s
z(TestCheck.test_correct_directory_verbosec
Cs>t���,}ttd|d��|�|�W5QRXW5QRXdS)zADirectory which contains few error free python source code files.rrTN�rrUrrQrO)rrXrrr�test_correct_directory�s
z TestCheck.test_correct_directoryc	Cs<ttd��&}d}|�d|��}|j||d�W5QRXdS)zBA python source code file eligible for raising `IndentationError`.r
�Iunindent does not match any outer indentation level (<tokenize>, line 3)
�: Indentation Error: �rMNrP�rr rMrrr�test_when_wrong_indented�sz"TestCheck.test_when_wrong_indentedc	Cs<ttd��&}d}|�d|��}|j||d�W5QRXdS)zEA python source code file eligible for raising 'tokenize.TokenError'.r	z(('EOF in multi-line statement', (7, 0))
z: Token Error: r_NrPr`rrr�test_when_tokenize_tokenerror�sz'TestCheck.test_when_tokenize_tokenerrorc	CsJttd��4}|�d�}|d7}|d7}dt_|j||d�W5QRXdS)z�A python source code file eligible for raising `tabnanny.NannyNag`.

        Tests will assert `stdout` after activating `tabnanny.verbose` mode.
        rz': *** Line 3: trouble in tab city! ***
z%offending line: '\tprint("world")\n'
z$indent not equal e.g. at tab size 1
r7�rLN)rrQr1rHrO�rr rLrrr� test_when_nannynag_error_verbose�s
z*TestCheck.test_when_nannynag_error_verbosec	Cs4ttd��}|�d�}|j||d�W5QRXdS)zCA python source code file eligible for raising `tabnanny.NannyNag`.rz 3 '\tprint("world")\n'
rcNrPrdrrr�test_when_nannynag_error�s
z"TestCheck.test_when_nannynag_errorcCs<d}|�dtj�dt�tj��d|�d�}|j||d�dS)z6A python file which does not exist actually in system.z
no_file.pyz: I/O Error: [Errno z] z: r:r_N)�errnoZENOENT�os�strerrorrO)r�pathrMrrr�test_when_no_file�s&zTestCheck.test_when_no_filecCsxt���f}ttd|d�}ttd|d�}|�6}|�&}d}|�d|��}|j||d�W5QRXW5QRXW5QRXdS)z?Directory containing wrongly indented python source code files.r
rTrr]r^r_Nr[)rrXZ
error_fileZ	code_fileZe_fileZc_filerMrrr�test_errored_directory�s
��z TestCheck.test_errored_directoryN)rr)r'r(r)r*rJrOrSrZr\rarbrerfrkrlrrrrrG�s


rGc@s*eZdZdZe�d�dd��Zdd�ZdS)�TestProcessTokensz$Testing `tabnanny.process_tokens()`.ztabnanny.NannyNagc
CsNttd��8}t|��}t�t�|j��W5QRX|�|j	�W5QRXdS)z=A python source code without any whitespace related problems.rN)
rrQ�openr1�process_tokens�tokenize�generate_tokens�readlineZassertFalseZcalled)rZMockNannyNagr r!rrr�test_with_correct_codes
z(TestProcessTokens.test_with_correct_codec
Cs�dD]v}|j|d��`tt|��H}t|��4}t�|j�}|�tj	��t�
|�W5QRXW5QRXW5QRXW5QRXqdS)z>A python source code with whitespace related sampled problems.)r
r)�keyN)r/rrQrnrprqrrZassertRaisesr1rEro)rrtr r!�tokensrrr�test_with_errored_codes_samples
s	
z1TestProcessTokens.test_with_errored_codes_samplesN)r'r(r)r*rZpatchrsrvrrrrrms
rmc@sReZdZdZdddd�dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dS)�TestCommandLinez+Tests command line interface of `tabnanny`.rF)rNr=�partialcGs�tjd|��\}}}|�d�}|�d�}|r�||f||ffD]D\}}	|	��}
|��D]*}|j||
d��|�||
�W5QRXqTq<n(|�|��|���|�|��|���dS)zBCommon function to assert the behaviour of command line interface.�-mr1�ascii)�std�outputN)ryr1)rZassert_python_ok�decode�
splitlinesr/rWZassertListEqual)rrNr=rxr<�_rLrMr{r|Z_outputZ_stdrrr�validate_cmd"s

zTestCommandLine.validate_cmdc	Cs<ttd��&}|�d�}|d7}|j||d�W5QRXdS)z8Should displays error when errored python file is given.r
r^zHunindent does not match any outer indentation level (<tokenize>, line 3)�r=N�rrQr�)rr r=rrr�test_with_errored_file3s
z&TestCommandLine.test_with_errored_filec	Cs&ttd��}|�|�W5QRXdS)zAShould not display anything if python file is correctly indented.rNr�rRrrr�test_with_error_free_file;sz)TestCommandLine.test_with_error_free_filecCs$td�}d|�d�}|j|d�dS)z%Should display usage on no arguments.ztabnanny.pyzUsage: z [-v] file_or_directory ...r�N)rr�)rrjr=rrr�test_command_usage@sz"TestCommandLine.test_command_usagec	Cs6ttd�� }|�d�}|jd||d�W5QRXdS)z*Should display less when quite mode is on.rr:z-q)rNNr�)rr rNrrr�test_quiet_flagFs
zTestCommandLine.test_quiet_flagc	Cs<ttd��&}t�d���}|jd||dd�W5QRXdS)z<Should display more error information if verbose mode is on.r�$offending line: '\tprint("world")\n'z-vT�rNrxN�rrQ�textwrap�dedent�stripr��rrjrNrrr�test_verbose_modeLs
�z!TestCommandLine.test_verbose_modec	Cs<ttd��&}t�d���}|jd||dd�W5QRXdS)zBShould display detailed error information if double verbose is on.rr�z-vvTr�Nr�r�rrr�test_double_verbose_modeTs
�z(TestCommandLine.test_double_verbose_modeN)r'r(r)r*r�r�r�r�r�r�r�rrrrrwsrw)r*Zunittestrrrgrhr1rprr�Ztest.supportrrrrrrQrr+r4r?rGrmrwrrrr�<module>s.�-p