o
    h                     @   sl   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 G dd de
ZG dd de
ZG dd	 d	e
Zd
S )    )messages)FutureImportationImportationImportationFromStarImportationSubmoduleImportation)TestCaseskipc                   @   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   P/var/www/html/ai/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_module2   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_as7   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_memberA   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_asF   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_asK   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_starP   r   z*TestImportationObject.test_importfrom_starc                 C   r0   )Nz.bzfrom .b import *z.b.*r1   r   r   r   r   test_importfrom_star_relativeU   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_futureZ   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_underscore_      z2TestImportationObject.test_unusedImport_underscoreN)__name__
__module____qualname__r   r   r   r   r   r"   r&   r(   r*   r+   r,   r-   r/   r2   r3   r5   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 ZcddÄ Zdddń ZedS )Testc                 C   s(   |  dtjtj |  dtjtj d S )Nzimport fu, barzfrom baz import fu, barr7   r;   r   r   r   test_unusedImporti   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)r8   r9   r:   r   messagemessage_argsr   checkererrorr   r   r   test_unusedImport_relativem   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r8   r9   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r8   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 furN   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 bazrN   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r8   r9   rL   r;   r   r   r   test_redefinedWhileUnused   s   zTest.test_redefinedWhileUnusedc                 C   r6   )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.pathNrV   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.pathNrN   r;   r   r   r   test_redefinedIfElse      zTest.test_redefinedIfElsec                 C   r6   )za
        Test that importing a module twice in a try block
        does raise a warning.
        zj
        try:
            import os
            import os
        except:
            pass
        os.pathNrV   r;   r   r   r   test_redefinedTry   s   zTest.test_redefinedTryc                 C   rZ   )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.pathNrN   r;   r   r   r   test_redefinedTryExcept   r\   zTest.test_redefinedTryExceptc                 C   rZ   )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.pathNrN   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)
        rN   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)
        rV   r;   r   r   r   test_redefinedTryElse   s   zTest.test_redefinedTryElsec                 C   r`   )Nz
        try:
            import funca
        except ImportError:
            from bb import funca
            from bb import funcb
        else:
            from bbb import funcb
        print(funca, funcb)
        rN   r;   r   r   r   test_redefinedTryExceptElse   rb   z Test.test_redefinedTryExceptElsec                 C   r`   )Nz
        try:
            from aa import a
        except ImportError:
            from bb import a
        finally:
            a = 42
        print(a)
        rN   r;   r   r   r   test_redefinedTryExceptFinally  rb   z#Test.test_redefinedTryExceptFinallyc                 C   r`   )Nz
        try:
            import b
        except ImportError:
            b = Ellipsis
            from bb import a
        else:
            from aa import a
        finally:
            a = 42
        print(a, b)
        rN   r;   r   r   r   "test_redefinedTryExceptElseFinally  rb   z'Test.test_redefinedTryExceptElseFinallyc                 C   rc   )Nz>
        import fu
        def fu():
            pass
        rV   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
        NrK   r;   r   r   r   test_redefinedInNestedFunction$  s   z#Test.test_redefinedInNestedFunctionc                 C   s   |  dtjtjtjtj dS )rk   z
        import fu
        def bar():
            import fu
            def baz():
                def fu():
                    pass
        NrK   r;   r   r   r   #test_redefinedInNestedFunctionTwice1  s   z(Test.test_redefinedInNestedFunctionTwicec                 C   rZ   )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()
        NrN   r;   r   r   r   test_redefinedButUsedLaterA  r\   zTest.test_redefinedButUsedLaterc                 C   rc   )Nz>
        import fu
        class fu:
            pass
        rV   r;   r   r   r   test_redefinedByClassS  ri   zTest.test_redefinedByClassc                 C   rZ   )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
        NrN   r;   r   r   r   test_redefinedBySubclassZ  r\   zTest.test_redefinedBySubclassc                 C   rZ   )zi
        Test that shadowing a global with a class attribute does not produce a
        warning.
        zS
        import fu
        class bar:
            fu = 1
        print(fu)
        NrN   r;   r   r   r   test_redefinedInClasse  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r8   r9   UndefinedNamer;   r   r   r   test_importInClassq  s   
zTest.test_importInClassc                 C   r`   )NzD
        import fu
        def fun():
            print(fu)
        rN   r;   r   r   r   test_usedInFunction  rb   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)
        r8   r9   r:   rL   r;   r   r   r   test_shadowedByParameter  s   zTest.test_shadowedByParameterc                 C   r`   )Nz	fu = NonerN   r;   r   r   r   test_newAssignment  rb   zTest.test_newAssignmentc                 C   s   |  d |  dtj d S )Nzimport fu; fu.bar.bazzimport fu; "bar".fu.bazr7   r;   r   r   r   test_usedInGetattr  s   
