Python bar.bar() Examples

The following are 30 code examples of bar.bar(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module bar , or try the search function .
Example #1
Source File: test_imports.py    From blackmamba with MIT License 6 votes vote down vote up
def test_usedInOperators(self):
        self.flakes('import fu; 3 + fu.bar')
        self.flakes('import fu; 3 % fu.bar')
        self.flakes('import fu; 3 - fu.bar')
        self.flakes('import fu; 3 * fu.bar')
        self.flakes('import fu; 3 ** fu.bar')
        self.flakes('import fu; 3 / fu.bar')
        self.flakes('import fu; 3 // fu.bar')
        self.flakes('import fu; -fu.bar')
        self.flakes('import fu; ~fu.bar')
        self.flakes('import fu; 1 == fu.bar')
        self.flakes('import fu; 1 | fu.bar')
        self.flakes('import fu; 1 & fu.bar')
        self.flakes('import fu; 1 ^ fu.bar')
        self.flakes('import fu; 1 >> fu.bar')
        self.flakes('import fu; 1 << fu.bar') 
Example #2
Source File: test_imports.py    From pyflakes with MIT License 6 votes vote down vote up
def test_shadowedByForDeep(self):
        """
        Test that shadowing a global name with a for loop variable nested in a
        tuple unpack generates a warning.
        """
        self.flakes('''
        import fu
        fu.bar()
        for (x, y, z, (a, b, c, (fu,))) in ():
            pass
        ''', m.ImportShadowedByLoopVar)
        # Same with a list instead of a tuple
        self.flakes('''
        import fu
        fu.bar()
        for [x, y, z, (a, b, c, (fu,))] in ():
            pass
        ''', m.ImportShadowedByLoopVar) 
Example #3
Source File: test_imports.py    From pyflakes with MIT License 6 votes vote down vote up
def test_usedInOperators(self):
        self.flakes('import fu; 3 + fu.bar')
        self.flakes('import fu; 3 % fu.bar')
        self.flakes('import fu; 3 - fu.bar')
        self.flakes('import fu; 3 * fu.bar')
        self.flakes('import fu; 3 ** fu.bar')
        self.flakes('import fu; 3 / fu.bar')
        self.flakes('import fu; 3 // fu.bar')
        self.flakes('import fu; -fu.bar')
        self.flakes('import fu; ~fu.bar')
        self.flakes('import fu; 1 == fu.bar')
        self.flakes('import fu; 1 | fu.bar')
        self.flakes('import fu; 1 & fu.bar')
        self.flakes('import fu; 1 ^ fu.bar')
        self.flakes('import fu; 1 >> fu.bar')
        self.flakes('import fu; 1 << fu.bar') 
Example #4
Source File: test_imports.py    From pyflakes with MIT License 6 votes vote down vote up
def test_usedAsClassDecorator(self):
        """
        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.
        """
        self.flakes('''
        from interior import decorate
        @decorate
        class foo:
            pass
        ''')

        self.flakes('''
        from interior import decorate
        @decorate("foo")
        class bar:
            pass
        ''')

        self.flakes('''
        @decorate
        class foo:
            pass
        ''', m.UndefinedName) 
Example #5
Source File: test_imports.py    From blackmamba with MIT License 6 votes vote down vote up
def test_unusedImport_relative(self):
        self.flakes('from . import fu', m.UnusedImport)
        self.flakes('from . import fu as baz', m.UnusedImport)
        self.flakes('from .. import fu', m.UnusedImport)
        self.flakes('from ... import fu', m.UnusedImport)
        self.flakes('from .. import fu as baz', m.UnusedImport)
        self.flakes('from .bar import fu', m.UnusedImport)
        self.flakes('from ..bar import fu', m.UnusedImport)
        self.flakes('from ...bar import fu', m.UnusedImport)
        self.flakes('from ...bar import fu as baz', m.UnusedImport)

        checker = self.flakes('from . import fu', m.UnusedImport)

        error = checker.messages[0]
        assert error.message == '%r imported but unused'
        assert error.message_args == ('.fu', )

        checker = self.flakes('from . import fu as baz', m.UnusedImport)

        error = checker.messages[0]
        assert error.message == '%r imported but unused'
        assert error.message_args == ('.fu as baz', ) 
Example #6
Source File: test_imports.py    From pyflakes with MIT License 6 votes vote down vote up
def test_unusedImport_relative(self):
        self.flakes('from . import fu', m.UnusedImport)
        self.flakes('from . import fu as baz', m.UnusedImport)
        self.flakes('from .. import fu', m.UnusedImport)
        self.flakes('from ... import fu', m.UnusedImport)
        self.flakes('from .. import fu as baz', m.UnusedImport)
        self.flakes('from .bar import fu', m.UnusedImport)
        self.flakes('from ..bar import fu', m.UnusedImport)
        self.flakes('from ...bar import fu', m.UnusedImport)
        self.flakes('from ...bar import fu as baz', m.UnusedImport)

        checker = self.flakes('from . import fu', m.UnusedImport)

        error = checker.messages[0]
        assert error.message == '%r imported but unused'
        assert error.message_args == ('.fu', )

        checker = self.flakes('from . import fu as baz', m.UnusedImport)

        error = checker.messages[0]
        assert error.message == '%r imported but unused'
        assert error.message_args == ('.fu as baz', ) 
Example #7
Source File: test_imports.py    From blackmamba with MIT License 6 votes vote down vote up
def test_shadowedByForDeep(self):
        """
        Test that shadowing a global name with a for loop variable nested in a
        tuple unpack generates a warning.
        """
        self.flakes('''
        import fu
        fu.bar()
        for (x, y, z, (a, b, c, (fu,))) in ():
            pass
        ''', m.ImportShadowedByLoopVar)
        # Same with a list instead of a tuple
        self.flakes('''
        import fu
        fu.bar()
        for [x, y, z, (a, b, c, (fu,))] in ():
            pass
        ''', m.ImportShadowedByLoopVar) 
Example #8
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedInParameterDefault(self):
        self.flakes('''
        import fu
        def f(bar=fu):
            pass
        ''') 
Example #9
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedImport_relative(self):
        self.flakes('from . import fu; assert fu')
        self.flakes('from .bar import fu; assert fu')
        self.flakes('from .. import fu; assert fu')
        self.flakes('from ..bar import fu as baz; assert baz') 
Example #10
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_unusedInNestedScope(self):
        self.flakes('''
        def bar():
            import fu
        fu
        ''', m.UnusedImport, m.UndefinedName) 
Example #11
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_shadowedByFor(self):
        """
        Test that shadowing a global name with a for loop variable generates a
        warning.
        """
        self.flakes('''
        import fu
        fu.bar()
        for fu in ():
            pass
        ''', m.ImportShadowedByLoopVar) 
Example #12
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_aliasedImportShadowModule(self):
        """Imported aliases can shadow the source of the import."""
        self.flakes('from moo import fu as moo; moo')
        self.flakes('import fu as fu; fu')
        self.flakes('import fu.bar as fu; fu') 
Example #13
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_aliasedImport(self):
        self.flakes('import fu as FU, bar as FU',
                    m.RedefinedWhileUnused, m.UnusedImport)
        self.flakes('from moo import fu as FU, bar as FU',
                    m.RedefinedWhileUnused, m.UnusedImport) 
Example #14
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedInAssert(self):
        self.flakes('import fu; assert fu.bar') 
Example #15
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedInSubscript(self):
        self.flakes('import fu; fu.bar[1]') 
Example #16
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedInRaise(self):
        self.flakes('''
        import fu
        raise fu.bar
        ''') 
Example #17
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_usedInKeywordArg(self):
        self.flakes('import fu; fu.bar(stuff=fu)') 
Example #18
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_redefinedInNestedFunctionTwice(self):
        """
        Test that shadowing a global name with a nested function definition
        generates a warning.
        """
        self.flakes('''
        import fu
        def bar():
            import fu
            def baz():
                def fu():
                    pass
        ''',
                    m.RedefinedWhileUnused, m.RedefinedWhileUnused,
                    m.UnusedImport, m.UnusedImport) 
Example #19
Source File: test_imports.py    From blackmamba with MIT License 5 votes vote down vote up
def test_unusedImport(self):
        self.flakes('import fu, bar', m.UnusedImport, m.UnusedImport)
        self.flakes('from baz import fu, bar', m.UnusedImport, m.UnusedImport) 
Example #20
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_all_mixed_attributes_and_strings(self):
        self.flakes('''
        from foo import bar
        from foo import baz
        __all__ = ['bar', baz.__name__]
        ''') 
Example #21
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_all_with_names(self):
        # not actually valid, but shouldn't produce a crash
        self.flakes('''
        from foo import bar
        __all__ = [bar]
        ''') 
Example #22
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_all_with_attributes(self):
        self.flakes('''
        from foo import bar
        __all__ = [bar.__name__]
        ''') 
Example #23
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_ignoredInClass(self):
        """
        An C{__all__} definition in a class does not suppress unused import warnings.
        """
        self.flakes('''
        import bar
        class foo:
            __all__ = ["bar"]
        ''', m.UnusedImport) 
Example #24
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_ignoredInFunction(self):
        """
        An C{__all__} definition does not suppress unused import warnings in a
        function scope.
        """
        self.flakes('''
        def foo():
            import bar
            __all__ = ["bar"]
        ''', m.UnusedImport, m.UnusedVariable) 
Example #25
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_futureImportFirst(self):
        """
        __future__ imports must come before anything else.
        """
        self.flakes('''
        x = 5
        from __future__ import division
        ''', m.LateFutureImport)
        self.flakes('''
        from foo import bar
        from __future__ import division
        bar
        ''', m.LateFutureImport) 
Example #26
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_assignRHSFirst(self):
        self.flakes('import fu; fu = fu')
        self.flakes('import fu; fu, bar = fu')
        self.flakes('import fu; [fu, bar] = fu')
        self.flakes('import fu; fu += fu') 
Example #27
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_unused_package_with_submodule_import(self):
        """
        When a package and its submodule are imported, only report once.
        """
        checker = self.flakes('''
        import fu
        import fu.bar
        ''', m.UnusedImport)
        error = checker.messages[0]
        assert error.message == '%r imported but unused'
        assert error.message_args == ('fu.bar', )
        assert error.lineno == 5 if self.withDoctest else 3 
Example #28
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_used_package_with_submodule_import_of_alias(self):
        """
        Usage of package by alias marks submodule imports as used.
        """
        self.flakes('''
        import foo as f
        import foo.bar
        f.bar.do_something()
        ''')

        self.flakes('''
        import foo as f
        import foo.bar.blah
        f.bar.blah.do_something()
        ''') 
Example #29
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_used_package_with_submodule_import(self):
        """
        Usage of package marks submodule imports as used.
        """
        self.flakes('''
        import fu
        import fu.bar
        fu.x
        ''')

        self.flakes('''
        import fu.bar
        import fu
        fu.x
        ''') 
Example #30
Source File: test_imports.py    From pyflakes with MIT License 5 votes vote down vote up
def test_differentSubmoduleImport(self):
        """
        If two different submodules of a package are imported, no duplicate
        import warning is reported for the package.
        """
        self.flakes('''
        import fu.bar, fu.baz
        fu.bar, fu.baz
        ''')
        self.flakes('''
        import fu.bar
        import fu.baz
        fu.bar, fu.baz
        ''')