o
    h81                     @   s   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 dZG dd	 d	eZ
G d
d deeZG dd deeZG dd deeZdS )    N)messages)PYPYDoctestScopeFunctionScopeModuleScope)Test)TestCaseskipc                       s(   e Zd ZdZdd Z fddZ  ZS )_DoctestMixinTc                 C   s   g }t | D ]>}| dkrn0|ds9|ds9|ds9|ds9|ds9|ds9|r>|d d	r>d
| }nd| }|| q	t d}|d| 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doctestificator r   Q/var/www/html/ai/venv/lib/python3.10/site-packages/pyflakes/test/test_doctests.py
doctestify   s0   


z_DoctestMixin.doctestifyc                    s    t  j| |g|R i |S )N)superflakesr   )r   r   argskw	__class__r   r   r   ,   s    z_DoctestMixin.flakes)__name__
__module____qualname__withDoctestr   r   __classcell__r   r   r!   r   r
      s    r
   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zeddd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-S ).r   Tc                 C   s   |  d}|j}dd |D }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                 S      g | ]	}|j tu r|qS r   r"   r   .0scoper   r   r   
<listcomp>B       z)Test.test_scope_class.<locals>.<listcomp>c                 S   r(   r   r"   r   r*   r   r   r   r-   D   r.   c                 S   r(   r   r"   r   r*   r   r   r   r-   F   r.      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_scoper   r   r   test_scope_class4   s0   
zTest.test_scope_classc                 C   s   |  d}|j}dd |D }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                 S   r(   r   r)   r*   r   r   r   r-   q   r.   z4Test.test_nested_doctest_ignored.<locals>.<listcomp>c                 S   r(   r   r/   r*   r   r   r   r-   s   r.   c                 S   r(   r   r0   r*   r   r   r   r-   u   r.   r1   r   r2   r3   function_in_doctest   r5   dfN)r   r6   r7   r8   r;   r<   r   r   r   test_nested_doctest_ignored\   s*   
z Test.test_nested_doctest_ignoredc                 C   s   |  d}|j}dd |D }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                 S   r(   r   r)   r*   r   r   r   r-      r.   z;Test.test_global_module_scope_pollution.<locals>.<listcomp>c                 S   r(   r   r/   r*   r   r   r   r-      r.   c                 S   r(   r   r0   r*   r   r   r   r-      r.   r1   r   r3   rE   rF   r5   rG   r2   N)r   r6   r7   r8   r;   assertNotInr<   r   r   r   "test_global_module_scope_pollution   s,   
z'Test.test_global_module_scope_pollutionc                 C      |  dtj d S )Nzn
        global m

        def doctest_stuff():
            '''
                >>> m
            '''
        r   r2   UndefinedNamer   r   r   r   test_global_undefined      zTest.test_global_undefinedc                 C   s   |  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
        NrL   rN   r   r   r   test_nested_class   s   zTest.test_nested_classc                 C   s   |  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   rN   r   r   r   test_ignore_nested_function   s   z Test.test_ignore_nested_functionc                 C   s   |  dtj dS )z#Doctest may not access class scope.z
        class C:
            def doctest_stuff(self):
                '''
                    >>> m
                '''
                return 1
            m = 1
        NrL   rN   r   r   r   test_inaccessible_scope_class   s   z"Test.test_inaccessible_scope_classc                 C      |  d d S )Nzr
        import foo

        def doctest_stuff():
            '''
                >>> foo
            '''
        rR   rN   r   r   r   test_importBeforeDoctest      zTest.test_importBeforeDoctesttodoc                 C   rK   )Nz
        import foo

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

        foo
        )r   r2   RedefinedWhileUnusedrN   r   r   r   test_importBeforeAndInDoctest   s   
z"Test.test_importBeforeAndInDoctestc                 C   rU   )Nz
        def doctest_stuff():
            """
                >>> import foo
                >>> foo
            """

        import foo
        foo()
        rR   rN   r   r   r   test_importInDoctestAndAfter  rW   z!Test.test_importInDoctestAndAfterc                 C   4   |  dtjjd }| |jd | |jd d S )Nzg

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

        r         r   r2   rM   r   r7   linenocolr   excr   r   r   test_offsetInDoctests     zTest.test_offsetInDoctestsc                 C   r\   )Nzo

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

        r   r]      r_   rb   r   r   r   test_offsetInLambdasInDoctests  re   z#Test.test_offsetInLambdasInDoctestsc                 C   s4   |  dtjjd }| |jd | |jd d S )Nzm

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

        x

        r      r_   rb   r   r   r   test_offsetAfterDoctests(  s   		
zTest.test_offsetAfterDoctestsc                 C   s   |  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            r1   r]         rF      )r   r2   DoctestSyntaxErrorr   r7   r`   r   ra   r   
exceptionsrc   r   r   r   test_syntaxErrorInDoctest6  s*   zTest.test_syntaxErrorInDoctestc                 C   r\   )Nz|
        def doctest_stuff():
            """
                >>> if True:
                ... pass
            """
        r   r]   rm   )r   r2   rp   r   r7   r`   ra   rb   r   r   r   test_indentationErrorInDoctestW  s   z#Test.test_indentationErrorInDoctestc                 C   sT   |  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
                """
            ro         r^   )r   r2   rp   rM   r   r7   r`   ra   )r   exc1exc2r   r   r   test_offsetWithMultiLineArgsb  s   	z!Test.test_offsetWithMultiLineArgsc                 C   rU   )NzT
        def foo():
            '''
                >>> foo
            '''
        rR   rN   r   r   r   test_doctestCanReferToFunctiont  rW   z#Test.test_doctestCanReferToFunctionc                 C   rU   )Nz
        class Foo():
            '''
                >>> Foo
            '''
            def bar(self):
                '''
                    >>> Foo
                '''
        rR   rN   r   r   r   test_doctestCanReferToClass|  rW   z Test.test_doctestCanReferToClassc                 C   sD   |  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   rj   r1   ro   )r   r2   rp   r   r7   r`   rq   r   r   r   !test_noOffsetSyntaxErrorInDoctest  s   
z&Test.test_noOffsetSyntaxErrorInDoctestc                 C   rU   )Nz
        def func():
            """A docstring

            >>> func()
            1
            >>> _
            1
            """
            return 1
        rR   rN   r   r   r   test_singleUnderscoreInDoctest  rW   z#Test.test_singleUnderscoreInDoctestc                 C   rK   )Nz
        from gettext import ugettext as _

        def doctest_stuff():
            '''
                >>> pass
            '''
        )r   r2   UnusedImportrN   r   r   r   test_globalUnderscoreInDoctest  rP   z#Test.test_globalUnderscoreInDoctestN)r#   r$   r%   r&   rD   rH   rJ   rO   rQ   rS   rT   rV   r	   rZ   r[   rd   rg   ri   rs   rt   ry   rz   r{   r|   r}   r   r   r   r   r   r   0   s0    (++


!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         r   c                   @   r   )TestImportsz4Run TestImports with each test wrapped in a doctest.Nr   r   r   r   r   r     r   r   c                   @   r   )TestUndefinedNamesz;Run TestUndefinedNames with each test wrapped in a doctest.Nr   r   r   r   r   r     r   r   )r   pyflakesr   r2   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   r   <module>   s        