a ze5@sddlmZmZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z mZddddd d d ZGd d d ZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZdS))TestCasemock)rN)captured_stderrcaptured_stdout script_helperfindfileunlinkzCfruits = [ "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_expressionwrong_indentednannynag_errored error_freetab_space_errored_1tab_space_errored_2c@s&eZdZd ddZddZddZdS) TemporaryPyFileNcCs||_||_dSN) source_codedir)selfr directoryrF/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_tabnanny.py__init__BszTemporaryPyFile.__init__cCsNtjd|jddd}||jWdn1s60Y|j|_|jS)Nwz.pyF)modersuffixdelete)tempfileNamedTemporaryFilerwritername file_path)rfrrr __enter__Fs *zTemporaryPyFile.__enter__cCst|jdSr)rr!)rexc_type exc_value exc_tracebackrrr__exit__NszTemporaryPyFile.__exit__)rN)__name__ __module__ __qualname__rr#r'rrrrr?s rc@seZdZddZdS)TestFormatWitnessesc CsZgd}|D]H\}}|j||d"|t||Wdq 1sJ0Yq dS)N))ZTestzat tab sizes T, e, s, t)rz at tab size )tz at tab size t)z t zat tab sizes , , t, , )wordsexpected)subTest assertEqualtabnannyZformat_witnesses)rtestsr-r.rrrtest_format_witnessesUs z)TestFormatWitnesses.test_format_witnessesN)r(r)r*r3rrrrr+Rsr+c@seZdZddZdS) TestErrPrintc Csddgdfdgdfgddfgdfg}|D]v\}}|j||dPt}tj|Wdn1sh0Y|||Wdq*1s0Yq*dS) Nfirstsecondz first second zfirst )z1 2 3  )Z argumentsr.)r/rr1Zerrprintr0getvalue)rr2argsr.stderrrrr test_errprintfs   (zTestErrPrint.test_errprintN)r(r)r*r>rrrrr4csr4c@seZdZddZdS) TestNannyNagc Cs&tdddddddftdddddddfg}|D]\}}|}|}|}|j||dd  ||d|Wdn1s0Y|j||d d  ||d |Wdn1s0Y|j||d d  ||d |Wdq81s0Yq8dS)NrZfooZbar)linenomsglineZtestmsgZtestliner@) line_numberr.rA)rAr.rB)rBr.)r1NannyNagZ get_linenoZget_msgZget_liner/r0)rr2Znannyr.rDrArBrrrtest_all_methodsws&     ..zTestNannyNag.test_all_methodsN)r(r)r*rFrrrrr?vsr?c@sfeZdZddZdddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ dS) TestCheckcCs|ttdtjdt_dS)Nverboser)Z addCleanupsetattrr1rH)rrrrsetUpszTestCheck.setUprc Cszt@}t}t|Wdn1s.0YWdn1sL0Y||||||dSr)rrr1checkr0r;)rZ dir_or_fileouterrstdoutr=rrrverify_tabnanny_checksFzTestCheck.verify_tabnanny_checkcCs:ttd}||Wdn1s,0YdSNr r SOURCE_CODESrOrr!rrrtest_correct_fileszTestCheck.test_correct_filec Cs~t^}|dg}ttd|d}ttd|d}| }|}||fD]}||dqNdt_t@}t} t |Wdn1s0YWdn1s0Y| }|D]<} |j | d| | |Wdq1s0Yq| | dWdn1s00YWdn1sP0YWdn1sp0YdS)Nz: listing directory r rz: Clean bill of health. r7)rBr)rTemporaryDirectoryrrRappendr1rHrrrKr;r/assertInr0) rtmp_dirlinesZfile1Zfile2Z file1_pathZ file2_pathr!rNr=rBrrrtest_correct_directory_verboses   F,z(TestCheck.test_correct_directory_verbosec CsftJ}ttd|d||Wdn1s:0YWdn1sX0YdS)Nr rUrrVrrRrO)rrYrrrtest_correct_directorys z TestCheck.test_correct_directorycCsPttd0}d}|d|}|j||dWdn1sB0YdS)Nr Iunindent does not match any outer indentation level (, line 3) : Indentation Error: rMrQrr!rMrrrtest_when_wrong_indentedsz"TestCheck.test_when_wrong_indentedcCsPttd0}d}|d|}|j||dWdn1sB0YdS)Nr z(('EOF in multi-line statement', (7, 0)) z: Token Error: r`rQrarrrtest_when_tokenize_tokenerrorsz'TestCheck.test_when_tokenize_tokenerrorcCs^ttd>}|d}|d7}|d7}dt_|j||dWdn1sP0YdS)Nr z': *** Line 3: trouble in tab city! *** z%offending line: '\tprint("world")\n' z$indent not equal e.g. at tab size 1 r7rL)rrRr1rHrOrr!rLrrr test_when_nannynag_error_verboses  z*TestCheck.test_when_nannynag_error_verbosecCsHttd(}|d}|j||dWdn1s:0YdS)Nr z 3 '\tprint("world")\n' rdrQrerrrtest_when_nannynag_errors z"TestCheck.test_when_nannynag_errorcCs<d}|dtjdttjd|d}|j||ddS)Nz no_file.pyz: I/O Error: [Errno z] z: r:r`)errnoENOENTosstrerrorrO)rpathrMrrrtest_when_no_files zTestCheck.test_when_no_filec Cst}ttd|d}ttd|d}|T}|0}d}|d|}|j||dWdn1sj0YWdn1s0YWdn1s0YdS)Nr rUr r^r_r`r\)rrYZ error_fileZ code_fileZe_fileZc_filerMrrrtest_errored_directorys  z TestCheck.test_errored_directoryN)rr)r(r)r*rJrOrTr[r]rbrcrfrgrmrnrrrrrGs  rGc@s&eZdZedddZddZdS)TestProcessTokensztabnanny.NannyNagc CsvttdV}t|"}tt|jWdn1s>0Y||j Wdn1sh0YdSrP) rrRopenr1process_tokenstokenizegenerate_tokensreadlineZ assertFalseZcalled)rZ MockNannyNagr!r"rrrtest_with_correct_codes 0z(TestProcessTokens.test_with_correct_codec CsdD]}|j|dtt|z}t|R}t|j}|tj t |Wdn1sf0YWdn1s0YWdn1s0YWdq1s0YqdS)N)r r)key) r/rrRrprrrsrtZ assertRaisesr1rErq)rrvr!r"tokensrrrtest_with_errored_codes_samples s   z1TestProcessTokens.test_with_errored_codes_samplesN)r(r)r*rZpatchrurxrrrrros roc@sNeZdZddddddZddZdd Zd d Zd d ZddZddZ dS)TestCommandLinerF)rNr=partialc Gstjddg|R\}}}|d}|d}|r||f||ffD]X\}} | } |D]>} |j| | d|| | WdqZ1s0YqZqBn(||||||dS)Nz-mr1ascii)stdoutput)rZassert_python_okdecode splitlinesr/rXZassertListEqual) rrNr=rzr<_rLrMr|r}Z_outputZ_stdrrr validate_cmd"s   0zTestCommandLine.validate_cmdcCsPttd0}|d}|d7}|j||dWdn1sB0YdS)Nr r_zHunindent does not match any outer indentation level (, line 3)r=rrRr)rr!r=rrrtest_with_errored_file3s z&TestCommandLine.test_with_errored_filecCs:ttd}||Wdn1s,0YdSrPrrSrrrtest_with_error_free_file;sz)TestCommandLine.test_with_error_free_filecCs$td}d|d}|j|ddS)Nz tabnanny.pyzUsage: z [-v] file_or_directory ...r)rr)rrlr=rrrtest_command_usage@s z"TestCommandLine.test_command_usagecCsJttd*}|d}|jd||dWdn1s<0YdS)Nr r:z-q)rNr)rr!rNrrrtest_quiet_flagFs zTestCommandLine.test_quiet_flagcCsPttd0}td}|jd||ddWdn1sB0YdS)Nr $offending line: '\tprint("world")\n'z-vTrNrzrrRtextwrapdedentstriprrrlrNrrrtest_verbose_modeLs z!TestCommandLine.test_verbose_modecCsPttd0}td}|jd||ddWdn1sB0YdS)Nr rz-vvTrrrrrrtest_double_verbose_modeTs z(TestCommandLine.test_double_verbose_modeN) r(r)r*rrrrrrrrrrrrysry)Zunittestrrrhrjr1rrrrZ test.supportrrrrrrRrr+r4r?rGroryrrrrs, -p