o
    9Di                     @   s|   d dl mZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZmZmZ G dd deZG dd deZG d	d
 d
eZdS )    )version_info)messages)FutureImportationImportationImportationFromStarImportationSubmoduleImportation)TestCaseskipskipIfc                   @   s   e 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
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 )$TestImportationObjectc                 C   s.   t dd d}|jdksJ t|dksJ d S )Nazimport ar   source_statementstrselfbinding r   S/var/www/Datamplify/venv/lib/python3.10/site-packages/pyflakes/test/test_imports.pytest_import_basic      z'TestImportationObject.test_import_basicc                 C   .   t dd d}|jdksJ t|dksJ d S )Ncr   zimport a as cza as cr   r   r   r   r   test_import_as   r   z$TestImportationObject.test_import_asc                 C   s,   t dd }|jdksJ t|dksJ d S )Na.bz
import a.b)r   r   r   r   r   r   r   test_import_submodule      
z+TestImportationObject.test_import_submodulec                 C   r   )Nr   r   zimport a.b as ca.b as cr   r   r   r   r   test_import_submodule_as   s   z.TestImportationObject.test_import_submodule_asc                 C   r   )Nr   r   zimport a.b as aza.b as ar   r   r   r   r   $test_import_submodule_as_source_name%   r   z:TestImportationObject.test_import_submodule_as_source_namec                 C   0   t dd dd}|jdksJ t|dksJ d S )Nr   .zfrom . import az.ar   r   r   r   r   r   r   test_importfrom_relative*      z.TestImportationObject.test_importfrom_relativec                 C   r!   )Nr   ..zfrom .. import a..ar#   r   r   r   r   test_importfrom_relative_parent/   r%   z5TestImportationObject.test_importfrom_relative_parentc                 C   r!   )Nbr'   zfrom ..a import bz..a.br#   r   r   r   r   $test_importfrom_relative_with_module4   r%   z:TestImportationObject.test_importfrom_relative_with_modulec                 C   0   t dd dd}|jdksJ t|dksJ d S )Nr   r'   r)   zfrom ..a import b as cz
..a.b as cr#   r   r   r   r   'test_importfrom_relative_with_module_as9   r%   z=TestImportationObject.test_importfrom_relative_with_module_asc                 C   r!   )Nr)   r   zfrom a import br   r#   r   r   r   r   test_importfrom_member>   r%   z,TestImportationObject.test_importfrom_memberc                 C   r!   )Nr   r   zfrom a.b import cza.b.cr#   r   r   r   r    test_importfrom_submodule_memberC   r%   z6TestImportationObject.test_importfrom_submodule_memberc                 C   r+   )Nr   r   r)   zfrom a import b as cr   r#   r   r   r   r   test_importfrom_member_asH   r%   z/TestImportationObject.test_importfrom_member_asc                 C   r+   )Ndr   r   zfrom a.b import c as dz
a.b.c as dr#   r   r   r   r   #test_importfrom_submodule_member_asM   r%   z9TestImportationObject.test_importfrom_submodule_member_asc                 C   ,   t dd }|jdksJ t|dksJ d S )Nr   zfrom a.b import *za.b.*r   r   r   r   r   r   r   test_importfrom_starR   r   z*TestImportationObject.test_importfrom_starc                 C   r2   )Nz.bzfrom .b import *z.b.*r3   r   r   r   r   test_importfrom_star_relativeW   r   z3TestImportationObject.test_importfrom_star_relativec                 C   s.   t dd d }|jdksJ t|dksJ d S )Nprint_functionz%from __future__ import print_functionz__future__.print_function)r   r   r   r   r   r   r   test_importfrom_future\   r   z,TestImportationObject.test_importfrom_futurec                 C      |  dtj dS )zm
        The magic underscore var should be reported as unused when used as an
        import alias.
        zimport fu as _NflakesmUnusedImportr   r   r   r   test_unusedImport_underscorea      z2TestImportationObject.test_unusedImport_underscoreN)__name__
