Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
testing.cpython-313.pyc176 linesDownload Raw Back to __pycache__
1�

2��j\<��d�SSKJr SSKrSSKrSSKrSSKJrJrJrJ	r	J3r4 SSKJr "SS5r
g)�)�contextmanagerN�)�
ParserElement�ParseException�Keyword�__diag__�5__compat__)�core_builtin_exprsc�2�\rSrSrSr"SS5r"SS\R5r\	SS	SS6.S\7S\R\
S
\R\
S\S\8S\R\9S\R\10S\R\11\
4S\S\124Sjjj5rSrg)�pyparsing_test�z:13namespace class for classes useful in writing unit tests14c�<�\rSrSrSrSrSrSrSrSr	Sr15S	rg16)�&pyparsing_test.reset_pyparsing_context�a_17Context manager to be used when writing unit tests that modify pyparsing config values:18- packrat parsing19- bounded recursion parsing20- default whitespace characters21- default keyword characters22- literal string auto-conversion class23- ``__diag__`` settings24 25Example:26 27.. testcode::28 29    ppt = pyparsing.pyparsing_test30 31    class MyTestClass(ppt.TestParseResultsAsserts):32        def test_literal(self):33            with ppt.reset_pyparsing_context():34                # test that literals used to construct35                # a grammar are automatically suppressed36                ParserElement.inline_literals_using(Suppress)37 38                term = Word(alphas) | Word(nums)39                group = Group('(' + term[...] + ')')40 41                # assert that the '()' characters42                # are not included in the parsed tokens43                self.assertParseAndCheckList(44                    group,45                    "(abc 123 def)",46                    ['abc', '123', 'def']47                )48 49            # after exiting context manager, literals50            # are converted to Literal expressions again51c��0Ulg�N��
_save_context��selfs �WD:\code\apps\devtools\python\user_packages\Python313\site-packages\pyparsing/testing.py�__init__�/pyparsing_test.reset_pyparsing_context.__init__>s52��!#�D��c���[RURS'[RURS'[R53URS'[RURS'[RURS'[R(a([RRURS'OSURS'[RURS'[RURS'[RVs0sHo[[U5_M snURS	'S54[R 0URS'U$s snf)N�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�55_all_names�getattrr	r$)r�names  r�save�+pyparsing_test.reset_pyparsing_context.saveAsM��7D�7X�7X�D���3�4�:A�:W�:W�D���6�7��1�1�
���5�6�8E�7W�7W�D���3�4�4A�4Q�4Q�D���0�1��,�,�!�/�/�4�4��"�"�#7�8�<@��"�"�#7�8�2?�2F�2F�D����/��5�5�
���2�3�56;C�:M�:M�.�:M�$�g�h��-�-�:M�.�D���z�*�57)�*�*K�*K�0�D���|�,��K��.s�*E5c�,�[RURS:wa#[R"URS5 URS[lURS[58l[R"URS5 URSR5H2upU(a[RO[R"U5 M4 S[lURS(a$[R"URS5 OURS	[lURS59[l[ HnUR#S5 M URS[$lU$)NrrrrrFr r!r"r#r	)rr%r�set_default_whitespace_charsrrr&�inline_literals_using�itemsr�enable�disabler(�enable_packratr+r,r60�	set_debugr	r$)rr/�value�exprs    r�restore�.pyparsing_test.reset_pyparsing_context.restoreasQ���1�1��%�%�&:�;�<��:�:��&�&�';�<��04�/A�/A�BV�/W�M�,�,0�,>�,>�?V�,W�G�)��/�/��"�"�#9�:�
� $�1�1�*�=�C�C�E���$)����x�/?�/?�?��F� F�-2�M�)��!�!�"3�4��,�,�T�-?�-?�@T�-U�V�'+�'9�'9�/�'J�
�$�48�4F�4F�#�5�M�1�61+�����u�%�+�15�0B�0B�<�0P�J�-��Krc�p�[U5"5nURRUR5 U$r)�typer�update)r�rets  r�copy�+pyparsing_test.reset_pyparsing_context.copy�s,���t�*�,�C����$�$�T�%7�%7�8��Jrc�"�UR5$r)r0rs r�	__enter__�0pyparsing_test.reset_pyparsing_context.__enter__�s���9�9�;�rc�$�UR5 gr)r<)r�argss  r�__exit__�/pyparsing_test.reset_pyparsing_context.__exit__�s���L�L�NrrN)�__name__�62__module__�__qualname__�__firstlineno__�__doc__rr0r<rBrErI�__static_attributes__�rr�reset_pyparsing_contextrs(��#	�J	$�	�@#	�J	�63	�	rrRc�b�\rSrSrSrS64SjrSSjrSSjrSSjr\	\65SS4Sj5rS	rg)
�&pyparsing_test.TestParseResultsAsserts�z[66A mixin class to add parse results assertion methods to normal unittest.TestCase classes.67Nc��UbURX!R5US9 UbURX1R5US9 gg)z�68Unit test assertion to compare a :class:`ParseResults` object with an optional ``expected_list``,69and compare any defined results names with an optional ``expected_dict``.70N��msg)�assertEqual�as_list�as_dict)r�result�
expected_list�
expected_dictrXs     r�assertParseResultsEquals�?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals�sI���(�� � ����0@�c� �J��(�� � ����0@�c� �J�)rc��URUSS9nU(a[UR55 O[UR55 UR	XcUS9 g)z�71Convenience wrapper assert to test a parser element and input string, and assert that72the resulting :meth:`ParseResults.as_list` is equal to the ``expected_list``.73T��	parse_all)r]rXN��parse_string�print�dumprZr_)rr;�test_stringr]rX�verboser\s       r�assertParseAndCheckList�>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList��M���&�&�{�d�&�C�F���f�k�k�m�$��f�n�n�&�'��)�)�&�SV�)�Wrc��URUSS9nU(a[UR55 O[UR55 UR	XcUS9 g)z�74Convenience wrapper assert to test a parser element and input string, and assert that75the resulting :meth:`ParseResults.as_dict` is equal to the ``expected_dict``.76Trb)r^rXNrd)rr;rhr^rXrir\s       r�assertParseAndCheckDict�>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict�rlrc�n�UupEUcURXCbUOSS9 g[XR5VVs/sHupg/UQUP7PM nnnUH�up�n[SU5S5n[SU5S5nUb;URX�=(d US9 [	U77[785(aU79eSSS5 Mj[SU5S5n
[SU5S5nX�4S	:waUR
U80U
UU=(d US819 M�[SU	<35 M� URXCbUOSS9 gs snnf!,(df   M�=f)a�82Unit test assertion to evaluate output of83:meth:`~ParserElement.run_tests`.84 85If a list of list-dict tuples is given as the86``expected_parse_results`` argument, then these are zipped87with the report tuples returned by ``run_tests()``88and evaluated using :meth:`assertParseResultsEquals`.89Finally, asserts that the overall90`:meth:~ParserElement.run_tests` success value is ``True``.91 92:param run_tests_report: the return value from :meth:`ParserElement.run_tests`93:type run_tests_report: tuple[bool, list[tuple[str, ParseResults | Exception]]]94:param expected_parse_results: (optional)95:type expected_parse_results: list[tuple[str | list | dict | Exception, ...]]96Nzfailed runTestsrWc3�T# �UHn[U[5(dMUv� M  g7fr)�97isinstance�str��.0�exps  r�	<genexpr>�Npyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>�s��� Q���J�s�C�<P������(�	(c3�# �UH5n[U[5(dM[U[5(dM1Uv� M7 g7fr)rrr?�98issubclass�	Exceptionrts  rrwrx�s2����#+�C�%�c�4�0��5?��Y�5O���#+�s�?�?�	?)�expected_exceptionrXc3�T# �UHn[U[5(dMUv� M  g7fr)rr�listrts  rrwrx�����J���J�s�D�4I����ryc3�T# �UHn[U[5(dMUv� M  g7fr)rr�dictrts  rrwrx�r�ry�NN)r]r^rXzno validation for )�99assertTrue�zip�next�assertRaisesrrr|r_rf)r�run_tests_report�expected_parse_resultsrX�run_test_success�run_test_results�rpt�expected�mergedrhr\�fail_msgr}r]r^s               r�assertRunTestResults�;pyparsing_test.TestParseResultsAsserts.assertRunTestResults�s���&2B�.��%�-����$��#�FW� ���&)�)9�%R��%R�M�C�!�#� �x� �%R�
��28�-��X� � Q�� Q�SW�X��%)��#+��100�
&�"�&�1��*�*�+=�?�s�+��&�f�i�8�8�"(�L�9���%)�J��J�D�%�M�%)�J��J�D�%�M�&�5��E��5�5�"�*7�*7� (��C�	6��� 2�;�/�B�C�G28�L
�O�O� �_�c�BS�
�
��U�$��s�D�101D%�%102D4	c#� # �UbI[U[5(a[R"U5nUR	XUS9nUv� SSS5 gURXS9nUv� SSS5 g!,(df   g=f!,(df   g=f7f)NrW)rrrs�re�escape�assertRaisesRegexr�)r�exc_type�expected_msgrX�ctxs     r�assertRaisesParseException�Apyparsing_test.TestParseResultsAsserts.assertRaisesParseExceptions�����'��l�C�0�0�#%�9�9�\�#:�L��+�+�H��+�L�PS��I�M�L��&�&�x�&�9�S��I�:�9�	M�L��:�9�s5�?B�A,�B�A=�#	B�,103A:�6B�=104B�BrQ)NNN)NTr�)
rKrLrMrNrOr_rjrnr�rrr�rPrQrr�TestParseResultsAssertsrT�sW��	�105GK�106	K�GK�	X�GK�	X�FJ�G	�R107�)��$�	�108�	rr�NT�)�indent�base_1�s�109start_line�end_line�expand_tabs�eol_mark�mark_spaces�mark_controlr�r��returnc110�Z^^^�U(aUR5n[T[5(aST-mTR5mUb�[R"[111U5nUS:XaQ[
[SS5[SS55V	V112s0sHup�X�_M	 nn	n113SUS'[114RU5nS	mOH[U5n
[115R[[SS11655S/-V	s0sHo�U
_M sn	5nURU5nUbHUS:waBUS:Xa*[117RSSS
.5nURU5nOURSU5nUcSnUc[UR55n[U[UR555n[[!SU5U5nUS:wa UR5[!X-118S5UnO3UR#S5[!X-119S5UVs/sHnUS-PM120 nnU(dg	[[U55m[!SU55nTSTS--3nUS:�aAUU(aS	OS-S	R%S[[!US-S5555-S-nOS	nU(aS	OSU-S	R%S[U*S-*555-S-nSnUU(aS	OS-UU*S-*--S-nUU-U-SR%UUU4Sj['X�U-S955-S-$s sn121n	fs sn	fs snf)u�122Helpful method for debugging a parser - prints a string with line and column numbers.123(Line and column numbers are 1-based by default - if debugging a parse action,124pass base_1=False, to correspond to the loc value passed to the parse action.)125 126:param s: string to be printed with line and column numbers127:param start_line: starting line number in s to print (default=1)128:param end_line: ending line number in s to print (default=len(s))129:param expand_tabs: expand tabs to spaces, to match the pyparsing default130:param eol_mark: string to mark the end of lines, helps visualize trailing spaces131:param mark_spaces: special character to display in place of spaces132:param mark_control: convert non-printing control characters to a placeholding133                     character; valid values:134 135                     - ``"unicode"`` - replaces control chars with Unicode symbols, such as "␍" and "␊"136                     - any single character string - replace control characters with given string137                     - ``None`` (default) - string is displayed as-is138 139 140:param indent: string to indent with line and column numbers; if an int141               is passed, converted to ``" " * indent``142:param base_1: whether to label string using base 1; if False, string will be143               labeled based at 0144 145:returns: input string with leading line numbers and column number headers146 147.. versionchanged:: 3.2.0148   New ``indent`` and ``base_1`` arguments.149� �unicoder�!i$i3$i!$�r�� i	$i#$)�	r�u␊c3�8# �UHn[U5v� M g7fr)�len)ru�lines  rrw�3pyparsing_test.with_line_numbers.<locals>.<genexpr>ks���9���3�t�9�9����r�cc3�:# �UHnSUS-S-3v� M g7f)zc                                                                                                   r�dNrQ�ru�is  rrwr�rs(����?�� �j�!�a�%�3���0�?�s�r��150c3�8# �UHnSUS-S-3v� M g7f)z	         r�151NrQr�s  rrwr�~s!���X�:W�Q�	�1�q�5�B�,��0�:W�r�r��1521234567890�0c3�F># �UHupTUTS3SUT3v� M g7f)�d�:NrQ)rur�r�r�r��lineno_widths   ���rrwr��s7�����L�G�A��(�1�l�^�1�,�-�Q�t�f�X�J�?�L�s�!)�start)�153expandtabsrr�int�typing�castrsr��range�	maketrans�ordr�	translate�replacer��154splitlines�min�max�split�join�	enumerate)r�r�r�r�r�r�r�r�r��c�u�transtable_map�tbl�ord_mark_control�s_linesr��max_line_len�lead�header0�header1�digits�header2r�s    `  `              @r�with_line_numbers� pyparsing_test.with_line_numbersse���T�����A��f�c�"�"��6�\�F��"�"�$���#�!�;�;�s�L�9�L��y�(�%(��q�"��u�V�V�7L�%M�"�%M�T�Q�A�D�%M��"�'-��s�#��m�m�N�3����#&�|�#4� ��m�m�26�u�Q��|�2D��u�2L�M�2L�Q�(�(�2L�M������C� �A��"�{�c�'9��i�'��m�m��F�$;�<���K�K��$���I�I�c�;�/�����J����1�<�<�>�*�H��x��Q�\�\�^�!4�5����Q�155�+�X�6�156��9�$��l�l�n�S��)<�a�%@�8�L�G��G�G�E�N�3�z�/B�A�+F��R��R�D��u��R�
�����3�x�=�)���9��9�9����#���!1�2�3�4���2����2�S�*��'�'��"�3�|�s�':�A�#>�?�����
�
��G��R�s��
��g�g�X�%�<�-�SU�BU�@V�:W�X�X�
Y��
�	����&�B�c�*�V�,��"�9L�7M�-N�N�QU�U�	�
��
��
��i�i��(��V�8K�L���
��
�		157��}"��N��&s�L�/L#�L(rQ)NNT�|NN)rKrLrMrNrOrR�unittest�TestCaser��staticmethodrsr��Optionalr��bool�Unionr�rPrQrrrrs����w�w�rB�(�"3�"3�B�H�,0�)-� ��,0�-1�x158�*,��x159��x160��O�O�C�(�x161��/�/�#�&�x162��	x163�164�x165��_�_�S�)�
x166��o�o�c�*�x167����S�#�X�&�x168��x169�170
�x171��x172rr)�173contextlibrr�r�r��corerrrrr	r�r174rrQrr�<module>r�s.��&�	�
����!�{175�{176r
codekingpro/portable-devtools · Team Ai