(r$9SrSSKJrJr SSKrSSKrSSKrSSKrSSKrSSK r SSK J r J r J r Jr SSKJr SSSS S S S .r"S S5r"SS\5r"SS\5r"SS\5r"SS\5r"SS\5r"SS\5rg)zfTesting `tabnanny` module. Glossary: * errored : Whitespace related problems present in file. )TestCasemockN)captured_stderrcaptured_stdout script_helperfindfile)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_expressionwrong_indentednannynag_errored error_freetab_space_errored_1tab_space_errored_2c.\rSrSrSrSSjrSrSrSrg) TemporaryPyFile?z+Create a temporary python source code file.NcXlX lgN) source_codedir)selfr directorys 9/opt/alt/python313/lib64/python3.13/test/test_tabnanny.py__init__TemporaryPyFile.__init__Bs &c[R"SURSSS9nURUR5 SSS5 WR UlUR $!,(df  N+=f)Nwz.pyF)modersuffixdelete)tempfileNamedTemporaryFilerwritername file_path)rfs r __enter__TemporaryPyFile.__enter__FsY  ( ($((5  GGD$$ % ~~   s A## A1c.[UR5 gr)r r&)rexc_type exc_value exc_tracebacks r__exit__TemporaryPyFile.__exit__Nst~~r)rr&r)N) __name__ __module__ __qualname____firstlineno____doc__rr(r.__static_attributes__rrrr?s5rrc\rSrSrSrSrSrg)TestFormatWitnessesRz&Testing `tabnanny.format_witnesses()`.c/SQnUHCup#URX#S9 UR[R"U5U5 SSS5 ME g!,(df  MW=f)z;Asserting formatter result by giving various input samples.))Testzat tab sizes T, e, s, t)r0z at tab size )tz at tab size t)z t zat tab sizes , , t, , )wordsexpectedN)subTest assertEqualtabnannyformat_witnesses)rtestsr>r?s rtest_format_witnesses)TestFormatWitnesses.test_format_witnessesUsO  %OEE=  !:!:5!A8L>= %==s 'A A r7N)r1r2r3r4r5rEr6r7rrr9r9Rs 0 Mrr9c\rSrSrSrSrSrg) TestErrPrintczTesting `tabnanny.errprint()`.c SS/S4S/S4/SQS4/S4/nUHup#URX#S9 UR[5 [5n[R "U6 S S S 5 UR WR5U5 S S S 5 S S S 5 M g !,(df  NC=f!,(df  N,=f!,(df  M=f) zBAsserting result of `tabnanny.errprint()` by giving sample inputs.firstsecondz first second zfirst )z1 2 3  ) argumentsr?N)r@ assertRaises SystemExitrrBerrprintrAgetvalue)rrDargsr?stderrs r test_errprintTestErrPrint.test_errprintfsx "2 3Y "  " J  $ND@&&z2(*f ))40+$$V__%6B3A@$+*32A@s;B> B- B (B-B> B* &B-- B; 7B>> C r7N)r1r2r3r4r5rXr6r7rrrHrHcs (CrrHc\rSrSrSrSrg) TestNannyNagwcz[R"SSS5SSSS.4[R"SSS5SSSS.4/nUHup#UR5nUR5nUR 5nUR XCSS 9 UR USU5 S S S 5 UR XSS S 9 UR US U5 S S S 5 UR XcS S9 UR US U5 S S S 5 M g !,(df  Ns=f!,(df  NT=f!,(df  M=f)z5Asserting behaviour of `tabnanny.NannyNag` exception.rfoobar)linenomsglinetestmsgtestliner`) line_numberr?Nra)rar?rb)rbr?)rBNannyNag get_linenoget_msgget_liner@rA)rrDnannyr?rfrarbs rtest_all_methodsTestNannyNag.test_all_methodsxs2!!!UE2UE:  !!!Y ;Y C    %OE**,K--/C>>#D'82D  (!3[A#@  %#6A462BC  &!148DC %A@CCs$D 6D&D+ D  D( + D: r7N)r1r2r3r4rlr6r7rrr[r[ws9rr[c^\rSrSrSrSrSSjrSrSrSr Sr S r S r S r S rS rSrg) TestCheckzTesting tabnanny.check().cnUR[[S[R5 S[lg)Nverboser) addCleanupsetattrrBrr)rs rsetUpTestCheck.setUps" 9h6F6FGrc@[5n[5n[R"U5 SSS5 SSS5 UR WR 5U5 UR WR 5U5 g!,(df  NW=f!,(df  N`=f)a*Common 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)rrrBcheckrArU)r dir_or_fileouterrstdoutrWs rverify_tabnanny_checkTestCheck.verify_tabnanny_checkse &/*;v NN; '+<  *C0 *C0+<*;  s! BA>B> B B Bc~[[S5nURU5 SSS5 g!,(df  g=f)z-A python source code file without any errors.r Nr SOURCE_CODESr}rr&s rtest_correct_fileTestCheck.test_correct_files+ \,7 8I  & &y 19 8 8. <c [R"5nU<S3/n[[SUS9n[[SUS9nUoTnXV4HnUR U<S35 M S[ l[5n[5n [ R"U5 SSS5 SSS5 WR5nUH,n URU S9 URX5 SSS5 M. URW R5S5 SSS5 SSS5 SSS5 g!,(df  N=f!,(df  N=f!,(df  M=f!,(df  NS=f!,(df  N\=f!,(df  g=f) zDirectory 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. rMN)rbr0)r"TemporaryDirectoryrrappendrBrrrrrxrUr@assertInrA) rtmp_dirlinesfile1file2 file1_path file2_pathr&r|rWrbs rtest_correct_directory_verbose(TestCheck.test_correct_directory_verboses, ( ( *g{"78:E#L$>'RE#L$>'RE*ez",!9ILLI=0I!JK":$% $&&/2CvNN7+3D&*!D40 d310"  !2B7', + *3D2C&&10',e + *s,E<E+5E9 D7 D& D7 #,EE !,E E+E<& D40D7 7 E E EE E( $E++ E9 5E<< F c[R"5n[[SUS9 UR U5 SSS5 SSS5 g!,(df  N=f!,(df  g=f)zADirectory which contains few error free python source code files.r rN)r"rrrr})rrs rtest_correct_directory TestCheck.test_correct_directorysK  ( ( *g l!;wO**73P+ *OO+ *s!AA A A A A*c[[S5nSnU<SU3nUR[5 UR XS9 SSS5 SSS5 g!,(df  N=f!,(df  g=f)zBA python source code file eligible for raising `IndentationError`.r Iunindent does not match any outer indentation level (, line 3) : Indentation Error: r{NrrrRrSr}rr&r{s rtest_when_wrong_indented"TestCheck.test_when_wrong_indentedsh \*:; < *CM!6se/ = </. = <" A%AA% A" A%% A3c[[S5nSnU<SU3nUR[5 UR XS9 SSS5 SSS5 g!,(df  N=f!,(df  g=f)zEA python source code file eligible for raising 'tokenize.TokenError'.r z(('EOF in multi-line statement', (7, 0)) z: Token Error: rNrrs rtest_when_tokenize_tokenerror'TestCheck.test_when_tokenize_tokenerrorsg \*AB Cy=CM6C"":.**9*>/D C/.D Crc[[S5nU<S3nUS- nUS- nS[lUR XS9 SSS5 g!,(df  g=f)zA python source code file eligible for raising `tabnanny.NannyNag`. Tests will assert `stdout` after activating `tabnanny.verbose` mode. r z': *** Line 3: trouble in tab city! *** z#offending line: '\tprint("world")' z3inconsistent use of tabs and spaces in indentation rMrzN)rrrBrrr}rr&rzs r test_when_nannynag_error_verbose*TestCheck.test_when_nannynag_error_verboses\ \*<= >)M!IJC < >s +A Ac[[S5nUS3nURXS9 SSS5 g!,(df  g=f)zCA python source code file eligible for raising `tabnanny.NannyNag`.r z 3 '\tprint("world")' rNrrs rtest_when_nannynag_error"TestCheck.test_when_nannynag_errors< \*<= >)K9:C  & &y & :? > >s1 ?cSnU<S[RS[R"[R5SU<S3nUR [ 5 UR XS9 SSS5 g!,(df  g=f)z6A python file which does not exist actually in system.z no_file.pyz: I/O Error: [Errno z] z: rPrN)errnoENOENTosstrerrorrRrSr})rpathr{s rtest_when_no_fileTestCheck.test_when_no_filesf-ell^2U\\*+2dXR9   z *  & &t & 5+ * *s A11 A?c [R"5n[[SUS9n[[SUS9nUoCnSnU<SU3nUR [ 5 UR XS9 SSS5 SSS5 SSS5 SSS5 g!,(df  N'=f!,(df  N0=f!,(df  N9=f!,(df  g=f)z?Directory containing wrongly indented python source code files.r rr rrrN)r"rrrrRrSr})rr error_file code_filee_filec_filer{s rtest_errored_directory TestCheck.test_errored_directorys  ( ( *g(-.'J(\*gIvyF6 "7u=&&z2..w.@3 (1+ *32 (1y+ *sQ%CB0 BB -B5B0=C B B B- )B00 B> :C Cr7N)r0r0)r1r2r3r4r5rur}rrrrrrrrrr6r7rrroros=# 12 804 ?? ;; 6ArrocN\rSrSrSr\R "S5S5rSrSr g)TestProcessTokensiz$Testing `tabnanny.process_tokens()`.ztabnanny.NannyNagcD[[S5n[U5n[R"[ R "UR55 SSS5 URUR5 SSS5 g!,(df  N2=f!,(df  g=f)z=A python source code without any whitespace related problems.r N) rropenrBprocess_tokenstokenizegenerate_tokensreadline assertFalsecalled)r MockNannyNagr&r's rtest_with_correct_code(TestProcessTokens.test_with_correct_code si\,7 8IiA''(@(@(LM!   \00 19 8 9 8s" B5B#B B B Bc SHnURUS9 [[U5n[U5n[R "UR 5nUR[R5 [R"U5 SSS5 SSS5 SSS5 SSS5 M g!,(df  N+=f!,(df  N4=f!,(df  N==f!,(df  M=f)z>A python source code with whitespace related sampled problems.)rr)keyN) r@rrrrrrrRrBrgr)rrr&r'tokenss rtest_with_errored_codes_samples1TestProcessTokens.test_with_errored_codes_samplessBC#&$\#%679iA!)!9!9!**!E!..x/@/@A$33F;B)8'&B BA)87'&sRC# CAC 4B0 C CC#0 B>:C  C C C C## C2 r7N) r1r2r3r4r5rpatchrrr6r7rrrrs&. ZZ#$2%2  !163D3D3F G  !163D3D3F G @?s /D// D> c[[S5nU<S3nUS- nURXSS9 SSS5 g!,(df  g=f)z8Should displays error when errored python file is given.r rzFunindent does not match any outer indentation level (, line 3)TrWrNrrr)rr&rWs rtest_with_errored_file&TestCommandLine.test_with_errored_file;sM \*:; < " %:;F - .F   it  L = < )!{"%F   dI  =? > >s 2 Ac[[S5n[R"S5R 5nUR SXSS9 SSS5 g!,(df  g=f)z$__7eg    dD  F ? > > 6A A c[[S5n[R"S5R 5nUR SXSS9 SSS5 g!,(df  g=f)zBShould display detailed error information if double verbose is on.r rz-vvTrNrrs rtest_double_verbose_mode(TestCommandLine.test_double_verbose_mode\sP \*<= >$__7eg    eT$  G ? > >rr7N) r1r2r3r4r5rrrrrrrr6r7rrrr$s65)+BV[H(M) > > GHrr)r5unittestrrrrrBrr"r test.supportrrrrtest.support.os_helperr rrr9rHr[rorrr7rrrs $ $$)   % % % !  'K* Z&M(M"C8C(9896qAqAh<<<>Hh>Hr