__module____qualname__r   r   r   r   r    r$   r(   r*   r,   r-   r.   r/   r1   r4   r5   r7   r>   r   r   r   r   r      s$    r   c                   @   s@  e 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
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+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dodp Z:dqdr Z;dsdt Z<dudv Z=dwdx Z>dydz Z?d{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\e]ddd Z^dd Z_dd Z`dd Zadd Zbdd ZcedeedkdÃddń ZfedeedkdÃddǄ ZgdS )Testc                 C   s(   |  dtjtj |  dtjtj d S )Nzimport fu, barzfrom baz import fu, barr9   r=   r   r   r   test_unusedImportk   s   zTest.test_unusedImportc                 C   s   |  dtj |  dtj |  dtj |  dtj |  dtj |  dtj |  dtj |  dtj |  d	tj |  dtj}|jd
 }|jdksRJ |jdksYJ |  dtj}|jd
 }|jdkslJ |jdkssJ d S )Nzfrom . import fuzfrom . import fu as bazzfrom .. import fuzfrom ... import fuzfrom .. import fu as bazzfrom .bar import fuzfrom ..bar import fuzfrom ...bar import fuzfrom ...bar import fu as bazr   %r imported but unusedz.fu)z
.fu as baz)r:   r;   r<   r   messagemessage_argsr   checkererrorr   r   r   test_unusedImport_relativeo   s"   

zTest.test_unusedImport_relativec                 C   s(   |  dtjtj |  dtjtj d S )Nzimport fu as FU, bar as FUz#from moo import fu as FU, bar as FUr:   r;   RedefinedWhileUnusedr<   r=   r   r   r   test_aliasedImport   s   zTest.test_aliasedImportc                 C   s"   |  d |  d |  d dS )z5Imported aliases can shadow the source of the import.zfrom moo import fu as moo; moozimport fu as fu; fuzimport fu.bar as fu; fuNr:   r=   r   r   r   test_aliasedImportShadowModule   s   

z#Test.test_aliasedImportShadowModulec                 C   "   |  d |  d |  d d S )Nzimport fu; print(fu)zfrom baz import fu; print(fu)zimport fu; del furP   r=   r   r   r   test_usedImport      

zTest.test_usedImportc                 C   ,   |  d |  d |  d |  d d S )Nzfrom . import fu; assert fuzfrom .bar import fu; assert fuzfrom .. import fu; assert fuz'from ..bar import fu as baz; assert bazrP   r=   r   r   r   test_usedImport_relative      


zTest.test_usedImport_relativec                 C   s.   |  dtj |  dtj |  dtj d S )Nzimport fu; fu = 3zimport fu; fu, bar = 3zimport fu; [fu, bar] = 3r:   r;   rN   r=   r   r   r   test_redefinedWhileUnused   s   zTest.test_redefinedWhileUnusedc                 C   r8   )ze
        Test that importing a module twice within an if
        block does raise a warning.
        z[
        i = 2
        if i==1:
            import os
            import os
        os.pathNrX   r=   r   r   r   test_redefinedIf      zTest.test_redefinedIfc                 C      |  d dS )zl
        Test that importing a module twice in if
        and else blocks does not raise a warning.
        zi
        i = 2
        if i==1:
            import os
        else:
            import os
        os.pathNrP   r=   r   r   r   test_redefinedIfElse      zTest.test_redefinedIfElsec                 C   r8   )za
        Test that importing a module twice in a try block
        does raise a warning.
        zj
        try:
            import os
            import os
        except:
            pass
        os.pathNrX   r=   r   r   r   test_redefinedTry   s   zTest.test_redefinedTryc                 C   r\   )zp
        Test that importing a module twice in a try
        and except block does not raise a warning.
        zY
        try:
            import os
        except:
            import os
        os.pathNrP   r=   r   r   r   test_redefinedTryExcept   r^   zTest.test_redefinedTryExceptc                 C   r\   )z~
        Test that importing a module twice using a nested
        try/except and if blocks does not issue a warning.
        z
        try:
            if True:
                if True:
                    import os
        except:
            import os
        os.pathNrP   r=   r   r   r   test_redefinedTryNested   r^   zTest.test_redefinedTryNestedc                 C      |  d d S )Nz
        try:
            from aa import mixer
        except AttributeError:
            from bb import mixer
        except RuntimeError:
            from cc import mixer
        except:
            from dd import mixer
        mixer(123)
        rP   r=   r   r   r   test_redefinedTryExceptMulti      z!Test.test_redefinedTryExceptMultic                 C      |  dtj d S )Nz
        try:
            from aa import mixer
        except ImportError:
            pass
        else:
            from bb import mixer
        mixer(123)
        rX   r=   r   r   r   test_redefinedTryElse   s   zTest.test_redefinedTryElsec                 C   rb   )Nz
        try:
            import funca
        except ImportError:
            from bb import funca
            from bb import funcb
        else:
            from bbb import funcb
        print(funca, funcb)
        rP   r=   r   r   r   test_redefinedTryExceptElse   rd   z Test.test_redefinedTryExceptElsec                 C   rb   )Nz
        try:
            from aa import a
        except ImportError:
            from bb import a
        finally:
            a = 42
        print(a)
        rP   r=   r   r   r   test_redefinedTryExceptFinally  rd   z#Test.test_redefinedTryExceptFinallyc                 C   rb   )Nz
        try:
            import b
        except ImportError:
            b = Ellipsis
            from bb import a
        else:
            from aa import a
        finally:
            a = 42
        print(a, b)
        rP   r=   r   r   r   "test_redefinedTryExceptElseFinally  rd   z'Test.test_redefinedTryExceptElseFinallyc                 C   re   )Nz>
        import fu
        def fu():
            pass
        rX   r=   r   r   r   test_redefinedByFunction     zTest.test_redefinedByFunctionc                 C      |  dtjtj dS )r
        Test that shadowing a global name with a nested function definition
        generates a warning.
        zx
        import fu
        def bar():
            def baz():
                def fu():
                    pass
        NrM   r=   r   r   r   test_redefinedInNestedFunction&  s   z#Test.test_redefinedInNestedFunctionc                 C   s   |  dtjtjtjtj dS )rm   z
        import fu
        def bar():
            import fu
            def baz():
                def fu():
                    pass
        NrM   r=   r   r   r   #test_redefinedInNestedFunctionTwice3  s   z(Test.test_redefinedInNestedFunctionTwicec                 C   r\   )z
        Test that a global import which is redefined locally,
        but used later in another scope does not generate a warning.
        aq  
        import unittest, transport

        class GetTransportTestCase(unittest.TestCase):
            def test_get_transport(self):
                transport = 'transport'
                self.assertIsNotNone(transport)

        class TestTransportMethodArgs(unittest.TestCase):
            def test_send_defaults(self):
                transport.Transport()
        NrP   r=   r   r   r   test_redefinedButUsedLaterC  r^   zTest.test_redefinedButUsedLaterc                 C   re   )Nz>
        import fu
        class fu:
            pass
        rX   r=   r   r   r   test_redefinedByClassU  rk   zTest.test_redefinedByClassc                 C   r\   )z
        If an imported name is redefined by a class statement which also uses
        that name in the bases list, no warning is emitted.
        zM
        from fu import bar
        class bar(bar):
            pass
        NrP   r=   r   r   r   test_redefinedBySubclass\  r^   zTest.test_redefinedBySubclassc                 C   r\   )zi
        Test that shadowing a global with a class attribute does not produce a
        warning.
        zS
        import fu
        class bar:
            fu = 1
        print(fu)
        NrP   r=   r   r   r   test_redefinedInClassg  r^   zTest.test_redefinedInClassc                 C   s   |  d |  dtj dS )zN
        Test that import within class is a locally scoped attribute.
        z2
        class bar:
            import fu
        z>
        class bar:
            import fu

        fu
        Nr:   r;   UndefinedNamer=   r   r   r   test_importInClasss  s   
zTest.test_importInClassc                 C   rb   )NzD
        import fu
        def fun():
            print(fu)
        rP   r=   r   r   r   test_usedInFunction  rd   zTest.test_usedInFunctionc                 C       |  dtjtj |  d d S )NzF
        import fu
        def fun(fu):
            print(fu)
        zX
        import fu
        def fun(fu):
            print(fu)
        print(fu)
        r:   r;   r<   rN   r=   r   r   r   test_shadowedByParameter  s   zTest.test_shadowedByParameterc                 C   rb   )Nz	fu = NonerP   r=   r   r   r   test_newAssignment  rd   zTest.test_newAssignmentc                 C   s   |  d |  dtj d S )Nzimport fu; fu.bar.bazzimport fu; "bar".fu.bazr9   r=   r   r   r   test_usedInGetattr  s   
zTest.test_usedInGetattrc                 C   rb   )Nzimport fu; print(fu.bar[1:])rP   r=   r   r   r   test_usedInSlice  rd   zTest.test_usedInSlicec                 C   rb   )Nz6
        import fu
        if True: print(fu)
        rP   r=   r   r   r   test_usedInIfBody  rd   zTest.test_usedInIfBodyc                 C   rb   )Nz/
        import fu
        if fu: pass
        rP   r=   r   r   r   test_usedInIfConditional  rd   zTest.test_usedInIfConditionalc                 C   rb   )NzH
        import fu
        if False: pass
        elif fu: pass
        rP   r=   r   r   r   test_usedInElifConditional  rd   zTest.test_usedInElifConditionalc                 C   rb   )NzJ
        import fu
        if False: pass
        else: print(fu)
        rP   r=   r   r   r   test_usedInElse  rd   zTest.test_usedInElsec                 C   rb   )Nzimport fu; fu.bar()rP   r=   r   r   r   test_usedInCall  rd   zTest.test_usedInCallc                 C   rb   )NzC
        import fu
        class bar:
            bar = fu
        rP   r=   r   r   r   test_usedInClass  rd   zTest.test_usedInClassc                 C   rb   )NzO
        import fu
        class bar(object, fu.baz):
            pass
        rP   r=   r   r   r   test_usedInClassBase  rd   zTest.test_usedInClassBasec                 C   rb   )NzR
        import fu
        def bleh():
            pass
        print(fu)
        rP   r=   r   r   r   test_notUsedInNestedScope  rd   zTest.test_notUsedInNestedScopec                 C   rb   )NzN
        import fu
        for bar in range(9):
            print(fu)
        rP   r=   r   r   r   test_usedInFor  rd   zTest.test_usedInForc                 C   rb   )Nzn
        import fu
        for bar in range(10):
            pass
        else:
            print(fu)
        rP   r=   r   r   r   test_usedInForElse  rd   zTest.test_usedInForElsec                 C   re   )NzH
        import fu
        for fu in range(2):
            pass
        r:   r;   ImportShadowedByLoopVarr=   r   r   r   test_redefinedByFor  rk   zTest.test_redefinedByForc                 C   r8   )zi
        Test that shadowing a global name with a for loop variable generates a
        warning.
        zS
        import fu
        fu.bar()
        for fu in ():
            pass
        Nr   r=   r   r   r   test_shadowedByFor  r[   zTest.test_shadowedByForc                 C       |  dtj |  dtj dS )z
        Test that shadowing a global name with a for loop variable nested in a
        tuple unpack generates a warning.
        zl
        import fu
        fu.bar()
        for (x, y, z, (a, b, c, (fu,))) in ():
            pass
        zl
        import fu
        fu.bar()
        for [x, y, z, (a, b, c, (fu,))] in ():
            pass
        Nr   r=   r   r   r   test_shadowedByForDeep  s   zTest.test_shadowedByForDeepc                 C   rb   )NzD
        import fu
        def fun():
            return fu
        rP   r=   r   r   r   test_usedInReturn  rd   zTest.test_usedInReturnc                 C   s   |  d |  d |  d |  d |  d |  d |  d |  d |  d	 |  d
 |  d |  d |  d |  d |  d d S )Nzimport fu; 3 + fu.barzimport fu; 3 % fu.barzimport fu; 3 - fu.barzimport fu; 3 * fu.barzimport fu; 3 ** fu.barzimport fu; 3 / fu.barzimport fu; 3 // fu.barzimport fu; -fu.barzimport fu; ~fu.barzimport fu; 1 == fu.barzimport fu; 1 | fu.barzimport fu; 1 & fu.barzimport fu; 1 ^ fu.barzimport fu; 1 >> fu.barzimport fu; 1 << fu.barrP   r=   r   r   r   test_usedInOperators  s   













zTest.test_usedInOperatorsc                 C   rb   )Nzimport fu; assert fu.barrP   r=   r   r   r   test_usedInAssert#  rd   zTest.test_usedInAssertc                 C   rb   )Nzimport fu; fu.bar[1]rP   r=   r   r   r   test_usedInSubscript&  rd   zTest.test_usedInSubscriptc                 C   rR   )Nzimport fu; fu and Falsezimport fu; fu or Falsezimport fu; not fu.barrP   r=   r   r   r   test_usedInLogic)  rT   zTest.test_usedInLogicc                 C   rb   )Nzimport fu; [fu]rP   r=   r   r   r   test_usedInList.  rd   zTest.test_usedInListc                 C   rb   )Nzimport fu; (fu,)rP   r=   r   r   r   test_usedInTuple1  rd   zTest.test_usedInTuplec                 C   rb   Nz@
        import fu
        try: fu
        except: pass
        rP   r=   r   r   r   test_usedInTry4  rd   zTest.test_usedInTryc                 C   rb   r   rP   r=   r   r   r   test_usedInExcept;  rd   zTest.test_usedInExceptc                 C   s*   t jg}|t j | jdg|R   d S )NzR
        import fu
        try: pass
        except Exception as fu: pass
        )r;   rN   appendUnusedVariabler:   )r   expectedr   r   r   test_redefinedByExceptB  s
   zTest.test_redefinedByExceptc                 C   rb   )Nz0
        import fu
        raise fu.bar
        rP   r=   r   r   r   test_usedInRaiseL  rd   zTest.test_usedInRaisec                 C   rb   )NzC
        import fu
        def gen():
            yield fu
        rP   r=   r   r   r   test_usedInYieldR  rd   zTest.test_usedInYieldc                 C      |  d |  d d S )Nzimport fu; {fu:None}zimport fu; {1:fu}rP   r=   r   r   r   test_usedInDictY     
zTest.test_usedInDictc                 C   rb   )NzC
        import fu
        def f(bar=fu):
            pass
        rP   r=   r   r   r   test_usedInParameterDefault]  rd   z Test.test_usedInParameterDefaultc                 C   rb   )Nzimport fu; fu.bar = 1rP   r=   r   r   r   test_usedInAttributeAssignd  rd   zTest.test_usedInAttributeAssignc                 C   rb   )Nzimport fu; fu.bar(stuff=fu)rP   r=   r   r   r   test_usedInKeywordArgg  rd   zTest.test_usedInKeywordArgc                 C   r   )Nzimport fu; bar=fuzimport fu; n=0; n+=furP   r=   r   r   r   test_usedInAssignmentj  r   zTest.test_usedInAssignmentc                 C   r   )Nz!import fu; [fu for _ in range(1)]z&import fu; [1 for _ in range(1) if fu]rP   r=   r   r   r   test_usedInListCompn  r   zTest.test_usedInListCompc                 C   r   )NzA
        import fu
        try: pass
        finally: fu
        zA
        import fu
        try: fu
        finally: pass
        rP   r=   r   r   r   test_usedInTryFinallyr     
zTest.test_usedInTryFinallyc                 C   r   )Nz;
        import fu
        while 0:
            fu
        z2
        import fu
        while fu: pass
        rP   r=   r   r   r   test_usedInWhile  r   zTest.test_usedInWhilec                 C   rl   )zt
        A 'global' statement shadowing an unused import should not prevent it
        from being reported.
        z6
        import fu
        def f(): global fu
        N)r:   r;   r<   UnusedIndirectAssignmentr=   r   r   r   test_usedInGlobal  s   zTest.test_usedInGlobalc                 C   r8   )zt
        A 'global' statement shadowing a used import should not cause it to be
        reported as unused.
        zc
            import foo
            def f(): global foo
            def g(): foo.is_used()
        N)r:   r;   r   r=   r   r   r   test_usedAndGlobal  s   zTest.test_usedAndGlobalc                 C   r\   )zn
        Binding an import to a declared global should not cause it to be
        reported as unused.
        zX
            def f(): global foo; import foo
            def g(): foo.is_used()
        NrP   r=   r   r   r   test_assignedToGlobal  r^   zTest.test_assignedToGlobalc                 C   s   d}|  d|  d S )Nzexec("print(1)", fu.bar)zimport fu; %srP   )r   	exec_stmtr   r   r   test_usedInExec  s   zTest.test_usedInExecc                 C   rb   )Nzimport fu; lambda: furP   r=   r   r   r   test_usedInLambda  rd   zTest.test_usedInLambdac                 C   rx   )Nzimport fu; lambda fu: fuzimport fu; lambda fu: fu
fu()ry   r=   r   r   r   test_shadowedByLambda  s   zTest.test_shadowedByLambdac                 C   rb   )Nzimport fu; "meow"[::fu]rP   r=   r   r   r   test_usedInSliceObj  rd   zTest.test_usedInSliceObjc                 C   s   |  dtjtj d S )Nz=
        def bar():
            import fu
        fu
        )r:   r;   r<   ru   r=   r   r   r   test_unusedInNestedScope  s   zTest.test_unusedInNestedScopec                 C   re   )Nz`
        class bar:
            import fu
            def fun(self):
                fu
        rt   r=   r   r   r   test_methodsDontUseClassScope     z"Test.test_methodsDontUseClassScopec                 C   rb   )NzX
        def a():
            def b():
                fu
            import fu
        rP   r=   r   r   r   test_nestedFunctionsNestScope  rd   z"Test.test_nestedFunctionsNestScopec                 C   rb   )Nz
        def a():
            import fu
            class b:
                def c(self):
                    print(fu)
        rP   r=   r   r   r    test_nestedClassAndFunctionScope  rd   z%Test.test_nestedClassAndFunctionScopec                 C   s   |  dtjtj |  dtjtj |  dtjtj}|jd }|jds(J |jdks/J |jd }|jdks;J |jdksBJ d	S )
