bg@ddlmZddlZddlmZmZddlZddlZddlZddlm Z ddl m Z  ddl Z ddl mZdZn #e$rdZYnwxYwed ZGd d ejZdS) )contextmanagerN)BytesIOStringIO)mock)Parser)peekableTFc#Ktjddkrtt}}ntt}}tjtj}} ||ct_t_tjtjfV||ct_t_dS#||ct_t_wxYw)Nr)sys version_inforrstdoutstderr)new_outnew_errold_outold_errs f/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/tap/tests/test_parser.pycaptured_outputrs Q"99gii#::xzzz3:WG2!(' CJj#*$$$$!(' CJJJ' CJ1111s +3B99CceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZejde ddZ!dS) TestParserzTests for tap.parser.Parserct}|d}|d|j||j||jdudS)zThe parser extracts an ok line.z!ok - This is a passing test line.testN)r parse_line assertEqualcategory assertTrueoknumberselfparserlines r test_finds_okzTestParser.test_finds_ok%sj  !DEE ///      t+,,,,,ct}|d}|d|j|d|jdS)z"The parser extracts a test number.zok 42 is the magic number.r*N)rrrrrrs rtest_finds_numberzTestParser.test_finds_number/sU  !=>> /// T[)))))r$ct}|d}|d|j|d|jdS)Nzok 42 A passing test.rzA passing test.rrrr descriptionrs rtest_finds_descriptionz!TestParser.test_finds_description8sW  !899 /// *D,<=====r$ct}|d}|d|j|d|jdS)Nz+ok A description # Not part of description.rz A descriptionr)rs r"test_after_hash_is_not_descriptionz-TestParser.test_after_hash_is_not_description@sV  !NOO /// $*:;;;;;r$ct}|d}|d|j||jdS)Nz ok A description # TODO Not doner)rrrrrtodors rtest_finds_todozTestParser.test_finds_todoHsQ  !CDD ///  """""r$ct}|d}|d|j||jdS)Nzok A description # SKIP for nowrrrrrrskiprs rtest_finds_skipzTestParser.test_finds_skipPsQ  !BCC ///  """""r$c.t}|d}|d|j||j||jdu|d|jj dS)z"The parser extracts a not ok line.z%not ok - This is a failing test line.rN) rrrr assertFalserrr directivetextrs rtest_finds_not_okzTestParser.test_finds_not_okXs  !HII /// !!!  t+,,, T^011111r$cht}d}||}|j}|d|j|d|j||j||j |d|j dS)zThe parser extracts a directivez/not ok - This line fails # TODO not implementedrzTODO not implementedznot implementedN) rrr8rrr9r7r3rr/reason)r r! test_liner"r8s rtest_finds_directivezTestParser.test_finds_directivecsE   ++N  /// /@@@ (((  ''' *I,<=====r$ct}|d}|d|jdS)z*The parser returns an unrecognizable line.z%This is not a valid TAP line. # srslyunknownNrrrrrs rtest_unrecognizable_linez#TestParser.test_unrecognizable_lineqs=  !HII DM22222r$cd}t}||}|d|j|||jdS)z&The parser extracts a diagnostic line.z# An example diagnostic line diagnosticN)rrrrr9)r r9r!r"s rtest_diagnostic_linezTestParser.test_diagnostic_lineysY-  && t}555 ty)))))r$ct}|d}|d|j|d|jdS)z$The parser extracts a bail out line.z%Bail out! This is the reason to bail.bailzThis is the reason to bail.N)rrrrr<rs rtest_bail_out_linezTestParser.test_bail_out_linesV  !HII /// 6 DDDDDr$ct}|d}|d|j|d|jdS)z#The parser extracts a version line.zTAP version 13version N)rrrrrJrs rtest_finds_versionzTestParser.test_finds_versionsU  !122 DM222 T\*****r$ct}|t5|dddddS#1swxYwYdS)z=The TAP spec dictates that anything less than 13 is an error.zTAP version 12N)r assertRaises ValueErrorr)r r!s rtest_errors_on_old_versionz%TestParser.test_errors_on_old_versions   z * * 0 0   . / / / 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0sA  AAct}|d}|d|j|d|jdS)z The parser extracts a plan line.z1..42planr&N)rrrrexpected_testsrs rtest_finds_planzTestParser.test_finds_plansU  )) /// T011111r$ct}|d}|d|j||jdS)z2The parser extracts a plan line containing a SKIP.z 1..42 # Skipping this test file.rRNr2rs rtest_finds_plan_with_skipz$TestParser.test_finds_plan_with_skipsQ  !CDD ///  """""r$ct}|d}|d|jdS)z4The parser only recognizes SKIP directives in plans.z1..42 # TODO will not work.r@NrArs r-test_ignores_plan_with_any_non_skip_directivez8TestParser.test_ignores_plan_with_any_non_skip_directives=  !>?? DM22222r$c4tjd}t}g}||D]}|||dt ||d|dj|d|dj||dj |d|dj| |dj dS)NH1..2 ok 1 A passing test not ok 2 A failing testr rRrr) inspectcleandocr parse_textappendrlenrrrr7)r sampler!linesr"s rtest_parses_textzTestParser.test_parses_texts! '   %%f--  D LL     CJJ''' q!2333 q!2333 a $$$ q!2333 q%%%%%r$c tjd}tjd}||d|t}g}||j D]}| || dt|| d|dj | d|d j ||d j||d j| d|d j ||d jdS) NrZFdeletezutf-8r rRrrr[r\)r]r^tempfileNamedTemporaryFilewriteencodecloser parse_filenamer`rrarrr assertIsNone yaml_blockr7)r rbtempr!rcr"s rtest_parses_filezTestParser.test_parses_filesa! '   *%888 6==))*** %%di00  D LL     CJJ''' q!2333 q!2333 a $$$ %(-... q!2333 q%%%%%r$cztjd}t}g}||D]}||t rt jd}|dt||d|dj |||dj |d|dj | |dj dS|d t||d|dj ttdd D]#}|d ||j $|d|d j dS) NzTAP version 13 1..2 ok 1 A passing test --- test: sample yaml ... not ok 2 A failing testtest: sample yamlrKrr\rr r@r]r^rr_r` have_yamlyaml safe_loadrrarJrprrolistranger rbr!rcr"converted_yaml line_indexs rtest_parses_yamlzTestParser.test_parses_yamls! '  %%f--  D LL      8!^,DEEN   QE + + +   Rq!1 2 2 2   ^U1X-@ A A A   VU1X%6 7 7 7   eAh1 2 2 2 2 2   QE + + +   Rq!1 2 2 2"5A;;// H H   E*,=,FGGGG   VU1X%6 7 7 7 7 7r$c tjd}tjd}t}g}||||||t r|d|dj|d|dj|d|dj|d |d j|d |d jn|d|dj|d|dj|d|d j|d |d j|d |djt}g}||||||t r|d |dj|d |dj|d|dj|d|d j|d|d jdS|d |dj|d |dj|d|dj|d|d j|d|djdS)NzTAP version 13 1..2 ok 1 A passing version 13 test --- test: sample yaml ... not ok 2 A failing version 13 testzV1..2 ok 1 A passing pre-13 test not ok 2 A failing pre-13 testrKrzA passing version 13 testr\zA failing version 13 testr zA passing pre-13 testzA failing pre-13 testrw r[) r]r^rextendr_ryrrJr*)r sample_version_13 sample_pre_13r!rcs rtest_parses_mixedzTestParser.test_parses_mixedsL$, 2   ( .   V&&'899::: V&&}55666  L   Rq!1 2 2 2   8%(:N O O O   8%(:N O O O   4eAh6J K K K   4eAh6J K K K K   Rq!1 2 2 2   8%(:N O O O   8%(:N O O O   4eAh6J K K K   4eAh6J K K K V&&}55666 V&&'899:::  P   4eAh6J K K K   4eAh6J K K K   Rq!1 2 2 2   8%(:N O O O   8%(:N O O O O O   4eAh6J K K K   4eAh6J K K K   Rq!1 2 2 2   8%(:N O O O   8%(:N O O O O Or$cztjd}t}g}||D]}||t rt jd}|dt||d|dj |||dj |d|dj | |dj dS|d t||d|dj ttdd D]#}|d ||j $|d|d j dS) NzTAP version 13 1..2 ok 1 A passing test --- test: sample yaml not ok 2 A failing testrtrurKrr\rr rwrr@rxr~s rtest_parses_yaml_no_endz"TestParser.test_parses_yaml_no_end4s! '  %%f--  D LL      8!^,DEEN   QE + + +   Rq!1 2 2 2   ^U1X-@ A A A   VU1X%6 7 7 7   eAh1 2 2 2 2 2   QE + + +   Rq!1 2 2 2"5A;;// H H   E*,=,FGGGG   VU1X%6 7 7 7 7 7r$ctjd}t}g}||D]}||t r{t jd}|dt||d|dj |||dj dS|dt||d|dj ttddD]#}|d ||j$dS) NaTAP version 13 1..2 ok 1 A passing test --- message: test severity: fail data: got: - foo expect: - bar output: |- a multiline string must be handled properly even with | pipes | here > and: therea message: test severity: fail data: got: - foo expect: - bar output: "a multiline string\nmust be handled properly\neven with | pipes\n| here > and: there"r rKrr\ r@)r]r^rr_r`ryrzr{rrarJrpr|r}rr~s rtest_parses_yaml_more_complexz(TestParser.test_parses_yaml_more_complexQs`! (  $%%f--  D LL      H!^t  N   QE + + +   Rq!1 2 2 2   ^U1X-@ A A A A A   RU , , ,   Rq!1 2 2 2"5B<<00 H H   E*,=,FGGGG H Hr$cvtjd}t}g}||D]}|||dt ||d|dj||dj |d|dj ttdd D]#}|d ||j $|d |d j dS) NzTAP version 13 1..2 ok 1 A passing test # Diagnostic line --- test: sample yaml ... not ok 2 A failing testrrKrr\rDr rurvr@r) r]r^rr_r`rrarJrorprr|r}r rbr!rcr"rs rtest_parses_yaml_no_associationz*TestParser.test_parses_yaml_no_associations1! '   %%f--  D LL     CJJ''' U1X-... %(-... uQx'8999uQ{{++ D DJ   Yj(9(B C C C C q!233333r$c4tjd}t}g}||D]}|||dt ||d|dj||dj ttddD]#}|d||j $|d |dj dS) NzTAP version 13 1..2 ok 1 A passing test test: sample yaml ... not ok 2 A failing testrwrKrr\r rr@r) r]r^rr_r`rrarJrorpr|r}rrs rtest_parses_yaml_no_startz$TestParser.test_parses_yaml_no_starts! '  %%f--  D LL     CJJ''' U1X-... %(-...uQ{{++ D DJ   Yj(9(B C C C C q!233333r$cd|_tjd}tjd}t}g}t 5\}}||D]}|| dddn #1swxYwYtr |dt||d|dj t 5\}}| |dj dddn #1swxYwY|d| |d|d j| |d j dS|d t||d|dj t!t#d d D]#} |d || j$|d|d j||| dS) NzTAP version 13 1..2 ok 1 A passing test --- test: sample yaml fail: tabs are not allowed! ... not ok 2 A failing testz WARNING: Optional imports not found, TAP 13 output will be ignored. To parse yaml, see requirements in docs: https://tappy.readthedocs.io/en/latest/consumers.html#tap-version-13rurKrr\z+Error parsing yaml block. Check formatting.rr rrvr@)maxDiffr]r^rrr_r`ryrrarJrorpgetvaluestriprr|r}) r rbyaml_errr!rc parse_out_r"outrs rtest_malformed_yamlzTestParser.test_malformed_yamls ! '   # L       #.9a))&11 # # T"""" # # # # # # # # # # # # # # # #  E   QE + + +   Rq!1 2 2 2 "" 7hsA!!%("5666 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7   =s||~~?S?S?U?U      VU1X%6 7 7 7   eAh1 2 2 2 2 2   QE + + +   Rq!1 2 2 2"5A;;// H H   E*,=,FGGGG   VU1X%6 7 7 7   Xy'9'9';';'A'A'C'C D D D D Ds$1B  BB1$D!!D%(D%c"tjd}|t}g}||jD]}|||dt|dS)NFrfr) rhrirlrrmrnr`rra)r rqr!rcr"s rtest_parse_empty_filez TestParser.test_parse_empty_files*%888 %%di00  D LL     CJJ'''''r$ztap.parser.sys.stdinz01..2 ok 1 A passing test not ok 2 A failing testc t}g}|D]}|||dt ||d|dj|d|dj||dj|d|dj||djdS)Nr rRrrr[r\) r parse_stdinr`rrarrrr7)r r!rcr"s rtest_parses_stdinzTestParser.test_parses_stdins&&((  D LL     CJJ''' q!2333 q!2333 a $$$ q!2333 q%%%%%r$N)"__name__ __module__ __qualname____doc__r#r'r+r-r0r4r:r>rBrErHrLrPrTrVrXrdrrrrrrrrrrrpatchrrr$rrr"s%%---***>>><<<###### 2 2 2 > > >333***EEE+++000222###333&&&&&&&.888<4P4P4Pl888:,H,H,H\4442444,)E)E)EV ( ( (TZ    & & & & &r$r) contextlibrr]iorrr rhunittestr tap.parserrrzmore_itertoolsrry ImportErrorrTestCaserrr$rrs%%%%%% KKK''''''IIIII 2 2 2V&V&V&V&V&"V&V&V&V&V&s 9AA