� ,�ReZ4��P�ddlmZddlZddlmZmZmZmZmZGd�d��Z dS)�)�contextmanagerN�)� ParserElement�ParseException�Keyword�__diag__� __compat__c���eZdZdZGd�d��ZGd�d��Ze dd ed ej e d ej e d e d edej edej edefd���Z dS)�pyparsing_testzB namespace class for classes useful in writing unit tests c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z dS) �&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 c��i|_dS�N)� _save_context��selfs ��/builddir/build/BUILDROOT/alt-python311-setuptools-65.6.3-2.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/setuptools/_vendor/pyparsing/testing.py�__init__z/pyparsing_test.reset_pyparsing_context.__init__-s��!#�D� � � �c���tj|jd<tj|jd<tj|jd<tj|jd<tj|jd<tjrtjj |jd<n d|jd<tj |jd<tj |jd<d �tj D��|jd <d tji|jd <|S) N�default_whitespace�default_keyword_chars�literal_string_class�verbose_stacktrace�packrat_enabled�packrat_cache_size� packrat_parse�recursion_enabledc�:�i|]}|tt|����S�)�getattrr)�.0�names r� z?pyparsing_test.reset_pyparsing_context.save..Fs1��.�.�.�26��g�h��-�-�.�.�.rr�collect_all_And_tokensr )r�DEFAULT_WHITE_CHARSrr�DEFAULT_KEYWORD_CHARS�_literalStringClassr�_packratEnabled� packrat_cache�size�_parse�_left_recursion_enabledr� _all_namesr r%rs r�savez+pyparsing_test.reset_pyparsing_context.save0s��7D�7X�D� �3� 4�:A�:W�D� �6� 7��1� � �&� �8E�7W�D� �3� 4�4A�4Q�D� �0� 1��,� @�"�/�4��"�(���<@��"�#7�8�2?�2F�D� �� /��5� � �#� �.�.�:B�:M�.�.�.�D� �z� *� )�*�*K�0�D� �|� ,��Krc��tj|jdkrtj|jd��|jdt_|jdt _tj|jd��|jd���D](\}}|r tj n tj |���)dt_ |jdr tj |jd��n|jd t_|jd t_|jd t _|S) NrrrrrFrrrrr )rr&r�set_default_whitespace_charsrrr'�inlineLiteralsUsing�itemsr�enable�disabler)�enable_packratr,r-r r%)rr#�values r�restorez.pyparsing_test.reset_pyparsing_context.restorePsE���1��%�&:�;�<�<��:��&�';�<����04�/A�BV�/W�M� ,�,0�,>�?V�,W�G� )� � -��"�#9�:� � � � $�1�*�=�C�C�E�E� G� G� ��e�?�E�?����x�/?��F�F�F�F�,1�M� )��!�"3�4� K��,�T�-?�@T�-U�V�V�V�V�'+�'9�/�'J� �$�48�4F�#�5�M� 1�15�0B�<�0P�J� -��Krc�r�t|����}|j�|j��|Sr)�typer�update)r�rets r�copyz+pyparsing_test.reset_pyparsing_context.copyqs2���$�t�*�*�,�,�C� � � $� $�T�%7� 8� 8� 8��Jrc�*�|���Sr)r/rs r� __enter__z0pyparsing_test.reset_pyparsing_context.__enter__vs���9�9�;�;� rc�.�|���dSr)r8)r�argss r�__exit__z/pyparsing_test.reset_pyparsing_context.__exit__ys�� �L�L�N�N�N�N�NrN) �__name__� __module__� __qualname__�__doc__rr/r8r=r?rBr rr�reset_pyparsing_contextr sz������ � �0 $� $� $� � � �@ � � �B � � �  � � � � � � � rrGc�V�eZdZdZ d d�Z d d�Z d d�Z d d�Zee dfd���Z dS) �&pyparsing_test.TestParseResultsAssertszk A mixin class to add parse results assertion methods to normal unittest.TestCase classes. Nc��|�*|�||���|���|�,|�||���|���dSdS)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``. N��msg)� assertEqual�as_list�as_dict)r�result� expected_list� expected_dictrLs r�assertParseResultsEqualsz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals�sh���(�� � �����0@�0@�c� �J�J�J��(�� � �����0@�0@�c� �J�J�J�J�J�)�(rTc���|�|d���}|r"t|�����n!t|�����|�|||���dS)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)rQrLN�� parse_string�print�dumprNrS)r�expr� test_stringrQrL�verboserPs r�assertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList�sw���&�&�{�d�&�C�C�F�� (��f�k�k�m�m�$�$�$�$��f�n�n�&�&�'�'�'� � )� )�&� �SV� )� W� W� W� W� Wrc���|�|d���}|r"t|�����n!t|�����|�|||���dS)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)rRrLNrV)rrZr[rRrLr\rPs r�assertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict�sw���&�&�{�T�&�B�B�F�� (��f�k�k�m�m�$�$�$�$��f�n�n�&�&�'�'�'� � )� )�&� �SV� )� W� W� W� W� Wrc��|\}}|��d�t||��D��}|D�]\}}} td�| D��d��} td�| D��d��} | �J|�| | p|���5t|t��r|� ddd��n #1swxYwY��td�| D��d��} td�| D��d��} | | fdkr|�|| | | p|� ����t d �|������|�||�|nd � ��dS) 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)] Nc�"�g|] \}}g|�|�R�� Sr r )r"�rpt�expecteds r� zOpyparsing_test.TestParseResultsAsserts.assertRunTestResults..�s9�����%��X�%�c�$�8�$�$���rc3�DK�|]}t|t���|V��dSr)� isinstance�str�r"�exps r� zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..�s1����I�I��J�s�C�4H�4H�I��I�I�I�I�I�Irc3�nK�|]0}t|t���t|t���,|V��1dSr)rgr:� issubclass� Exceptionris rrkzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..�s[������ #�)�#�t�4�4��:D�C��9S�9S��������r)�expected_exceptionrLc3�DK�|]}t|t���|V��dSr)rg�listris rrkzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..��1����N�N�S� �3��8M�8M�N�S�N�N�N�N�N�Nrc3�DK�|]}t|t���|V��dSr)rg�dictris rrkzNpyparsing_test.TestParseResultsAsserts.assertRunTestResults..�rrr�NN)rQrRrLzno validation for {!r}zfailed runTestsrK) �zip�next� assertRaisesrgrnrSrX�format� assertTrue)r�run_tests_report�expected_parse_resultsrL�run_test_success�run_test_results�mergedr[rPrd�fail_msgrorQrRs r�assertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResults�s8��2B� .� �.�%�1���),�-=�?U�)V�)V�����6<�%P�%P�1�K��� $�I�I��I�I�I�4� � �H�*.���'/���� � *�*�&�*�5�!�.�.�/A�x��SV�/���-�-� *�&�)�<�<�-�&,� �-�-�-�-�-�-�-�-�-�-�-�-����-�-�-�-�� )-�N�N�H�N�N�N�PT�)�)� �)-�N�N�H�N�N�N�PT�)�)� �*�=�9�\�I�I� �9�9� &�.;�.;�$,�O�� :�����"�":�"A�"A�+�"N�"N�O�O�O�O� �O�O� �S�_�c�c�BS� � � � � � s�;B � B$ �'B$ c#�rK�|�||���5dV�ddd��dS#1swxYwYdS)NrK)rx)r�exc_typerLs r�assertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseException�s������"�"�8��"�5�5� � ����� � � � � � � � � � � � ���� � � � � � s �,�0�0)NNN)NTru) rCrDrErFrSr]r`r�rrr�r rr�TestParseResultsAssertsrI|s������� � � GK� K� K� K� K�GK� X� X� X� X�GK� X� X� X� X�FJ�= �= �= �= �~ �6D�$� � � � �� � � rr�NT�|�s� start_line�end_line� expand_tabs�eol_mark� mark_spaces� mark_control�returnc �����|r|���}����dkrVt�d�tt dd��t dd����D��dd iz��}d �nEt��fd �t t dd ����dgzD����}|�|��}|�U|d krO|dkr3t�ddd���}|�|��}n|�d |��}|�d}|�t|��}t|t|����}ttd|��|��}�dkr |� ��|dz |�}n*d�|� d��|dz |�D��}|sd Stt|�����td�|D����} d �dzz} | dkrD| d � d�t t| dzd����D����zdz} nd } | | zd � d�t | dz ��D����zdz} | d| dz zzdz} | | zd� ��fd�t||���D����zdzS)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 N�unicodec��i|]\}}||�� Sr r )r"�c�us rr$z4pyparsing_test.with_line_numbers..s��O�O�O�d�a��Q��O�O�Orr�!i$i3$�i!$�c���i|]}|���Sr r )r"r�r�s �rr$z4pyparsing_test.with_line_numbers..s���I�I�I��Q� �I�I�Ir� � i $i#$)� r�rc��g|]}|dz��S)�␊r �r"�lines rrez4pyparsing_test.with_line_numbers..'s��Z�Z�Z��t�e�|�Z�Z�Zrr�c3�4K�|]}t|��V��dSr)�lenr�s rrkz3pyparsing_test.with_line_numbers..,s(����9�9��3�t�9�9�9�9�9�9�9�9r�cc3�NK�|] }d�d|dzdz��V��!dS)z{}{}zc r�dN�ry�r"�is rrkz3pyparsing_test.with_line_numbers..1sL��������M�M�(�Q��U�c�M�:�:������rr�� c3�LK�|]}d�|dzdz��V�� dS)z {}r� Nr�r�s rrkz3pyparsing_test.with_line_numbers..<sL��������$�$�a�!�e�r�\�2�2������rr�� 1234567890c3�N�K�|]\}}d�|�|���V�� dS)z {:{}d}:{}{}Nr�)r"r�r�r�� lineno_widths ��rrkz3pyparsing_test.with_line_numbers..FsO��������A�t��$�$�Q� �d�H�E�E������r)�start)� expandtabsrh� maketransrv�rangerq� translate�replacer��min�max� splitlines�split�join� enumerate)r�r�r�r�r�r�r��tbl�s_lines� max_line_len�lead�header0�header1�header2r�s ` ` @r�with_line_numbersz pyparsing_test.with_line_numbers�sn�����8 � �� � ���A� � #��y�(�(��m�m�O�O�c�%��2�,�,��f�f�8M�8M�&N�&N�O�O�O��F�m�$��������m�m�I�I�I�I�d�5��B�<�<�.@�.@�C�5�.H�I�I�I����� � �C� � �A� � "�{�c�'9�'9��i�'�'��m�m��F�$;�$;�<�<���K�K��$�$����I�I�c�;�/�/�� � ��J� � ��1�v�v�H��x��Q���(�(����Q� �+�+�X�6�6� � �9� $� $��l�l�n�n�Z�!�^�h�%>�?�G�G�Z�Z�������z�A�~�PX�?X�0Y�Z�Z�Z�G�� ��2��3�x�=�=�)�)� ��9�9��9�9�9�9�9� ��l�Q�&�'�� �2� � ���'�'���"�3�|�s�':�A�#>�#>�?�?������� � � �G��G� �� ��g�g����,��"�!4�5�6�6������ � �  � ���L�=�B�+>�)?�@�@�4�G�� �� ��i�i������(�� �C�C�C������ � �  � r)NNTr�NN) rCrDrErFrGr�� staticmethodrh�typing�Optional�int�boolr�r rrr r s0��������f�f�f�f�f�f�f�f�Po�o�o�o�o�o�o�o�b�,0�)-� ��,0�-1�] �] � �] ��O�C�(�] ��/�#�&�] �� ] � � ] � �_�S�)� ] ��o�c�*�] � �] �] �] ��\�] �] �] rr ) � contextlibrr��corerrrrr r r rr�r�s���&�%�%�%�%�%� � � � ���������������| �| �| �| �| �| �| �| �| �| r