K iq;PddlmZddlZddlZddlmZmZmZmZm Z GddZ y))contextmanagerN) ParserElementParseExceptionKeyword__diag__ __compat__ceZdZdZGddZGddZe dddd d ed eje d eje d e dedejedejedejee fde defdZ 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: .. testcode:: ppt = pyparsing.pyparsing_test class MyTestClass(ppt.TestParseResultsAsserts): def test_literal(self): with ppt.reset_pyparsing_context(): # test that literals used to construct # a grammar are automatically suppressed ParserElement.inline_literals_using(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 W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-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.save?sJ7D7X7XD  3 4:A:W:WD  6 711   5 68E7W7WD  3 44A4Q4QD  0 1,,!//44""#78<@""#782?2F2FD   /55   2 3 ;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.restore_s@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.copys.$t*,C    $ $T%7%7 8Jrc"|jSr)r+rs r __enter__z0pyparsing_test.reset_pyparsing_context.__enter__s99; rc$|jyr)r4)rargss r__exit__z/pyparsing_test.reset_pyparsing_context.__exit__s LLNrN) __name__ __module__ __qualname____doc__rr+r4r9r;r>rrreset_pyparsing_contextr s(# J $ @ B    rrDcPeZdZdZ ddZ d dZ d dZ d dZee ddfdZ 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 :meth:`ParseResults.as_list` 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 :meth:`ParseResults.as_dict` is equal to the ``expected_dict``. T)parseAll)rOrINrS)rrWrXrOrIrYrMs rassertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDictsO&&{T&BFfkkm$fnn&'  ) )& SV ) Wrcj|\}}||j|||ydyt||Dcgc] \}}g||}}}|D]\} } }td|Dd} td|Dd} | 4|j| | xs|5t | t r|  dddctd|Dd} td|Dd}| |fd k7r|j | | || xs| td | |j|||ydycc}}w#1swYxYw) a2 Unit test assertion to evaluate output of :meth:`~ParserElement.run_tests`. 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 ``run_tests()`` and evaluated using :meth:`assertParseResultsEquals`. Finally, asserts that the overall `:meth:~ParserElement.run_tests` success value is ``True``. :param run_tests_report: the return value from :meth:`ParserElement.run_tests` :type run_tests_report: tuple[bool, list[tuple[str, ParseResults | Exception]]] :param expected_parse_results: (optional) :type expected_parse_results: list[tuple[str | list | dict | Exception, ...]] Nzfailed runTestsrHc3BK|]}t|ts|ywr) isinstancestr.0exps r zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..s QJsC.s+%c40ZY5Os,.)expected_exceptionrIc3BK|]}t|ts|ywr)r`listrbs rrezNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..JJsD4IJrfc3BK|]}t|ts|ywr)r`dictrbs rrezNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..rmrfNN)rNrOrIzno validation for ) assertTruezipnext assertRaisesr`rirPrU)rrun_tests_reportexpected_parse_resultsrIrun_test_successrun_test_resultsrptexpectedmergedrXrMfail_msgrjrNrOs rassertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResultss&2B . .%-$# GX &))9;Q%R!C!# x F28# D- VX Q QSWX%)#+  &"&1**+=8?s+)&fi8"(L9)) %)JJD%M%)JJD%M&}5E55"*7*7 (C 6 2;/BCG# DL OO S_c  BS  U$))sD#D))D2 c#K|Gt|trtj|}|j |||5}|dddy|j ||5}|dddy#1swYyxYw#1swYyxYww)NrH)r`rareescapeassertRaisesRegexrt)rexc_type expected_msgrIctxs rassertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptions'lC0#%99\#:L++Hl+LPSI&&xS&9SI s4B)NNN)NTrp) r?r@rArBrPrZr]r}rrrrCrrTestParseResultsAssertsrFsW GK KGK XGK XFJG R )$   rrNT)indentbase_1s start_lineend_line expand_tabseol_mark mark_spaces mark_controlrrreturnc |r|j}ttrdzj|tjt |}|dk(rPt tddtddD cic]\} } | |  } } } d| d<t j| } d nFt|} t jttdd dgzD cic]} | | c} } |j| }|F|dk7rA|dk(r*t jd d d } |j| }n|jd|}|d}| t|}t|t|}ttd||}|dk7r|j!||z |}n'|j#d||z |Dcgc]}|dz }}|sy tt |td|D}ddzzz}|dk\rA||rd ndzd j%dt|rdndt|dzdDzdz}nd }|rd nd|zd j%dt| dz Dzdz}d}||rd ndz|| dz zzdz}||zdj%fdt'|||zDzdzScc} } 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 by default - if debugging a parse action, pass base_1=False, to correspond to the loc value passed to the parse action.) :param s: string to be printed with line and column numbers :param start_line: starting line number in s to print (default=1) :param end_line: ending line number in s to print (default=len(s)) :param expand_tabs: expand tabs to spaces, to match the pyparsing default :param eol_mark: string to mark the end of lines, helps visualize trailing spaces :param mark_spaces: special character to display in place of spaces :param mark_control: 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 :param indent: string to indent with line and column numbers; if an int is passed, converted to ``" " * indent`` :param base_1: whether to label string using base 1; if False, string will be labeled based at 0 :returns: input string with leading line numbers and column number headers .. versionchanged:: 3.2.0 New ``indent`` and ``base_1`` arguments.  unicoder!i$i3$i!$r i $i#$) ru␊c32K|]}t|ywr)len)rclines rrez3pyparsing_test.with_line_numbers..ds93t99rcc34K|]}d|dzdzyw)zc rdNrCrcis rrez3pyparsing_test.with_line_numbers..js) j!a%30sr c32K|]}d|dzdzyw)z r NrCrs rrez3pyparsing_test.with_line_numbers..usXQ 1q5B,0Xrr 12345678900c3BK|]\}}|dd|yw)d:NrC)rcrrrr lineno_widths rrez3pyparsing_test.with_line_numbers..s:At(1l^1,-QtfXJ?s)start) expandtabsr`inttypingcastrarrrange maketransordrl translatereplacerminmax splitlinessplitjoin enumerate)rrrrrrrrrcutranstable_maptblord_mark_controls_linesr max_line_lenleadheader0header1digitsheader2rs ` ` @rwith_line_numbersz pyparsing_test.with_line_numberss9T  A fc "6\F""$  #!;;sL9Ly(%(q"uVV7L%M"!QAqD""'-s#mmN3#&|#4 mm26uQ|2Du2LMQQ((M C A  "{c'9i'mmF$;<KK$IIc;/  J  1vHxQ(Q +X6 9 $llnZ&%88DG*+ V8Kh)W!%u G3x=) 999 |a/00 2 2S*''"1As<3;NPQ7RS   GRs ggX%<-SUBU@V:WXX Y    &Bc *V,"9L7M-N NQU U   ii( V8KL     w"N&s? K! K < K)NNT|NN)r?r@rArBrDr staticmethodrarOptionalrboolUnionrrCrrr r sssjBBH,0)- ,0-1t *,t t OOC(t //#&t  t  t __S) t ooc*t  S#X&t t  t t rr ) contextlibrrrcorerrrrr r rCrrrs&& s s r