z,Use of import * at module level is reported.zfrom fu import *zT
        try:
            from fu import *
        except:
            pass
        r    'from %s import *' used; unable )fu   rE   )zfu.*Nr:   r;   ImportStarUsedr<   r   rG   
startswithrH   rI   r   r   r   test_importStar  s   

zTest.test_importStarc                 C   s   |  dtjtj |  dtjtj |  dtjtj}|jd }|jds(J |jdks/J |jd }|jdks;J |jdksBJ |  d	tjtj}|jd }|jdsXJ |jd
ks_J |jd }|jdkskJ |jdksrJ dS )z3Use of import * from a relative import is reported.zfrom .fu import *zU
        try:
            from .fu import *
        except:
            pass
        r   r   rF   r   rE   )z.fu.*from .. import *r&   )r   Nr   rI   r   r   r   test_importStar_relative  s,   



zTest.test_importStar_relativec                 C   sT   |  dtj |  dtj |  dtj}|jd }|jdks!J |jdks(J dS )z)import * is only allowed at module level.z7
        def a():
            from fu import *
        z7
        class a:
            from fu import *
        z7
        class a:
            from .. import *
        r   z/'from %s import *' only allowed at module levelr   N)r:   r;   ImportStarNotPermittedr   rG   rH   rI   r   r   r   test_localImportStar  s   