zTest.test_usedInGetattrc                 C   r`   )Nzimport fu; print(fu.bar[1:])rN   r;   r   r   r   test_usedInSlice  rb   zTest.test_usedInSlicec                 C   r`   )Nz6
        import fu
        if True: print(fu)
        rN   r;   r   r   r   test_usedInIfBody  rb   zTest.test_usedInIfBodyc                 C   r`   )Nz/
        import fu
        if fu: pass
        rN   r;   r   r   r   test_usedInIfConditional  rb   zTest.test_usedInIfConditionalc                 C   r`   )NzH
        import fu
        if False: pass
        elif fu: pass
        rN   r;   r   r   r   test_usedInElifConditional  rb   zTest.test_usedInElifConditionalc                 C   r`   )NzJ
        import fu
        if False: pass
        else: print(fu)
        rN   r;   r   r   r   test_usedInElse  rb   zTest.test_usedInElsec                 C   r`   )Nzimport fu; fu.bar()rN   r;   r   r   r   test_usedInCall  rb   zTest.test_usedInCallc                 C   r`   )NzC
        import fu
        class bar:
            bar = fu
        rN   r;   r   r   r   test_usedInClass  rb   zTest.test_usedInClassc                 C   r`   )NzO
        import fu
        class bar(object, fu.baz):
            pass
        rN   r;   r   r   r   test_usedInClassBase  rb   zTest.test_usedInClassBasec                 C   r`   )NzR
        import fu
        def bleh():
            pass
        print(fu)
        rN   r;   r   r   r   test_notUsedInNestedScope  rb   zTest.test_notUsedInNestedScopec                 C   r`   )NzN
        import fu
        for bar in range(9):
            print(fu)
        rN   r;   r   r   r   test_usedInFor  rb   zTest.test_usedInForc                 C   r`   )Nzn
        import fu
        for bar in range(10):
            pass
        else:
            print(fu)
        rN   r;   r   r   r   test_usedInForElse  rb   zTest.test_usedInForElsec                 C   rc   )NzH
        import fu
        for fu in range(2):
            pass
        r8   r9   ImportShadowedByLoopVarr;   r   r   r   test_redefinedByFor  ri   zTest.test_redefinedByForc                 C   r6   )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  rY   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   r`   )NzD
        import fu
        def fun():
            return fu
        rN   r;   r   r   r   test_usedInReturn	  rb   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.barrN   r;   r   r   r   test_usedInOperators  s   













zTest.test_usedInOperatorsc                 C   r`   )Nzimport fu; assert fu.barrN   r;   r   r   r   test_usedInAssert!  rb   zTest.test_usedInAssertc                 C   r`   )Nzimport fu; fu.bar[1]rN   r;   r   r   r   test_usedInSubscript$  rb   zTest.test_usedInSubscriptc                 C   rP   )Nzimport fu; fu and Falsezimport fu; fu or Falsezimport fu; not fu.barrN   r;   r   r   r   test_usedInLogic'  rR   zTest.test_usedInLogicc                 C   r`   )Nzimport fu; [fu]rN   r;   r   r   r   test_usedInList,  rb   zTest.test_usedInListc                 C   r`   )Nzimport fu; (fu,)rN   r;   r   r   r   test_usedInTuple/  rb   zTest.test_usedInTuplec                 C   r`   Nz@
        import fu
        try: fu
        except: pass
        rN   r;   r   r   r   test_usedInTry2  rb   zTest.test_usedInTryc                 C   r`   r   rN   r;   r   r   r   test_usedInExcept9  rb   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
        )r9   rL   appendUnusedVariabler8   )r   expectedr   r   r   test_redefinedByExcept@  s
   zTest.test_redefinedByExceptc                 C   r`   )Nz0
        import fu
        raise fu.bar
        rN   r;   r   r   r   test_usedInRaiseJ  rb   zTest.test_usedInRaisec                 C   r`   )NzC
        import fu
        def gen():
            yield fu
        rN   r;   r   r   r   test_usedInYieldP  rb   zTest.test_usedInYieldc                 C      |  d |  d d S )Nzimport fu; {fu:None}zimport fu; {1:fu}rN   r;   r   r   r   test_usedInDictW     
zTest.test_usedInDictc                 C   r`   )NzC
        import fu
        def f(bar=fu):
            pass
        rN   r;   r   r   r   test_usedInParameterDefault[  rb   z Test.test_usedInParameterDefaultc                 C   r`   )Nzimport fu; fu.bar = 1rN   r;   r   r   r   test_usedInAttributeAssignb  rb   zTest.test_usedInAttributeAssignc                 C   r`   )Nzimport fu; fu.bar(stuff=fu)rN   r;   r   r   r   test_usedInKeywordArge  rb   zTest.test_usedInKeywordArgc                 C   r   )Nzimport fu; bar=fuzimport fu; n=0; n+=furN   r;   r   r   r   test_usedInAssignmenth  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]rN   r;   r   r   r   test_usedInListCompl  r   zTest.test_usedInListCompc                 C   r   )NzA
        import fu
        try: pass
        finally: fu
        zA
        import fu
        try: fu
        finally: pass
        rN   r;   r   r   r   test_usedInTryFinallyp     
