
    rbiX<                     l    d dl mZ d dlZd dlZd dlZddlmZmZmZm	Z	m
Z
 ddlmZ  G d d          ZdS )    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__)core_builtin_exprsc                      e Zd ZdZ G d d          Z G d dej                  Ze	 	 	 	 	 	 dd	dd
de	de
j        e         de
j        e         dede	de
j        e	         de
j        e	         de
j        e	ef         dede	fd            ZdS )pyparsing_testzB
    namespace class for classes useful in writing unit tests
    c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	&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 | _         d S N)_save_contextselfs    a/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/pyparsing/testing.py__init__z/pyparsing_test.reset_pyparsing_context.__init__>   s    !#D    c                    t           j        | j        d<   t          j        | j        d<   t           j        | j        d<   t           j        | j        d<   t           j        | j        d<   t           j        rt           j        j	        | j        d<   n
d | j        d<   t           j
        | j        d<   t           j        | j        d<   d	 t          j        D             | j        d
<   dt          j        i| j        d<   | S )Ndefault_whitespacedefault_keyword_charsliteral_string_classverbose_stacktracepackrat_enabledpackrat_cache_sizepackrat_parserecursion_enabledc                 :    i | ]}|t          t          |          S  )getattrr   ).0names     r   
<dictcomp>z?pyparsing_test.reset_pyparsing_context.save.<locals>.<dictcomp>W   s1     . . .26gh--. . .r   r   collect_all_And_tokensr	   )r   DEFAULT_WHITE_CHARSr   r   DEFAULT_KEYWORD_CHARS_literalStringClassr   _packratEnabledpackrat_cachesize_parse_left_recursion_enabledr   
_all_namesr	   r&   r   s    r   savez+pyparsing_test.reset_pyparsing_context.saveA   s   7D7XD34:A:WD67 1 56 8E7WD344A4QD01, @!/4 "#788 <@"#782?2FD/5 23. .:B:M. . .Dz*
 )**K0D|, Kr   c                    t           j        | j        d         k    rt          j        | j        d                    | j        d         t           _        | j        d         t
          _        t          j        | j        d                    | j        d                                         D ](\  }} |rt          j
        nt          j        |           )dt           _        | j        d         r t          j        | j        d                    n| j        d	         t           _        | j        d
         t           _        t           D ]}|                    d           | j        d         t$          _        | S )Nr   r   r   r   r   Fr   r   r   r   r	   )r   r'   r   set_default_whitespace_charsr   r   r(   inline_literals_usingitemsr   enabledisabler*   enable_packratr-   r.   r
   	set_debugr	   r&   )r   r$   valueexprs       r   restorez.pyparsing_test.reset_pyparsing_context.restorea   si    1%&:;< < :&';<   04/ABV/WM,,0,>?V,WG)/"#9:    $1*=CCEE G Ge?E?x/?FFFF,1M)!"34 K,T-?@T-UVVVV'+'9/'J$484F#5M1
 + & &u%%%%040B<0PJ-Kr   c                 r     t          |                       }|j                            | j                   |S r   )typer   update)r   rets     r   copyz+pyparsing_test.reset_pyparsing_context.copy   s2    $t**,,C$$T%7888Jr   c                 *    |                                  S r   )r0   r   s    r   	__enter__z0pyparsing_test.reset_pyparsing_context.__enter__   s    99;;r   c                 .    |                                   d S r   )r;   )r   argss     r   __exit__z/pyparsing_test.reset_pyparsing_context.__exit__   s    LLNNNNNr   N)