zTest.test_localImportStarc                 C   r\   )zP
        If a dotted name is imported and used, no warning is reported.
        z.
        import fu.bar
        fu.bar
        NrP   r=   r   r   r   test_packageImport!     zTest.test_packageImportc                 C   r8   )zj
        If a dotted name is imported and not used, an unused import warning is
        reported.
        zimport fu.barNr9   r=   r   r   r   test_unusedPackageImport*  r?   zTest.test_unusedPackageImportc                 C   r   )z
        If a submodule of a package is imported twice, an unused import warning
        and a redefined while unused warning are reported.
        z6
        import fu.bar, fu.bar
        fu.bar
        zD
        import fu.bar
        import fu.bar
        fu.bar
        NrX   r=   r   r   r   test_duplicateSubmoduleImport1  s   z"Test.test_duplicateSubmoduleImportc                 C      |  d |  d dS )z
        If two different submodules of a package are imported, no duplicate
        import warning is reported for the package.
        z>
        import fu.bar, fu.baz
        fu.bar, fu.baz
        zL
        import fu.bar
        import fu.baz
        fu.bar, fu.baz
        NrP   r=   r   r   r   test_differentSubmoduleImport@     
z"Test.test_differentSubmoduleImportc                 C   r   )zC
        Usage of package marks submodule imports as used.
        z>
        import fu
        import fu.bar
        fu.x
        z>
        import fu.bar
        import fu
        fu.x
        NrP   r=   r   r   r   'test_used_package_with_submodule_importO     
