
    yIf81                         d dl Z d dlmZ d dlmZmZmZmZ d dl	m
Z d dlm
Z d dlm
Z d dlmZmZ  G d d          Z G d d	e          Z
 G d
 dee          Z G d dee          Z G d dee          ZdS )    N)messages)PYPYDoctestScopeFunctionScopeModuleScope)Test)TestCaseskipc                   (     e Zd ZdZd Z fdZ xZS )_DoctestMixinTc                 X   g }t          j        |                                          D ]}|                                dk    rn|                    d          s|                    d          sq|                    d          s\|                    d          sG|                    d          s2|                    d          s|r!|d                             d	          rd
|z  }nd|z  }|                    |           t          j        d          }|d                    |          z  S )N  zexcept:zexcept zfinally:zelse:zelif )z>>> @z... @z... %sz>>> %szo            def doctest_something():
                """
                   %s
                """
            z
       )textwrapdedent
splitlinesstrip
startswithappendjoin)selfinputlineslinedoctestificators        O/var/www/piapp/venv/lib/python3.11/site-packages/pyflakes/test/test_doctests.py
doctestifyz_DoctestMixin.doctestify   sC   OE**5577 	 	Dzz||r!!//#&& 	'//),,	'//),,	' //*--	' //'**		'
 //'**	' 	' #2Y112DEE	'  $$LL"/ +   !1!1%!8!888    c                 d     t                      j        |                     |          g|R i |S )N)superflakesr   )r   r   argskw	__class__s       r   r"   z_DoctestMixin.flakes,   s5    uww~dooe44BtBBBrBBBr   )__name__
__module____qualname__withDoctestr   r"   __classcell__)r%   s   @r   r   r      sU        K9 9 90C C C C C C C C Cr   r   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z ed
          d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )r   Tc                    |                      d          }|j        }d |D             }d |D             }d |D             }|                     t          |          d           |                     t          |          d           |d         }|d         }|                     |t
                     |                     |t                     |                     |t                     |                     |t
                     | 	                    d|           | 	                    d|           | 	                    d	|           |                     t          |          d           | 	                    d
|d                    dS )z-Check that a doctest is given a DoctestScope.z
        m = None

        def doctest_stuff():
            '''
                >>> d = doctest_stuff()
            '''
            f = m
            return f
        c                 .    g | ]}|j         t          u |S  r%   r   .0scopes     r   
<listcomp>z)Test.test_scope_class.<locals>.<listcomp>B   .     I I IK)G)GE)G)G)Gr   c                 .    g | ]}|j         t          u |S r.   r%   r   r0   s     r   r3   z)Test.test_scope_class.<locals>.<listcomp>D   .     J J JL)H)HE)H)H)Hr   c                 .    g | ]}|j         t          u |S r.   r%   r   r0   s     r   r3   z)Test.test_scope_class.<locals>.<listcomp>F   .     K K KM)I)IE)I)I)Ir      r   mdoctest_stuffdfN)
r"   
deadScopesassertEquallenassertIsInstancer   r   assertNotIsInstancer   assertInr   checkerscopesmodule_scopesdoctest_scopesfunction_scopesmodule_scopedoctest_scopes           r   test_scope_classzTest.test_scope_class4   s   ++ 	 	 	 #I I%I I IJ J%J J JK K%K K K 	]++Q///^,,a000$Q'&q)m\:::m[999  >>>  |<<<c<(((o|444c=)))_--q111c?1-.....r   c                 l   |                      d          }|j        }d |D             }d |D             }d |D             }|                     t          |          d           |                     t          |          d           |d         }|d         }|                     d|           |                     d|           |                     d	|           |                     t          |          d
           |                     d|d                    |                     d|d                    dS )z'Check that nested doctests are ignored.a  
        m = None

        def doctest_stuff():
            '''
                >>> def function_in_doctest():
                ...     """
                ...     >>> ignored_undefined_name
                ...     """
                ...     df = m
                ...     return df
                ...
                >>> function_in_doctest()
            '''
            f = m
            return f
        c                 .    g | ]}|j         t          u |S r.   r/   r0   s     r   r3   z4Test.test_nested_doctest_ignored.<locals>.<listcomp>q   r4   r   c                 .    g | ]}|j         t          u |S r.   r6   r0   s     r   r3   z4Test.test_nested_doctest_ignored.<locals>.<listcomp>s   r7   r   c                 .    g | ]}|j         t          u |S r.   r9   r0   s     r   r3   z4Test.test_nested_doctest_ignored.<locals>.<listcomp>u   r:   r   r;   r   r<   r=   function_in_doctest   r?   dfN)r"   r@   rA   rB   rE   rF   s           r   test_nested_doctest_ignoredz Test.test_nested_doctest_ignored\   sr   ++   $ #I I%I I IJ J%J J JK K%K K K 	]++Q///^,,a000$Q'&q)c<(((o|444+];;;_--q111c?1-...dOA./////r   c                    |                      d          }|j        }d |D             }d |D             }d |D             }|                     t          |          d           |                     t          |          d           |d         }|d         }|                     d|           |                     d|           |                     t          |          d	           |                     d
