Files
intellecton/venv/lib/python3.12/site-packages/pyparsing/__pycache__/testing.cpython-312.pyc
T

176 lines
19 KiB
Plaintext
Raw Normal View History

Ë
vRj\<ãódddlmZddlZddlZddlZddlmZmZmZm Z m
Z
ddl m Z Gdd«Z
y)é)ÚcontextmanagerNé)Ú
ParserElementÚParseExceptionÚKeywordÚ__diag__Ú
__compat__)Úcore_builtin_exprscó$eZdZdZGdd«ZGddej «Ze dddd œd
e d e
je d e
je d
e
de de
je de
je de
je e fde
de fd«Zy)Úpyparsing_testzB
namespace class for classes useful in writing unit tests
có4eZdZdZdZdZdZdZdZdZ 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
cói|_y©N)Ú
_save_context©Úselfs úT/home/antigravity/intellecton/venv/lib/python3.12/site-packages/pyparsing/testing.pyÚ__init__z/pyparsing_test.reset_pyparsing_context.__init__>s
Ø!#ˆDÕ ócóætj|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) default_whitespaceÚdefault_keyword_charsÚliteral_string_classÚverbose_stacktraceÚpackrat_enabledÚpackrat_cache_sizeÚ
packrat_parseÚrecursion_enabledrÚcollect_all_And_tokensr )rÚDEFAULT_WHITE_CHARSrrÚDEFAULT_KEYWORD_CHARSÚ_literalStringClassrÚ_packratEnabledÚ
packrat_cacheÚsizeÚ_parseÚ_left_recursion_enabledrÚ
_all_namesÚgetattrr r )rÚnames rÚsavez+pyparsing_test.reset_pyparsing_context.saveAsJÜ7D×7XÑ7XˆD× Ñ Ð 4Ü:A×:WÑ:WˆD× Ñ Ð ×
× Ñ Ð 8E×7WÑ7WˆD× Ñ Ð 4ä4A×4QÑ4QˆD× Ñ Ð ×/××"Ð#7Ò<@×"Ð#7Ñ8Ü2?×2FÑ2FˆD× Ñ ˜Ñ ×
× Ñ Ð
;C×:MÑ:Mö.Ø26”gœh¨Ó.ˆD× Ñ ˜zÑ
)¬*×*KÑ*Kð0ˆD× Ñ ˜|Ñ ˆKùò.sÄ%E.có
tj|jdk7r"tj|jd«|jdt_|jdt
_tj|jd«|jdj«D]-\}}|rtjntj|«Œ/dt_ |jdr#tj|jd«n|jd t_|jd
t_t D]}|j#d«Œ|jd t$_|S) NrrrrrFrrrrr )rr!rÚset_default_whitespace_charsrrr"Úinline_literals_usingÚitemsrÚenableÚdisabler$Úenable_packratr'r(r
Ú set_debugr r )rr+ÚvalueÚexprs rÚrestorez.pyparsing_test.reset_pyparsing_context.restoreas]ô××%Ð&:Ñ××&Ð';Ñð04×/AÑ/AÐBVÑ/WŒMÔ ,à,0×,>Ñ,>Ð?VÑ,WŒGÔ × ×"Ð#9Ñ
ð1°*Ñ
G ?¡E”¬x×/?Ñ/?ÀÕ
Gð-2ŒMÔ ×!Ð"3Ò×,¨T×-?Ñ-?Ð@TÑ-UÕVà'+×'9Ñ'9¸/Ñ'J”
Ô$Ø48×4FÑ4FØ5ŒMÔ

&ؘ
15×0BÑ0BÀ<Ñ0PŒJÔ ˆKrcópt|««}|jj|j«|Sr)ÚtyperÚupdate)rÚrets rÚcopyz+pyparsing_test.reset_pyparsing_context.copy†s.Ø”$t“*“,ˆCØ × Ñ × $ T×%7Ñ%7Ô ˆJrcó"|j«Sr)r,rs rÚ __enter__z0pyparsing_test.reset_pyparsing_context.__enter__sØ—99“;Ð rcó$|j«yr)r7)rÚargss rÚ__exit__z/pyparsing_test.reset_pyparsing_context.__exit__Žs Ø L‰LNrN)
Ú__name__Ú
__module__Ú __qualname__Ú__doc__rr,r7r<r>rA©rrÚreset_pyparsing_contextrs(ñ# òJ ò@# òJ ò
 ó rrGcóPeZdZdZ ddZ d dZ d dZ d
dZee ddfd«Z
y) ú&pyparsing_test.TestParseResultsAssertszk
A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
Ncó–|"|j||j«|¬«|#|j||j«|¬«yy)
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``.
Úmsg)Ú assertEqualÚas_listÚas_dict)rÚresultÚ
expected_listÚ
expected_dictrLs rÚassertParseResultsEqualsz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEqualssMðÐ× Ñ  °·±Ó0@ÀcÐ ÔÐ× Ñ  °·±Ó0@ÀcÐ Õ)rcó¼|j|d¬«}|rt|j««nt|j««|j |||¬«y)
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``.
Ú parse_all)rQrLÚ parse_stringÚprintÚdumprNrS)rr6Ú test_stringrQrLÚverboserPs rÚassertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList¢óOð×& {¸CˆÜf—kk“mÕf—n × )¨&À
ÐSVÐ Wrcó¼|j|d¬«}|rt|j««nt|j««|j |||¬«y)
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 rÚassertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict°r^rcój|\}}||j|||¬«yd¬«yt||«Dcgc] \}}g|¢|­Œ}}}|D\} }
}td|D«d«} td|D«d«} | 4|j| | xs|¬«5t |
t
«r|
 ddd«Œctd|D«d«}
