
    g81                         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y)    N)messages)PYPYDoctestScopeFunctionScopeModuleScope)Test)TestCaseskipc                   (     e Zd ZdZd Z fdZ xZS )_DoctestMixinTc                     g }t        j                  |      j                         D ]  }|j                         dk(  rn|j	                  d      sk|j	                  d      sZ|j	                  d      sI|j	                  d      s8|j	                  d      s'|j	                  d      s|r|d   j	                  d	      rd
|z  }nd|z  }|j                  |        t        j                  d      }|dj                  |      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        ^/var/www/html/brdwt/brdwt/brdwtenv/lib/python3.12/site-packages/pyflakes/test/test_doctests.py
doctestifyz_DoctestMixin.doctestify   s    OOE*557 	Dzz|r!//#&//),//),//*-//'*//'*U2Y112DE$$LL	 #// +  !1!1%!888    c                 H    t        |   | j                  |      g|i |S )N)superflakesr   )r   r   argskw	__class__s       r   r"   z_DoctestMixin.flakes,   s%    w~dooe4BtBrBBr   )__name__
__module____qualname__withDoctestr   r"   __classcell__)r%   s   @r   r   r      s    K90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y)r   Tc                 $   | j                  d      }|j                  }|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t
        u s| }}| j                  t        |      d       | j                  t        |      d       |d   }|d   }| j                  |t               | j                  |t               | j                  |t
               | j                  |t               | j                  d|       | j                  d|       | j                  d|       | j                  t        |      d       | j                  d|d          yc c}w c c}w c c}w )	z-Check that a doctest is given a DoctestScope.z
        m = None

        def doctest_stuff():
            '''
                >>> d = doctest_stuff()
            '''
            f = m
            return f
           r   mdoctest_stuffdfN)r"   
deadScopesr%   r   r   r   assertEquallenassertIsInstanceassertNotIsInstanceassertIn	r   checkerscopesscopemodule_scopesdoctest_scopesfunction_scopesmodule_scopedoctest_scopes	            r   test_scope_classzTest.test_scope_class4   s   ++ 	 	 ##%IK)GEI I  &JL)HEJ J  &KM)IEK K 	]+Q/^,a0$Q'&q)m\:m[9  >  |<c<(o|4c=)_-q1c?1-.1IJKs"   FFFF&F>Fc                    | j                  d      }|j                  }|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t
        u s| }}| j                  t        |      d       | j                  t        |      d       |d   }|d   }| j                  d|       | j                  d|       | j                  d|       | j                  t        |      d       | j                  d|d          | j                  d	|d          y
c c}w c c}w c c}w )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
        r-   r   r.   r/   function_in_doctest   r1   dfN)	r"   r2   r%   r   r   r   r3   r4   r7   r8   s	            r   test_nested_doctest_ignoredz Test.test_nested_doctest_ignored\   sV   ++  $ ##%IK)GEI I  &JL)HEJ J  &KM)IEK K 	]+Q/^,a0$Q'&q)c<(o|4+];_-q1c?1-.dOA./)IJKs"   E E EE&E
>E
c                    | j                  d      }|j                  }|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t        u s| }}|D cg c]  }|j                  t
        u s| }}| j                  t        |      d       | j                  t        |      d       |d   }|d   }| j                  d|       | j                  d|       | j                  t        |      d       | j                  d|d          | j                  d|d          | j                  d	|d          | j                  d	|       y
c c}w c c}w c c}w )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

        r-   r   r/   rC   rD   r1   rE   r.   N)