__name__
__module____qualname____doc__r   r0   r;   r@   rB   rE   r!   r   r   reset_pyparsing_contextr      s{        #	 #	J	$ 	$ 	$	 	 	@#	 #	 #	J	 	 	
	 	 		 	 	 	 	r   rJ   c                   X    e Zd ZdZ	 d	dZ	 d
dZ	 d
dZ	 ddZee	ddfd            Z
dS )&pyparsing_test.TestParseResultsAssertszk
        A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
        Nc                     |*|                      ||                                |           |,|                      ||                                |           dS dS )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_dictrO   s        r   assertParseResultsEqualsz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals   sh     (  0@0@c JJJ(  0@0@c JJJJJ )(r   Tc                     |                     |d          }|r"t          |                                           n!t          |                                           |                     |||           dS )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)rT   rO   Nparse_stringprintdumprQ   rV   )r   r:   test_stringrT   rO   verboserS   s          r   assertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   w     &&{d&CCF (fkkmm$$$$fnn&&'''))&SV)WWWWWr   c                     |                     |d          }|r"t          |                                           n!t          |                                           |                     |||           dS )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``.
            TrX   )rU   rO   NrZ   )r   r:   r^   rU   rO   r_   rS   s          r   assertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   ra   r   c                    |\  }}||                      |||nd           dS d t          ||          D             }|D ]\  }}}	t          d |	D             d          }
t          d |	D             d          }|J|                     ||
p|          5  t	          |t
                    r|	 ddd           n# 1 swxY w Y   t          d |	D             d          }t          d	 |	D             d          }||fd
k    r|                     ||||
p|           t          d|           |                      |||nd           dS )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, ...]]
            Nzfailed runTestsrN   c                 "    g | ]\  }}g ||R S r!   r!   )r#   rptexpecteds      r   
<listcomp>zOpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<listcomp>   s9       !C !# x    r   c              3   D   K   | ]}t          |t                    |V  d S r   )
isinstancestrr#   exps     r   	<genexpr>zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s1       Q QJsC<P<P Q Q Q Q Q Q Qr   c              3   n   K   | ]0}t          |t                    t          |t                    ,|V  1d S r   )rj   r=   
issubclass	Exceptionrl   s     r   rn   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s[        %c400 6@Y5O5O     r   )expected_exceptionrO   c              3   D   K   | ]}t          |t                    |V  d S r   )rj   listrl   s     r   rn   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   1      JJJsD4I4IJJJJJJJr   c              3   D   K   | ]}t          |t                    |V  d S r   )rj   dictrl   s     r   rn   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   ru   r   NN)rT   rU   rO   zno validation for )
assertTruezipnextassertRaisesrj   rq   rV   r\   )r   run_tests_reportexpected_parse_resultsrO   run_test_successrun_test_resultsmergedr^   rS   rg   fail_msgrr   rT   rU   s                 r   assertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResults   sZ   & 2B..%-$##FW       %()9;Q%R%R  F 28 #D #D-VX   Q Q Q Q QSWXX%) #+  
 & &" &1**+=8?s +   ) ) &fi88 )"(L)) ) ) ) ) ) ) ) ) ) ) ) ) ) ) %)JJJJJD% %M %)JJJJJD% %M &}5EE55"*7*7 (C	 6     B;BBCCCC OO S_ccBS      s   B;;B?	B?	c              #   6  K   |`t          |t                    rt          j        |          }|                     |||          5 }|V  d d d            d S # 1 swxY w Y   d S |                     ||          5 }|V  d d d            d S # 1 swxY w Y   d S )NrN   )rj   rk   reescapeassertRaisesRegexr|   )r   exc_typeexpected_msgrO   ctxs        r   assertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseException  s:      'lC00 ;#%9\#:#:L++Hl+LL PSIII                  &&xS&99 SIII                 s$   AAA<BBB)NNN)NTrx   )rF   rG   rH   rI   rV   r`   rc   r   r   r   r   r!   r   r   TestParseResultsAssertsrL      s        	 	
 GK
	K 
	K 
	K 
	K GK	X 	X 	X 	X GK	X 	X 	X 	X FJG	 G	 G	 G	R 
)$	 	 	 
	 	 	r   r   NT| )indentbase_1s
start_lineend_lineexpand_tabseol_markmark_spacesmark_controlr   r   returnc          
      $   |r|                                  } t          t                    rdz                                   |t          j        t
          |          }|dk    rXd t          t          dd          t          dd                    D             }	d	|	d