td|D«d«}|
|fd k7r|j
|
|
|| xs|¬
«Œªtd | ›«Œ¹|j|||¬«yd¬«ycc}}w#1swYŒçxYw) 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 runTestsrKc3óBK|]}t|t«sŒ|Œy­wr)Ú
isinstanceÚstr©Ú.0Úexps rú <genexpr>zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>ásèø€Ò Q¨¼JÀsÌCÕ<P¤Ñ Qùó˜c3ó`K|]&}t|t«rt|t«r|Œ(y­wr)rcr9Ú
issubclassÚ Exceptionres rrhzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>ãs+èø€òàÜ% c¬4Ô0´ZÀÄYÔ5Oôñùs,.)Úexpected_exceptionrLc3óBK|]}t|t«sŒ|Œy­wr)rcÚlistres rrhzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>òóèø€Ò´J¸sÄDÕ4IœÑJùric3óBK|]}t|t«sŒ|Œy­wr)rcÚdictres rrhzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>õrpri©NN)rQrRrLzno validation for )Ú
assertTrueÚzipÚnextÚ assertRaisesrcrlrSrY)rÚrun_tests_reportÚexpected_parse_resultsrLÚrun_test_successÚrun_test_resultsÚrptÚexpectedÚmergedr[rPÚfail_msgrmrQrRs rÚassertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResults¾ð&2BÑ ÐØ°¨#ð ôððGXð ôðô&)Ð)9Ð;QÓ%R÷á!C˜ð!  ðˆFñð28ò#
DÑ- ˜V Xô Ñ Q°Ô QÐSWÓXÜ%)ñà#+ôð
ó
&Ð×*Ø+=À8Â?Èsðñ& f¬iÔ8Ø"(˜ %)ÙÔJÈDó%%)ÙÔJÈDó%& 5¸Ò×"Ø*7Ø*7Ø (¢¨Cð ôÐ 2°;°/ÐCðG#
DðL
O‰OØ ¨S¨_ 
õ
ØBSð
õ
ùóU÷$)úsµD#ÂD)Ä)D2 c#óK|Gt|t«rtj|«}|j |||¬«5}|ddd«y|j ||¬«5}|ddd«y#1swYyxYw#1swYyxYw­w)NrK)rcrdÚreÚescapeÚassertRaisesRegexrw)rÚexc_typeÚ expected_msgrLÚctxs rÚassertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptionsèø€ðИl¬CÔ0Ü#%§9¡9¨\Ó#:×+¨H°lÈÐÐPSØ’I÷ðð×& x°Sи’I÷ð÷ ðú÷ðüs4<B¾A-ÁBÁA9Á$ BÁ-A6Á2BÁ9BÁ>B)NNN)NTrs) rBrCrDrErSr]r`r€rrrˆrFrrÚTestParseResultsAssertsrIsWñ ð
GKó
KðGKó XðGKó XðFJóG ðR
à)¸À$ò ó
ñ rr‰NTÚ)ÚindentÚbase_1Ú
start_lineÚend_lineÚ expand_tabsÚeol_markÚ mark_spacesÚ mark_controlrÚreturnc
ó|r|j«}tt«rdzŠj«Š|Ætjt
|«}|dk(rPt
tdd«tdd««D
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!|j«t!||z
d«|}n1|j#d«t!||z
d«|Dcgc]}|dzŒ }}|sy tt |««Št!d|D««}ddzz}|dk\r<||rd ndzd j%dtt!|dzd««D««zdz}nd }|rd nd|zd j%dt| dz «D««zdz}d}||rd ndz|| dz zzdz}||z|zdj%ˆˆˆfdt'|||z¬«D««zdzScc}
} 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