z,Test.test_used_package_with_submodule_importc                 C   r   )zL
        Usage of package by alias marks submodule imports as used.
        zU
        import foo as f
        import foo.bar
        f.bar.do_something()
        z_
        import foo as f
        import foo.bar.blah
        f.bar.blah.do_something()
        NrP   r=   r   r   r   0test_used_package_with_submodule_import_of_alias_  r   z5Test.test_used_package_with_submodule_import_of_aliasc                 C   sP   |  dtj}|jd }|jdksJ |jdksJ | jr$|jdks&J dS dS )zR
        When a package and its submodule are imported, only report once.
        z1
        import fu
        import fu.bar
        r   rE   )zfu.bar      N)r:   r;   r<   r   rG   rH   withDoctestlinenorI   r   r   r   )test_unused_package_with_submodule_importo  s   
z.Test.test_unused_package_with_submodule_importc                 C   rU   )Nzimport fu; fu = fuzimport fu; fu, bar = fuzimport fu; [fu, bar] = fuzimport fu; fu += furP   r=   r   r   r   test_assignRHSFirst|  rW   zTest.test_assignRHSFirstc                 C   rb   )Nzp
        try:
            import fu
        except ImportError:
            import bar as fu
        fu
        rP   r=   r   r   r   test_tryingMultipleImports  rd   zTest.test_tryingMultipleImportsc                 C   rb   )Nz`
        import fu
        def a():
            fu = 3
            return fu
        fu
        rP   r=   r   r   r   test_nonGlobalDoesNotRedefine  rd   z"Test.test_nonGlobalDoesNotRedefinec                 C   rb   )Nz;
        def a():
            fu
        import fu
        rP   r=   r   r   r   test_functionsRunLater  rd   zTest.test_functionsRunLaterc                 C   re   )NzG
        import fu
        def fu():
            fu
        fu
        rX   r=   r   r   r   test_functionNamesAreBoundNow  r   z"Test.test_functionNamesAreBoundNowc                 C   rb   )Nza = 1; a = 2rP   r=   r   r   r   !test_ignoreNonImportRedefinitions  rd   z&Test.test_ignoreNonImportRedefinitionstodoc                 C   rb   )NzY
        try:
            import fu
        except ImportError:
            pass
        rP   r=   r   r   r   test_importingForImportError     z!Test.test_importingForImportErrorc                 C   r\   )z0Imports in class scope can be used through self.zf
        class c:
            import i
            def __init__(self):
                self.i
        NrP   r=   r   r   r   test_importedInClass  r   zTest.test_importedInClassc                 C   r\   )zW
        Method named 'foo' with default args referring to module named 'foo'.
        z
        import foo

        class Thing(object):
            def foo(self, parser=foo.parse_foo):
                pass
        NrP   r=   r   r   r   !test_importUsedInMethodDefinition  r   z&Test.test_importUsedInMethodDefinitionc                 C   r   )z__future__ is special.zfrom __future__ import divisionze
        "docstring is allowed before future import"
        from __future__ import division
        NrP   r=   r   r   r   test_futureImport  s   
zTest.test_futureImportc                 C   r   )zD
        __future__ imports must come before anything else.
        z?
        x = 5
        from __future__ import division
        zY
        from foo import bar
        from __future__ import division
        bar
        N)r:   r;   LateFutureImportr=   r   r   r   test_futureImportFirst  s   zTest.test_futureImportFirstc                 C   r\   )z?__future__ is special, but names are injected in the namespace.z
        from __future__ import division
        from __future__ import print_function

        assert print_function is not division
        NrP   r=   r   r   r   test_futureImportUsed  r   zTest.test_futureImportUsed)r      zin 3.14+ this is a SyntaxErrorc                 C   r8   )z0Importing undefined names from __future__ fails.z8
        from __future__ import print_statement
        Nr:   r;   FutureFeatureNotDefinedr=   r   r   r   test_futureImportUndefined     zTest.test_futureImportUndefinedc                 C   r8   )z$Importing '*' from __future__ fails.z*
        from __future__ import *
        Nr   r=   r   r   r   test_futureImportStar  r   zTest.test_futureImportStarN)hr@   rA   rB   rD   rL   rO   rQ   rS   rV   rY   rZ   r]   r_   r`   ra   rc   rf   rg   rh   ri   rj   rn   ro   rp   rq   rr   rs   rv   rw   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rC   i   s    	


	 			
		