|d                    |                     d|d                    |                     d|d                    |                     d|           dS )z;Check that global in doctest does not pollute module scope.a[  
        def doctest_stuff():
            '''
                >>> def function_in_doctest():
                ...     global m
                ...     m = 50
                ...     df = 10
                ...     m = df
                ...
                >>> function_in_doctest()
            '''
            f = 10
            return f

        c                 .    g | ]}|j         t          u |S r.   r/   r0   s     r   r3   z;Test.test_global_module_scope_pollution.<locals>.<listcomp>   r4   r   c                 .    g | ]}|j         t          u |S r.   r6   r0   s     r   r3   z;Test.test_global_module_scope_pollution.<locals>.<listcomp>   r7   r   c                 .    g | ]}|j         t          u |S r.   r9   r0   s     r   r3   z;Test.test_global_module_scope_pollution.<locals>.<listcomp>   r:   r   r;   r   r=   rS   rT   r?   rU   r<   N)r"   r@   rA   rB   rE   assertNotInrF   s           r   "test_global_module_scope_pollutionz'Test.test_global_module_scope_pollution   s   ++     #I I%I I IJ J%J J JK K%K K K 	]++Q///^,,a000$Q'&q)o|444+];;;_--q111c?1-...dOA.///c?1-...l+++++r   c                 F    |                      dt          j                   d S )Nzn
        global m

        def doctest_stuff():
            '''
                >>> m
            '''
        r"   r<   UndefinedNamer   s    r   test_global_undefinedzTest.test_global_undefined   s.      _	 	 	 	 	r   c                 \    |                      dt          j        t          j                   dS )z*Doctest within nested class are processed.a  
        class C:
            class D:
                '''
                    >>> m
                '''
                def doctest_stuff(self):
                    '''
                        >>> m
                    '''
                    return 1
        Nr^   r`   s    r   test_nested_classzTest.test_nested_class   s2      _ao	/ 	/ 	/ 	/ 	/r   c                 0    |                      d           dS )z<Doctest module does not process doctest in nested functions.a=  
        def doctest_stuff():
            def inner_function():
                '''
                    >>> syntax error
                    >>> inner_function()
                    1
                    >>> m
                '''
                return 1
            m = inner_function()
            return m
        Nr"   r`   s    r   test_ignore_nested_functionz Test.test_ignore_nested_function   s)     	  	 	 	 	 	r   c                 F    |                      dt          j                   dS )z#Doctest may not access class scope.z
        class C:
            def doctest_stuff(self):
                '''
                    >>> m
                '''
                return 1
            m = 1
        Nr^   r`   s    r   test_inaccessible_scope_classz"Test.test_inaccessible_scope_class   s.      _	 	 	 	 	r   c                 0    |                      d           d S )Nzr
        import foo

        def doctest_stuff():
            '''
                >>> foo
            '''
        re   r`   s    r   test_importBeforeDoctestzTest.test_importBeforeDoctest   s'      	 	 	 	 	r   todoc                 F    |                      dt          j                   d S )Nz
        import foo

        def doctest_stuff():
            """
                >>> import foo
                >>> foo
            """

        foo
        )r"   r<   RedefinedWhileUnusedr`   s    r   test_importBeforeAndInDoctestz"Test.test_importBeforeAndInDoctest   s/     
 #
	% 
	% 
	% 
	% 
	%r   c                 0    |                      d           d S )Nz
        def doctest_stuff():
            """
                >>> import foo
                >>> foo
            """

        import foo
        foo()
        re   r`   s    r   test_importInDoctestAndAfterz!Test.test_importInDoctestAndAfter  '     	 		 		 		 		 		r   c                     |                      dt          j                  j        d         }|                     |j        d           |                     |j        d           d S )Nzg

        def doctest_stuff():
            """
                >>> x # line 5
            """

        r         r"   r<   r_   r   rA   linenocolr   excs     r   test_offsetInDoctestszTest.test_offsetInDoctests  e    kk  _  'q* 	Q'''"%%%%%r   c                     |                      dt          j                  j        d         }|                     |j        d           |                     |j        d           d S )Nzo

        def doctest_stuff():
            """
                >>> lambda: x # line 5
            """

        r   rs      ru   rx   s     r   test_offsetInLambdasInDoctestsz#Test.test_offsetInLambdasInDoctests  r{   r   c                     |                      dt          j                  j        d         }|                     |j        d           |                     |j        d           d S )Nzm

        def doctest_stuff():
            """
                >>> x = 5
            """

        x

        r      ru   rx   s     r   test_offsetAfterDoctestszTest.test_offsetAfterDoctests(  se    kk 	 _	 	 'q	* 	Q'''!$$$$$r   c                 |   |                      dt          j        t          j        t          j                  j        }|d         }|                     |j        d           t          s|                     |j        d           n|                     |j        d           |d         }|                     |j        d           t          r|                     |j        d           n|                     |j        d	           |d
         }|                     |j        d           |                     |j        d           d S )Nz
            def doctest_stuff():
                """
                    >>> from # line 4
                    >>>     fortytwo = 42
                    >>> except Exception:
                """
            r            r;   rs         rT      )r"   r<   DoctestSyntaxErrorr   rA   rv   r   rw   r   
exceptionsry   s      r   test_syntaxErrorInDoctestzTest.test_syntaxErrorInDoctest6  s1   [[    " " #+ 	 mQ''' 	*SWb))))SWb)))
 mQ''' 	*SWb))))SWb)))mQ'''"%%%%%r   c                     |                      dt          j                  j        d         }|                     |j        d           |                     |j        d           d S )Nz|
        def doctest_stuff():
            """
                >>> if True:
                ... pass
            """
        r   rs   r   )r"   r<   r   r   rA   rv   rw   rx   s     r   test_indentationErrorInDoctestz#Test.test_indentationErrorInDoctestW  sf    kk  !# # $,A/ 	Q'''"%%%%%r   c                 D   |                      dt          j        t          j                  j        \  }}|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           d S )Nz
            def doctest_stuff(arg1,
                              arg2,
                              arg3):
                """
                    >>> assert
                    >>> this
                """
            r         rt   )r"   r<   r   r_   r   rA   rv   rw   )r   exc1exc2s      r   test_offsetWithMultiLineArgsz!Test.test_offsetWithMultiLineArgsb  s    {{  O  & 	t 	a(((2&&&a(((2&&&&&r   c                 0    |                      d           d S )NzT
        def foo():
            '''
                >>> foo
            '''
        re   r`   s    r   test_doctestCanReferToFunctionz#Test.test_doctestCanReferToFunctiont  s'      	 	 	 	 	r   c                 0    |                      d           d S )Nz
        class Foo():
            '''
                >>> Foo
            '''
            def bar(self):
                '''
                    >>> Foo
                '''
        re   r`   s    r   test_doctestCanReferToClassz Test.test_doctestCanReferToClass|  rq   r   c                     |                      dt          j        t          j                  j        }|d         }|                     |j        d           |d         }|                     |j        d           d S )NaF  
            def buildurl(base, *args, **kwargs):
                """
                >>> buildurl('/blah.php', ('a', '&'), ('b', '=')
                '/blah.php?a=%26&b=%3D'
                >>> buildurl('/blah.php', a='&', 'b'='=')
                '/blah.php?b=%3D&a=%26'
                """
                pass
            r   r   r;   r   )r"   r<   r   r   rA   rv   r   s      r   !test_noOffsetSyntaxErrorInDoctestz&Test.test_noOffsetSyntaxErrorInDoctest  sz    [[	   " " #+ 	 mQ'''mQ'''''r   c                 0    |                      d           d S )Nz
        def func():
            """A docstring

            >>> func()
            1
            >>> _
            1
            """
            return 1
        re   r`   s    r   test_singleUnderscoreInDoctestz#Test.test_singleUnderscoreInDoctest  s'     
 
	 
	 
	 
	 
	r   c                 F    |                      dt          j                   d S )Nz
        from gettext import ugettext as _

        def doctest_stuff():
            '''
                >>> pass
            '''
        )r"   r<   UnusedImportr`   s    r   test_globalUnderscoreInDoctestz#Test.test_globalUnderscoreInDoctest  s.      ^	 	 	 	 	r   N)r&   r'   r(   r)   rN   rV   r\   ra   rc   rf   rh   rj   r
   rn   rp   rz   r~   r   r   r   r   r   r   r   r   r   r.   r   r   r   r   0   sl       K&/ &/ &/P)0 )0 )0V), ), ),V  / / /  *
 
 
   
T&\\% % \%
 
 

& 
& 
&
& 
& 
&% % %& & &B	& 	& 	&' ' '$  
 
 
( ( (&      r   r   c                       e Zd ZdZdS )	TestOtherz2Run TestOther with each test wrapped in a doctest.Nr&   r'   r(   __doc__r.   r   r   r   r     s        <<<<r   r   c                       e Zd ZdZdS )TestImportsz4Run TestImports with each test wrapped in a doctest.Nr   r.   r   r   r   r     s        >>>>r   r   c                       e Zd ZdZdS )TestUndefinedNamesz;Run TestUndefinedNames with each test wrapped in a doctest.Nr   r.   r   r   r   r     s        EEEEr   r   )r   pyflakesr   r<   pyflakes.checkerr   r   r   r   pyflakes.test.test_otherr   r   pyflakes.test.test_importsr   "pyflakes.test.test_undefined_namesr   pyflakes.test.harnessr	   r
   r   r.   r   r   <module>r      s    " " " " " "            7 6 6 6 6 6 : : : : : : I I I I I I 0 0 0 0 0 0 0 0C C C C C C C C@@ @ @ @ @8 @ @ @F= = = = =y = = =? ? ? ? ?- ? ? ?F F F F F(: F F F F Fr   