Mpj\<dddlmZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z GddZ y))contextmanagerN) ParserElementParseExceptionKeyword__diag__ __compat__)core_builtin_exprsc$eZdZdZGddZGddej Ze dddd d e d e je d e je d e de de je de je de je e fde de fdZy)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 _/mnt/ssd/data/Dropbox/adrian/scripts/msg_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.saveAsJ7D7X7XD  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.c tj|jdk7r"tj|jd|jdt_|jdt _tj|jd|jdjD]-\}}|rtjntj|/dt_ |jdr#tj|jdn|jd t_|jd t_t D]}|j#d|jd t$_|S) NrrrrrFrrrrr )rr!rset_default_whitespace_charsrrr"inline_literals_usingitemsrenabledisabler$enable_packratr'r(r set_debugr r )rr+valueexprs rrestorez.pyparsing_test.reset_pyparsing_context.restoreas]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 1 + &u% &150B0B<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)r7)rargss r__exit__z/pyparsing_test.reset_pyparsing_context.__exit__s LLNrN) __name__ __module__ __qualname____doc__rr,r7r<r>rArrreset_pyparsing_contextrs(# J $ @# J    rrGcPeZdZdZ 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_dictrLs 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)rQrLN parse_stringprintdumprNrS)rr6 test_stringrQrLverboserPs rassertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckListO&&{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``. TrU)rRrLNrW)rr6r[rRrLr\rPs rassertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDictr^rcj|\}}||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 runTestsrKc3BK|]}t|ts|ywr) isinstancestr.0exps r zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..s QJsC.s+%c40ZY5Os,.)expected_exceptionrLc3BK|]}t|ts|ywr)rclistres rrhzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..JJsD4IJric3BK|]}t|ts|ywr)rcdictres rrhzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..rpriNN)rQrRrLzno validation for ) assertTruezipnext assertRaisesrcrlrSrY)rrun_tests_reportexpected_parse_resultsrLrun_test_successrun_test_resultsrptexpectedmergedr[rPfail_msgrmrQrRs 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)NrK)rcrdreescapeassertRaisesRegexrw)rexc_type expected_msgrLctxs rassertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptions'lC0#%99\#:L++Hl+LPSI&&xS&9SI s4B)NNN)NTrs) rBrCrDrErSr]r`rrrrrFrrTestParseResultsAssertsrIsW 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|j}t|t|j}tt!d||}|dk7r!|jt!||z d|}n1|j#dt!||z d|Dcgc]}|dz }}|sy tt |t!d|D}ddzz}|dk\r<||rd ndzd j%dtt!|dzdDzdz}nd }|rd nd|zd j%dt| dz Dzdz}d}||rd ndz|| dz zzdz}||z|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)rflines rrhz3pyparsing_test.with_line_numbers..ks93t99rcc34K|]}d|dzdzyw)zc rdNrFrfis rrhz3pyparsing_test.with_line_numbers..rs) j!a%30sr c32K|]}d|dzdzyw)z r NrFrs rrhz3pyparsing_test.with_line_numbers..~sXQ 1q5B,0Xrr 12345678900c3BK|]\}}|dd|yw)d:NrF)rfrrrr lineno_widths rrhz3pyparsing_test.with_line_numbers..s:At(1l^1,-QtfXJ?s)start) expandtabsrcinttypingcastrdrurange maketransordro translatereplacer splitlinesminmaxsplitjoin enumerate)rrrrrrrrrcutranstable_maptblord_mark_controls_linesr max_line_lenleadheader0header1digitsheader2rs ` ` @rwith_line_numbersz pyparsing_test.with_line_numberssbT  A fc "6\F""$  #!;;sL9Ly(%(q"uVV7L%M"!QAqD""'-s#mmN3#&|#4 mm26uQ|2Du2LMQQ((M C A  "{c'9i'mmF$;<KK$IIc;/  J  1<<>*HxQ\\^!45Q +X6 9 $llnSf)?   GRs ggX%<-SUBU@V:WXX Y    &Bc *V,"9L7M-N NQU U    ii( V8KL   }"N&s? K4! K:, K?)NNT|NN)rBrCrDrErGunittestTestCaser staticmethodrdrOptionalrboolUnionrrFrrr r swwrB("3"3BH,0)- ,0-1x *,x x OOC(x //#&x  x  x __S) x ooc*x  S#X&x x  x x rr ) contextlibrrrrcorerrrrr rr r rFrrrs.& !{ { r