& d4HddlmZddlZddlmZmZmZmZmZGddZ y))contextmanagerN) ParserElementParseExceptionKeyword__diag__ __compat__ceZdZdZGddZGddZe ddedeje d eje d e d ed ejed ejedefdZ y)pyparsing_testzB namespace class for classes useful in writing unit tests c4eZdZdZdZdZdZdZdZdZ y) &pyparsing_test.reset_pyparsing_contexta Context manager to be used when writing unit tests that modify pyparsing config values: - packrat parsing - bounded recursion parsing - default whitespace characters. - default keyword characters - literal string auto-conversion class - __diag__ settings Example:: with reset_pyparsing_context(): # test that literals used to construct a grammar are automatically suppressed ParserElement.inlineLiteralsUsing(Suppress) term = Word(alphas) | Word(nums) group = Group('(' + term[...] + ')') # assert that the '()' characters are not included in the parsed tokens self.assertParseAndCheckList(group, "(abc 123 def)", ['abc', '123', 'def']) # after exiting context manager, literals are converted to Literal expressions again ci|_yN) _save_contextselfs 3/usr/lib/python3/dist-packages/pyparsing/testing.py__init__z/pyparsing_test.reset_pyparsing_context.__init__-s !#D ctj|jd<tj|jd<tj |jd<tj |jd<tj|jd<tjr(tjj|jd<nd|jd<tj|jd<tj|jd<tjDcic]}|tt|c}|jd <d tj i|jd <|Scc}w) Ndefault_whitespacedefault_keyword_charsliteral_string_classverbose_stacktracepackrat_enabledpackrat_cache_size packrat_parserecursion_enabledrcollect_all_And_tokensr )rDEFAULT_WHITE_CHARSrrDEFAULT_KEYWORD_CHARS_literalStringClassr_packratEnabled packrat_cachesize_parse_left_recursion_enabledr _all_namesgetattrr r)rnames rsavez+pyparsing_test.reset_pyparsing_context.save0sT7D7X7XD  3 4:A:W:WD  6 711   & 8E7W7WD  3 44A4Q4QD  0 1,,"//44""(<@""#782?2F2FD   /55   #  ;C:M:M.26gh--.D  z * )**K*K0D  | ,K.s%E.ctj|jdk7r"tj|jd|jdt_|jdt _tj|jd|jdjD]-\}}|rtjntj|/dt_ |jdr#tj|jdn|jd t_|jd t_|jd t _|S) NrrrrrFrrrrr )rr rset_default_whitespace_charsrrr!inlineLiteralsUsingitemsrenabledisabler#enable_packratr&r'r r)rr*values rrestorez.pyparsing_test.reset_pyparsing_context.restorePs@11%%&:;<::&&';<04/A/ABV/WM ,,0,>,>?V,WG )  - -""#9:  $11*=CCE G e?Ex/?/?F G-2M )!!"34,,T-?-?@T-UV'+'9'9/'J $484F4F#5M 1150B0B<0PJ -Krcpt|}|jj|j|Sr)typerupdate)rrets rcopyz+pyparsing_test.reset_pyparsing_context.copyqs.$t*,C    $ $T%7%7 8Jrc"|jSr)r+rs r __enter__z0pyparsing_test.reset_pyparsing_context.__enter__vs99; rc$|jyr)r4)rargss r__exit__z/pyparsing_test.reset_pyparsing_context.__exit__ys LLNrN) __name__ __module__ __qualname____doc__rr+r4r9r;r>rrreset_pyparsing_contextr s' 0 $ @ B    rrDcNeZdZdZ ddZ d dZ d dZ d dZee dfdZ y) &pyparsing_test.TestParseResultsAssertszk A mixin class to add parse results assertion methods to normal unittest.TestCase classes. Nc|"|j||j||#|j||j|yy)z Unit test assertion to compare a :class:`ParseResults` object with an optional ``expected_list``, and compare any defined results names with an optional ``expected_dict``. Nmsg) assertEqualas_listas_dict)rresult expected_list expected_dictrIs rassertParseResultsEqualsz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEqualssM(  0@c J(  0@c J)rc|j|d}|rt|jnt|j|j |||y)z Convenience wrapper assert to test a parser element and input string, and assert that the resulting ``ParseResults.asList()`` is equal to the ``expected_list``. T) parse_all)rNrIN parse_stringprintdumprKrP)rexpr test_stringrNrIverboserMs rassertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckListsO&&{d&CFfkkm$fnn&'  ) )& SV ) Wrc|j|d}|rt|jnt|j|j |||y)z Convenience wrapper assert to test a parser element and input string, and assert that the resulting ``ParseResults.asDict()`` is equal to the ``expected_dict``. T)parseAll)rOrINrS)rrWrXrOrIrYrMs rassertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDictsO&&{T&BFfkkm$fnn&'  ) )& SV ) Wrc.|\}}|t||Dcgc] \}}g||}}}|D]\} } }td|Dd} td|Dd} | 4|j| | xs|5t| tr|  dddctd|Dd} td|Dd}| |fdk7r|j | | || xs|t d | |j||| yd ycc}}w#1swYxYw) ah Unit test assertion to evaluate output of ``ParserElement.runTests()``. If a list of list-dict tuples is given as the ``expected_parse_results`` argument, then these are zipped with the report tuples returned by ``runTests`` and evaluated using ``assertParseResultsEquals``. Finally, asserts that the overall ``runTests()`` success value is ``True``. :param run_tests_report: tuple(bool, [tuple(str, ParseResults or Exception)]) returned from runTests :param expected_parse_results (optional): [tuple(str, list, dict, Exception)] Nc3BK|]}t|ts|ywr) isinstancestr.0exps r zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..sIJsC4HIc3`K|]&}t|trt|tr|(ywr)r`r6 issubclass Exceptionrbs rrezNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..s+ #)#t4C9S s,.)expected_exceptionrIc3BK|]}t|ts|ywr)r`listrbs rrezNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..NS 38MSNrfc3BK|]}t|ts|ywr)r`dictrbs rrezNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..rmrfNN)rNrOrIzno validation for zfailed runTestsrH)zipnext assertRaisesr`rirPrU assertTrue)rrun_tests_reportexpected_parse_resultsrIrun_test_successrun_test_resultsrptexpectedmergedrXrMfail_msgrjrNrOs rassertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResultss2B . .%1*--=?U)V%X%c$8$6<%H1K $II4 H*.'/  *&*5!../AxSV/- *&)<&,  =-- )-NHNPT) )-NHNPT) *=9\I 99 &.;.;$,O :"$6{o"FGK%HP OO S_c  BS  Y(--sD3D  D c#dK|j||5ddddy#1swYyxYww)NrH)rs)rexc_typerIs rassertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptions0""8"5    s0$ 0-0)NNN)NTrp) r?r@rArBrPrZr]r}rrrrCrrTestParseResultsAssertsrF|sT GK KGK XGK XFJ= ~ 6D$   rrNs start_lineend_line expand_tabseol_mark mark_spaces mark_controlreturnc |r|j}|tjt|}|dk(rPt t ddt ddDcic]\}}|| } }}d| d<tj | } dnFt|} tj tt dd dgzDcic]}|| c}} |j| }|F|d k7rA|dk(r*tj d d d } |j| }n|jd |}|d}| t|}t|t|}ttd||}|dk7r|j|dz |} n'|jd|dz |D cgc]} | dz } } | sytt|td| D}d dzz}|dk\r5|dj!dt t|dzdDzdz}nd}||zdj!dt | dz Dzdz}|d| dz zzdz}||zdj!fdt#| |DzdzScc}}wcc}wcc} w)u  Helpful method for debugging a parser - prints a string with line and column numbers. (Line and column numbers are 1-based.) :param s: tuple(bool, str - string to be printed with line and column numbers :param start_line: int - (optional) starting line number in s to print (default=1) :param end_line: int - (optional) ending line number in s to print (default=len(s)) :param expand_tabs: bool - (optional) expand tabs to spaces, to match the pyparsing default :param eol_mark: str - (optional) string to mark the end of lines, helps visualize trailing spaces (default="|") :param mark_spaces: str - (optional) special character to display in place of spaces :param mark_control: str - (optional) convert non-printing control characters to a placeholding character; valid values: - "unicode" - replaces control chars with Unicode symbols, such as "␍" and "␊" - any single character string - replace control characters with given string - None (default) - string is displayed as-is :return: str - input string with leading line numbers and column number headers unicoder!i$i3$i!$  i $i#$) rru␊c32K|]}t|ywr)len)rclines rrez3pyparsing_test.with_line_numbers../s93t99cc34K|]}d|dzdzyw)zc rdNrCrcis rrez3pyparsing_test.with_line_numbers..4s) j!a%30sr c32K|]}d|dzdzyw)z r NrCrs rrez3pyparsing_test.with_line_numbers..?sXQ 1q5B,0Xrr 1234567890c3>K|]\}}|dd|yw)d:NrC)rcrrr lineno_widths rrez3pyparsing_test.with_line_numbers..Fs6Atl^1$%QtfXJ7s)start) expandtabstypingcastrarqrange maketransordrl translatereplacerminmax splitlinessplitjoin enumerate)rrrrrrrcutranstable_maptblord_mark_controls_linesr max_line_lenleadheader0header1header2rs ` @rwith_line_numbersz pyparsing_test.with_line_numberss8  A  #!;;sL9Ly(%(q"uVV7L%M"!QAqD""'-s#mmN3#&|#4 mm26uQ|2Du2LMQQ((M C A  "{c'9i'mmF$;<KK$IIc;/  J  1vHxQ(Q +X6 9 $llnZ!^h?G01zA~PX0YZte|ZGZ3x=) 999 lQ&' 2 ''"3|s':A#>?   G  ggX%<-SUBU@V:WXX Y   L=B+>)?@@4G  ii( C     k"N&[s I?; J J )NNT|NN) r?r@rArBrDr staticmethodrarOptionalintboolrrCrrr r sffPoob,0)- ,0-1] ] OOC(] //#&]  ]  ] __S) ] ooc*]  ] ] rr ) contextlibrrcorerrrrr r rCrrrs#& | | r