rC   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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 )'TestSpecialAllzH
    Tests for suppression of unused import warnings by C{__all__}.
    c                 C   rl   )zp
        An C{__all__} definition does not suppress unused import warnings in a
        function scope.
        zQ
        def foo():
            import bar
            __all__ = ["bar"]
        N)r:   r;   r<   r   r=   r   r   r   test_ignoredInFunction  s   z%TestSpecialAll.test_ignoredInFunctionc                 C   r8   )z_
        An C{__all__} definition in a class does not suppress unused import warnings.
        zM
        import bar
        class foo:
            __all__ = ["bar"]
        Nr9   r=   r   r   r   test_ignoredInClass  s   z"TestSpecialAll.test_ignoredInClassc                 C   re   )Nz:
        import bar
        (__all__,) = ("foo",)
        r9   r=   r   r   r   'test_ignored_when_not_directly_assigned  s   z6TestSpecialAll.test_ignored_when_not_directly_assignedc                 C   r   )zn
        If a name is imported and unused but is named in C{__all__}, no warning
        is reported.
        z6
        import foo
        __all__ = ["foo"]
        z7
        import foo
        __all__ = ("foo",)
        NrP   r=   r   r   r   test_warningSuppressed  r   z%TestSpecialAll.test_warningSuppressedc                 C   s   |  dtjtj dS )zC
        The C{__all__} variable is defined incrementally.
        z
        import a
        import c
        __all__ = ['a']
        __all__ += ['b']
        if 1 < 3:
            __all__ += ['c', 'd']
        Nr:   r;   UndefinedExportr=   r   r   r   test_augmentedAssignment  s   z'TestSpecialAll.test_augmentedAssignmentc                 C      |  dtjtjtjtj dS )zP
        The C{__all__} variable is defined through list concatenation.
        zD
        import sys
        __all__ = ['a'] + ['b'] + ['c']
        Nr:   r;   r   r<   r=   r   r   r   "test_list_concatenation_assignment,     z1TestSpecialAll.test_list_concatenation_assignmentc                 C   r   )zQ
        The C{__all__} variable is defined through tuple concatenation.
        zG
        import sys
        __all__ = ('a',) + ('b',) + ('c',)
        Nr   r=   r   r   r   #test_tuple_concatenation_assignment5  r   z2TestSpecialAll.test_tuple_concatenation_assignmentc                 C   rb   )NzF
        from foo import bar
        __all__ = [bar.__name__]
        rP   r=   r   r   r   test_all_with_attributes>  rd   z'TestSpecialAll.test_all_with_attributesc                 C   rb   )Nz=
        from foo import bar
        __all__ = [bar]
        rP   r=   r   r   r   test_all_with_namesD  r   z"TestSpecialAll.test_all_with_namesc                 C   rb   )Nzs
        from foo import bar
        from bar import baz
        __all__ = [bar.__name__] + [baz.__name__]
        rP   r=   r   r   r   test_all_with_attributes_addedK  rd   z-TestSpecialAll.test_all_with_attributes_addedc                 C   rb   )Nzi
        from foo import bar
        from foo import baz
        __all__ = ['bar', baz.__name__]
        rP   r=   r   r   r   %test_all_mixed_attributes_and_stringsR  rd   z4TestSpecialAll.test_all_mixed_attributes_and_stringsc                 C   s*   |  dtj dD ]	}| j d|d q	dS )zY
        If C{__all__} includes a name which is not bound, a warning is emitted.
        z#
        __all__ = ["foo"]
        )zfoo/__init__.pyz__init__.pyz+
            __all__ = ["foo"]
            )filenameNr   )r   r   r   r   r   test_unboundExportedY  s   z#TestSpecialAll.test_unboundExportedc                 C   s   |  dtjtjtjtj dS )z6
        Report undefined if import * is used
        zT
        from math import *
        __all__ = ['sin', 'cos']
        csc(1)
        N)r:   r;   r   ImportStarUsager=   r   r   r   test_importStarExportedh  s   z&TestSpecialAll.test_importStarExportedc                 C   rl   )z8Report unused import when not needed to satisfy __all__.zL
        from foolib import *
        a = 1
        __all__ = ['a']
        N)r:   r;   r   r<   r=   r   r   r   test_importStarNotExportedr  s   z)TestSpecialAll.test_importStarNotExportedc                 C   r   )zR
        Using a global in a generator expression results in no warnings.
        z!import fu; (fu for _ in range(1))z&import fu; (1 for _ in range(1) if fu)NrP   r=   r   r   r   test_usedInGenExpz  s   