r"   r2   r%   r   r   r   r3   r4   r7   assertNotInr8   s	            r   "test_global_module_scope_pollutionz'Test.test_global_module_scope_pollution   sk   ++    ##%IK)GEI I  &JL)HEJ J  &KM)IEK K 	]+Q/^,a0$Q'&q)o|4+];_-q1c?1-.dOA./c?1-.l+-IJKs"   EEEE&E>Ec                 D    | j                  dt        j                         y )Nzn
        global m

        def doctest_stuff():
            '''
                >>> m
            '''
        r"   r.   UndefinedNamer   s    r   test_global_undefinedzTest.test_global_undefined   s      __	r   c                 b    | j                  dt        j                  t        j                         y)z*Doctest within nested class are processed.a  
        class C:
            class D:
                '''
                    >>> m
                '''
                def doctest_stuff(self):
                    '''
                        >>> m
                    '''
                    return 1
        NrK   rM   s    r   test_nested_classzTest.test_nested_class   s"      __aoo	/r   c                 &    | j                  d       y)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"   rM   s    r   test_ignore_nested_functionz Test.test_ignore_nested_function   s     	  	r   c                 D    | j                  dt        j                         y)z#Doctest may not access class scope.z
        class C:
            def doctest_stuff(self):
                '''
                    >>> m
                '''
                return 1
            m = 1
        NrK   rM   s    r   test_inaccessible_scope_classz"Test.test_inaccessible_scope_class   s      __	r   c                 &    | j                  d       y )Nzr
        import foo

        def doctest_stuff():
            '''
                >>> foo
            '''
        rR   rM   s    r   test_importBeforeDoctestzTest.test_importBeforeDoctest   s      	r   todoc                 D    | j                  dt        j                         y )Nz
        import foo

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

        foo
        )r"   r.   RedefinedWhileUnusedrM   s    r   test_importBeforeAndInDoctestz"Test.test_importBeforeAndInDoctest   s     
 ##
	%r   c                 &    | j                  d       y )Nz
        def doctest_stuff():
            """
                >>> import foo
                >>> foo
            """

        import foo
        foo()
        rR   rM   s    r   test_importInDoctestAndAfterz!Test.test_importInDoctestAndAfter       	 		r   c                     | j                  dt        j                        j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nzg

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

        r         r"   r.   rL   r   r3   linenocolr   excs     r   test_offsetInDoctestszTest.test_offsetInDoctests  V    kk  __ 'hq* 	Q'"%r   c                     | j                  dt        j                        j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nzo

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

        r   r`      rb   re   s     r   test_offsetInLambdasInDoctestsz#Test.test_offsetInLambdasInDoctests  rh   r   c                     | j                  dt        j                        j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nzm

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

        x

        r      rb   re   s     r   test_offsetAfterDoctestszTest.test_offsetAfterDoctests(  sV    kk 	 __	 'hq	* 	Q'!$r   c                    | j                  dt        j                  t        j                  t        j                        j                  }|d   }| j	                  |j
                  d       t        s| j	                  |j                  d       n| j	                  |j                  d       |d   }| j	                  |j
                  d       t        r| j	                  |j                  d       n| j	                  |j                  d	       |d
   }| j	                  |j
                  d       | j	                  |j                  d       y )Nz
            def doctest_stuff():
                """
                    >>> from # line 4
                    >>>     fortytwo = 42
                    >>> except Exception:
                """
            r            r-   r`         rD      )r"   r.   DoctestSyntaxErrorr   r3   rc   r   rd   r   
exceptionsrf   s      r   test_syntaxErrorInDoctestzTest.test_syntaxErrorInDoctest6  s   [[       " #+( 	 mQ'SWWb)SWWb)
 mQ'SWWb)SWWb)mQ'"%r   c                     | j                  dt        j                        j                  d   }| j	                  |j
                  d       | j	                  |j                  d       y )Nz|
        def doctest_stuff():
            """
                >>> if True:
                ... pass
            """
        r   r`   rs   )r"   r.   rv   r   r3   rc   rd   re   s     r   test_indentationErrorInDoctestz#Test.test_indentationErrorInDoctestW  sX    kk  !!# $,8A/ 	Q'"%r   c                 \   | j                  dt        j                  t        j                        j                  \  }}| j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       y )Nz
            def doctest_stuff(arg1,
                              arg2,
                              arg3):
                """
                    >>> assert
                    >>> this
                """
            ru         ra   )r"   r.   rv   rL   r   r3   rc   rd   )r   exc1exc2s      r   test_offsetWithMultiLineArgsz!Test.test_offsetWithMultiLineArgsb  s    {{   OO &X 	t 	a(2&a(2&r   c                 &    | j                  d       y )NzT
        def foo():
            '''
                >>> foo
            '''
        rR   rM   s    r   test_doctestCanReferToFunctionz#Test.test_doctestCanReferToFunctiont  s      	r   c                 &    | j                  d       y )Nz
        class Foo():
            '''
                >>> Foo
            '''
            def bar(self):
                '''
                    >>> Foo
                '''
        rR   rM   s    r   test_doctestCanReferToClassz Test.test_doctestCanReferToClass|  r^   r   c                     | j                  dt        j                  t        j                        j                  }|d   }| j	                  |j
                  d       |d   }| j	                  |j
                  d       y )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   rp   r-   ru   )r"   r.   rv   r   r3   rc   rw   s      r   !test_noOffsetSyntaxErrorInDoctestz&Test.test_noOffsetSyntaxErrorInDoctest  so    [[	     " #+( 	 mQ'mQ'r   c                 &    | j                  d       y )Nz
        def func():
            """A docstring

            >>> func()
            1
            >>> _
            1
            """
            return 1
        rR   rM   s    r   test_singleUnderscoreInDoctestz#Test.test_singleUnderscoreInDoctest  s     
 
	r   c                 D    | j                  dt        j                         y )Nz
        from gettext import ugettext as _

        def doctest_stuff():
            '''
                >>> pass
            '''
        )r"   r.   UnusedImportrM   s    r   test_globalUnderscoreInDoctestz#Test.test_globalUnderscoreInDoctest  s      ^^	r   N)r&   r'   r(   r)   rA   rF   rI   rN   rP   rS   rU   rW   r
   r[   r]   rg   rk   rn   ry   r{   r   r   r   r   r   r    r   r   r   r   0   s    K&/P)0V),V/*
 
&\% %

&
&%&B	&'$
(&r   r   c                       e Zd ZdZy)	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y)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y)TestUndefinedNamesz;Run TestUndefinedNames with each test wrapped in a doctest.Nr   r   r   r   r   r     s    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      sl     "  7 : I 0C C@@8 @F=y =?- ?F(: Fr   