zTest.test_usedInTryFinallyc                 C   r   )Nz;
        import fu
        while 0:
            fu
        z2
        import fu
        while fu: pass
        rN   r;   r   r   r   test_usedInWhile}  r   zTest.test_usedInWhilec                 C   r6   )zt
        A 'global' statement shadowing an unused import should not prevent it
        from being reported.
        z6
        import fu
        def f(): global fu
        Nr7   r;   r   r   r   test_usedInGlobal  s   zTest.test_usedInGlobalc                 C   rZ   )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()
        NrN   r;   r   r   r   test_usedAndGlobal  r\   zTest.test_usedAndGlobalc                 C   rZ   )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()
        NrN   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; %srN   )r   	exec_stmtr   r   r   test_usedInExec  s   zTest.test_usedInExecc                 C   r`   )Nzimport fu; lambda: furN   r;   r   r   r   test_usedInLambda  rb   zTest.test_usedInLambdac                 C   rv   )Nzimport fu; lambda fu: fuzimport fu; lambda fu: fu
fu()rw   r;   r   r   r   test_shadowedByLambda  s   zTest.test_shadowedByLambdac                 C   r`   )Nzimport fu; "meow"[::fu]rN   r;   r   r   r   test_usedInSliceObj  rb   zTest.test_usedInSliceObjc                 C   s   |  dtjtj d S )Nz=
        def bar():
            import fu
        fu
        )r8   r9   r:   rs   r;   r   r   r   test_unusedInNestedScope  s   zTest.test_unusedInNestedScopec                 C   rc   )Nz`
        class bar:
            import fu
            def fun(self):
                fu
        rr   r;   r   r   r   test_methodsDontUseClassScope     z"Test.test_methodsDontUseClassScopec                 C   r`   )NzX
        def a():
            def b():
                fu
            import fu
        rN   r;   r   r   r   test_nestedFunctionsNestScope  rb   z"Test.test_nestedFunctionsNestScopec                 C   r`   )Nz
        def a():
            import fu
            class b:
                def c(self):
                    print(fu)
        rN   r;   r   r   r    test_nestedClassAndFunctionScope  rb   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   rC   )zfu.*Nr8   r9   ImportStarUsedr:   r   rE   
startswithrF   rG   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   rD   r   rC   )z.fu.*from .. import *r$   )r   Nr   rG   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)r8   r9   ImportStarNotPermittedr   rE   rF   rG   r   r   r   test_localImportStar  s   
zTest.test_localImportStarc                 C   rZ   )zP
        If a dotted name is imported and used, no warning is reported.
        z.
        import fu.bar
        fu.bar
        NrN   r;   r   r   r   test_packageImport     zTest.test_packageImportc                 C   r6   )zj
        If a dotted name is imported and not used, an unused import warning is
        reported.
        zimport fu.barNr7   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
        NrV   r;   r   r   r   test_duplicateSubmoduleImport/  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
        NrN   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
        NrN   r;   r   r   r   'test_used_package_with_submodule_importM     
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()
        NrN   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   rC   )zfu.bar      N)r8   r9   r:   r   rE   rF   withDoctestlinenorG   r   r   r   )test_unused_package_with_submodule_importm  s   