<   t
                              |	          }
dnTt          |          t
                              fdt          t          dd                    d
gz   D                       }
|                     |
          } |U|dk    rO|dk    r3t
                              ddd          }
|                     |
          } n|                     d|          } |d}|!t          |                                           }t          |t          |                                                     }t          t!          d|          |          }|dk    r.|                                 t!          ||z
  d          |         }n8d |                     d          t!          ||z
  d          |         D             }|sdS t          t          |                    t!          d |D                       }ddz   z  z   }|dk    rK||rdndz   d                    d t          t!          |dz  d                    D                       z   dz   }nd}|rdnd|z   d                    d t          | dz             D                       z   dz   }d}||rdndz   || dz   z  z   dz   }||z   |z   d                    fdt'          |||z             D                       z   dz   S )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.
         Nunicodec                     i | ]\  }}||	S r!   r!   )r#   cus      r   r%   z4pyparsing_test.with_line_numbers.<locals>.<dictcomp>G  s+     " " "!QAq" " "r   r   !   i $  i3$  i!$     r   c                     i | ]}|S r!   r!   )r#   r   ord_mark_controls     r   r%   z4pyparsing_test.with_line_numbers.<locals>.<dictcomp>P  s    MMMQQ(MMMr       i	$  i#$  )	   r   c                     g | ]}|d z   S )   ␊r!   r#   lines     r   rh   z4pyparsing_test.with_line_numbers.<locals>.<listcomp>c  s,        u  r   r   c              3   4   K   | ]}t          |          V  d S r   )lenr   s     r   rn   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>k  s(      993t99999999r   r   c   c              3   .   K   | ]}d  |dz   dz   V  dS )zc                                                                                                   r   d   Nr!   r#   is     r   rn   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>r  sI          0!a%300     r   r   
c              3   ,   K   | ]}d |dz   dz   V  dS )z	         r   
   Nr!   r   s     r   rn   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>~  s3      XXQ01q5B,00XXXXXXr   r   
12345678900c              3   <   K   | ]\  }} | d d|  V  dS )d:Nr!   )r#   r   r   r   r   lineno_widths      r   rn   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>  s^        At ?1l?????t?X??     r   )start)
expandtabsrj   inttypingcastrk   rz   range	maketransordrt   	translatereplacer   
splitlinesminmaxsplitjoin	enumerate)r   r   r   r   r   r   r   r   r   transtable_maptbls_linesmax_line_lenleadheader0header1digitsheader2r   r   s       `  `          @@r   with_line_numbersz pyparsing_test.with_line_numbers  s;   T  	Afc"" 	"6\F""$$#!;sL99Ly((" "%(q"uVV7L7L%M%M" " " '-s#mmN33#&|#4#4 mmMMMM$uQ||2D2Du2LMMM  C  A"{c'9'9i''mmF$;$;<<KK$$IIc;//J1<<>>**HxQ\\^^!4!455Q
++X66
9$$llnnSf)<a%@%@8%KLGG GGENN3zF/BA+F+F+QR  G  	23x==))9999999|a/002(22S*''  "3|s':A#>#>??      G G "RRsggXX%<-SUBU@V:W:WXXXXXY  	 &)BBc*V,"9L7M-NNQUU 	  ii      (
V8KLLL     		
r   )NNTr   NN)rF   rG   rH   rI   rJ   unittestTestCaser   staticmethodrk   r   Optionalr   boolUnionr   r!   r   r   r   r      sj        w w w w w w w wrB B B B B("3 B B BH  ,0)- ,0-1x
 *,x
 x
 x
x
OC(x
 /#&x
 	x

 x
 _S)x
 oc*x
 S#X&x
 x
 
x
 x
 x
 \x
 x
 x
r   r   )
contextlibr   r   r   r   corer   r   r   r   r	   r   r
   r   r!   r   r   <module>r      s    & % % % % % 				                !          {
 {
 {
 {
 {
 {
 {
 {
 {
 {
r   