z TestSpecialAll.test_usedInGenExpc                 C   rl   )z
        Re-using a global name as the loop variable for a generator
        expression results in a redefinition warning.
        z!import fu; (1 for fu in range(1))NrM   r=   r   r   r   test_redefinedByGenExp  s   z%TestSpecialAll.test_redefinedByGenExpc                 C   &   |  d |  d |  dtj dS )z
        Using a global name in a decorator statement results in no warnings,
        but using an undefined name in a decorator statement results in an
        undefined name warning.
        zm
        from interior import decorate
        @decorate
        def f():
            return "hello"
        zv
        from interior import decorate
        @decorate('value')
        def f():
            return "hello"
        zG
        @decorate
        def f():
            return "hello"
        Nrt   r=   r   r   r   test_usedAsDecorator  
   

z#TestSpecialAll.test_usedAsDecoratorc                 C   r   )z
        Using an imported name as a class decorator results in no warnings,
        but using an undefined name as a class decorator results in an
        undefined name warning.
        ze
        from interior import decorate
        @decorate
        class foo:
            pass
        zl
        from interior import decorate
        @decorate("foo")
        class bar:
            pass
        z?
        @decorate
        class foo:
            pass
        Nrt   r=   r   r   r   test_usedAsClassDecorator  r  z(TestSpecialAll.test_usedAsClassDecoratorN)r@   rA   rB   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r     s(    
		
r   N)sysr   pyflakesr   r;   pyflakes.checkerr   r   r   r   r   pyflakes.test.harnessr	   r
   r   r   rC   r   r   r   r   r   <module>   s    [       