z.Test.test_unused_package_with_submodule_importc                 C   rS   )Nzimport fu; fu = fuzimport fu; fu, bar = fuzimport fu; [fu, bar] = fuzimport fu; fu += furN   r;   r   r   r   test_assignRHSFirstz  rU   zTest.test_assignRHSFirstc                 C   r`   )Nzp
        try:
            import fu
        except ImportError:
            import bar as fu
        fu
        rN   r;   r   r   r   test_tryingMultipleImports  rb   zTest.test_tryingMultipleImportsc                 C   r`   )Nz`
        import fu
        def a():
            fu = 3
            return fu
        fu
        rN   r;   r   r   r   test_nonGlobalDoesNotRedefine  rb   z"Test.test_nonGlobalDoesNotRedefinec                 C   r`   )Nz;
        def a():
            fu
        import fu
        rN   r;   r   r   r   test_functionsRunLater  rb   zTest.test_functionsRunLaterc                 C   rc   )NzG
        import fu
        def fu():
            fu
        fu
        rV   r;   r   r   r   test_functionNamesAreBoundNow  r   z"Test.test_functionNamesAreBoundNowc                 C   r`   )Nza = 1; a = 2rN   r;   r   r   r   !test_ignoreNonImportRedefinitions  rb   z&Test.test_ignoreNonImportRedefinitionstodoc                 C   r`   )NzY
        try:
            import fu
        except ImportError:
            pass
        rN   r;   r   r   r   test_importingForImportError     z!Test.test_importingForImportErrorc                 C   rZ   )z0Imports in class scope can be used through self.zf
        class c:
            import i
            def __init__(self):
                self.i
        NrN   r;   r   r   r   test_importedInClass  r   zTest.test_importedInClassc                 C   rZ   )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
        NrN   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
        NrN   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)r8   r9   LateFutureImportr;   r   r   r   test_futureImportFirst  s   zTest.test_futureImportFirstc                 C   rZ   )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
        NrN   r;   r   r   r   test_futureImportUsed  r   zTest.test_futureImportUsedc                 C   r6   )z0Importing undefined names from __future__ fails.z8
        from __future__ import print_statement
        Nr8   r9   FutureFeatureNotDefinedr;   r   r   r   test_futureImportUndefined     zTest.test_futureImportUndefinedc                 C   r6   )z$Importing '*' from __future__ fails.z*
        from __future__ import *
        Nr   r;   r   r   r   test_futureImportStar  r   zTest.test_futureImportStarN)fr>   r?   r@   rB   rJ   rM   rO   rQ   rT   rW   rX   r[   r]   r^   r_   ra   rd   re   rf   rg   rh   rl   rm   rn   ro   rp   rq   rt   ru   rx   ry   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   rA   g   s    	


	 			
		rA   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   rj   )zp
        An C{__all__} definition does not suppress unused import warnings in a
        function scope.
        zQ
        def foo():
            import bar
            __all__ = ["bar"]
        N)r8   r9   r:   r   r;   r   r   r   test_ignoredInFunction  s   z%TestSpecialAll.test_ignoredInFunctionc                 C   r6   )z_
        An C{__all__} definition in a class does not suppress unused import warnings.
        zM
        import bar
        class foo:
            __all__ = ["bar"]
        Nr7   r;   r   r   r   test_ignoredInClass  s   z"TestSpecialAll.test_ignoredInClassc                 C   rc   )Nz:
        import bar
        (__all__,) = ("foo",)
        r7   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",)
        NrN   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r8   r9   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r8   r9   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_assignment1  r   z2TestSpecialAll.test_tuple_concatenation_assignmentc                 C   r`   )NzF
        from foo import bar
        __all__ = [bar.__name__]
        rN   r;   r   r   r   test_all_with_attributes:  rb   z'TestSpecialAll.test_all_with_attributesc                 C   r`   )Nz=
        from foo import bar
        __all__ = [bar]
        rN   r;   r   r   r   test_all_with_names@  r   z"TestSpecialAll.test_all_with_namesc                 C   r`   )Nzs
        from foo import bar
        from bar import baz
        __all__ = [bar.__name__] + [baz.__name__]
        rN   r;   r   r   r   test_all_with_attributes_addedG  rb   z-TestSpecialAll.test_all_with_attributes_addedc                 C   r`   )Nzi
        from foo import bar
        from foo import baz
        __all__ = ['bar', baz.__name__]
        rN   r;   r   r   r   %test_all_mixed_attributes_and_stringsN  rb   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_unboundExportedU  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)r8   r9   r   ImportStarUsager;   r   r   r   test_importStarExportedd  s   z&TestSpecialAll.test_importStarExportedc                 C   rj   )z8Report unused import when not needed to satisfy __all__.zL
        from foolib import *
        a = 1
        __all__ = ['a']
        N)r8   r9   r   r:   r;   r   r   r   test_importStarNotExportedn  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)NrN   r;   r   r   r   test_usedInGenExpv  s   
z TestSpecialAll.test_usedInGenExpc                 C   rj   )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))NrK   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"
        Nrr   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
        Nrr   r;   r   r   r   test_usedAsClassDecorator  r   z(TestSpecialAll.test_usedAsClassDecoratorN)r>   r?   r@   __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)pyflakesr   r9   pyflakes.checkerr   r   r   r   r   pyflakes.test.harnessr   r	   r
   rA   r   r   r   r   r   <module>   s    [       