Python foo.baz() Examples

The following are 30 code examples of foo.baz(). 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 foo , or try the search function .
Example #1
Source File: test_flake8_tidy_imports.py    From flake8-tidy-imports with ISC License 6 votes vote down vote up
def test_I250_from_fail_2(flake8dir):
    flake8dir.make_example_py(
        """
        from foo import bar as bar, baz as baz

        bar
        baz
    """
    )
    result = flake8dir.run_flake8()
    assert set(result.out_lines) == {
        (
            "./example.py:1:1: I250 Unnecessary import alias - rewrite as "
            + "'from foo import bar'."
        ),
        (
            "./example.py:1:1: I250 Unnecessary import alias - rewrite as "
            + "'from foo import baz'."
        ),
    }


# I251 
Example #2
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_module_attribute_as_usage(self):
        python_node = self.get_ast_node(
            """
            import foo.bar as baz

            var = 'echo "TEST"'

            baz.qux(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation({'foo.bar': ['qux']})
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #3
Source File: test_other.py    From blackmamba with MIT License 6 votes vote down vote up
def test_withStatementUndefinedInExpression(self):
        """
        An undefined name warning is emitted if a name in the I{test}
        expression of a C{with} statement is undefined.
        """
        self.flakes('''
        from __future__ import with_statement
        with bar as baz:
            pass
        ''', m.UndefinedName)

        self.flakes('''
        from __future__ import with_statement
        with bar as bar:
            pass
        ''', m.UndefinedName) 
Example #4
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_module_attribute_import_from_as_usage(self):
        python_node = self.get_ast_node(
            """
            from foo.bar import baz as qux

            var = 'echo "TEST"'

            qux(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation({'foo.bar': ['baz']})
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #5
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_module_attribute_missing_import_usage(self):
        python_node = self.get_ast_node(
            """
            import baz
            from qux import quine
            from . import xyz

            var = 'echo "TEST"'

            foo = None
            foo.bar(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation({'foo': ['bar']})
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
Example #6
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_module_attribute_usage_nested(self):
        python_node = self.get_ast_node(
            """
            import foo

            var = 'echo "TEST"'

            foo.bar(var).baz()
            """
        )

        linter = get_bad_module_attribute_use_implementation({'foo': ['bar']})
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #7
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_kwargs_present_different_module_path(self):
        python_node = self.get_ast_node(
            """
            import foo
            import boo

            boo.bar.baz(kwarg="test")
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.bar.baz",
                    "kwarg_name": "kwarg",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
Example #8
Source File: test_other.py    From pyflakes with MIT License 6 votes vote down vote up
def test_withStatementUndefinedInExpression(self):
        """
        An undefined name warning is emitted if a name in the I{test}
        expression of a C{with} statement is undefined.
        """
        self.flakes('''
        from __future__ import with_statement
        with bar as baz:
            pass
        ''', m.UndefinedName)

        self.flakes('''
        from __future__ import with_statement
        with bar as bar:
            pass
        ''', m.UndefinedName) 
Example #9
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_kwargs_missing_module_path(self):
        python_node = self.get_ast_node(
            """
            import foo

            foo.bar.baz(kwarg="test")
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.bar.baz",
                    "kwarg_name": "kwarg",
                    "predicate": dlint.tree.kwarg_not_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected 
Example #10
Source File: test_other.py    From Transcrypt with Apache License 2.0 6 votes vote down vote up
def test_withStatementUndefinedInExpression(self):
        """
        An undefined name warning is emitted if a name in the I{test}
        expression of a C{with} statement is undefined.
        """
        self.flakes('''
        from __future__ import with_statement
        with bar as baz:
            pass
        ''', m.UndefinedName)

        self.flakes('''
        from __future__ import with_statement
        with bar as bar:
            pass
        ''', m.UndefinedName) 
Example #11
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_kwargs_multi(self):
        python_node = self.get_ast_node(
            """
            import foo

            foo.bar(kwarg1="test")
            foo.baz(kwarg2="test")
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.bar",
                    "kwarg_name": "kwarg1",
                    "predicate": dlint.tree.kwarg_present,
                },
                {
                    "module_path": "foo.baz",
                    "kwarg_name": "kwarg2",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=5,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #12
Source File: test_pkgutil.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_mixed_namespace(self):
        pkgname = 'foo'
        dirname_0 = self.create_init(pkgname)
        dirname_1 = self.create_init(pkgname)
        self.create_submodule(dirname_0, pkgname, 'bar', 0)
        # Turn this into a PEP 420 namespace package
        os.unlink(os.path.join(dirname_0, pkgname, '__init__.py'))
        self.create_submodule(dirname_1, pkgname, 'baz', 1)
        import foo.bar
        import foo.baz
        # Ensure we read the expected values
        self.assertEqual(foo.bar.value, 0)
        self.assertEqual(foo.baz.value, 1)

        # Ensure the path is set up correctly
        self.assertEqual(sorted(foo.__path__),
                         sorted([os.path.join(dirname_0, pkgname),
                                 os.path.join(dirname_1, pkgname)]))

        # Cleanup
        shutil.rmtree(dirname_0)
        shutil.rmtree(dirname_1)
        del sys.path[0]
        del sys.path[0]
        del sys.modules['foo']
        del sys.modules['foo.bar']
        del sys.modules['foo.baz']

    # XXX: test .pkg files 
Example #13
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_augmentedAssignmentImportedFunctionCall(self):
        """
        Consider a function that is called on the right part of an
        augassign operation to be used.
        """
        self.flakes('''
        from foo import bar
        baz = 0
        baz += bar()
        ''') 
Example #14
Source File: test_flake8_comprehensions.py    From flake8-comprehensions with ISC License 5 votes vote down vote up
def test_it_does_not_crash_on_attribute_functions(flake8dir):
    flake8dir.make_example_py(
        """
        import foo
        bar = foo.baz(x + 1 for x in range(10))
    """
    )
    result = flake8dir.run_flake8()
    assert result.out_lines == []


# C408 
Example #15
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_multiple_bad_attributes_usage(self):
        python_node = self.get_ast_node(
            """
            import foo

            var = 'echo "TEST"'

            foo.bar(var)
            foo.baz(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation(
            {'foo': ['bar', 'baz']}
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #16
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_multiple_bad_modules_usage(self):
        python_node = self.get_ast_node(
            """
            import foo
            import baz

            var = 'echo "TEST"'

            foo.bar(var)
            baz.qux(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation(
            {'foo': ['bar'], 'baz': ['qux']}
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=7,
                col_offset=0,
                message=linter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=8,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #17
Source File: test_bad_module_attribute_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_multiple_module_depth_usage(self):
        python_node = self.get_ast_node(
            """
            import foo.bar.baz

            var = 'echo "TEST"'

            foo.bar.baz.qux(var)
            """
        )

        linter = get_bad_module_attribute_use_implementation(
            {'foo.bar.baz': ['qux']}
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=linter._error_tmpl
            ),
        ]

        assert result == expected 
Example #18
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_withStatementNameDefinedInBody(self):
        """
        A name defined in the body of a C{with} statement can be used after
        the body ends without warning.
        """
        self.flakes('''
        from __future__ import with_statement
        with open('foo') as bar:
            baz = 10
        baz
        ''') 
Example #19
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_withStatementUndefinedInside(self):
        """
        An undefined name warning is emitted if a name is used inside the
        body of a C{with} statement without first being bound.
        """
        self.flakes('''
        from __future__ import with_statement
        with open('foo') as bar:
            baz
        ''', m.UndefinedName) 
Example #20
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_ifexp(self):
        """
        Test C{foo if bar else baz} statements.
        """
        self.flakes("a = 'moo' if True else 'oink'")
        self.flakes("a = foo if True else 'oink'", m.UndefinedName)
        self.flakes("a = 'moo' if True else bar", m.UndefinedName) 
Example #21
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_kwargs_nested_calls(self):
        python_node = self.get_ast_node(
            """
            from foo import Bar

            Bar.baz(kwarg="test")()()
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.Bar.baz",
                    "kwarg_name": "kwarg",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #22
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_kwargs_subscript_calls(self):
        python_node = self.get_ast_node(
            """
            from foo import Bar

            Bar.baz(kwarg="test")["qux"]()
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.Bar.baz",
                    "kwarg_name": "kwarg",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #23
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_withStatementTupleNamesRedefined(self):
        """
        A redefined name warning is emitted if a name bound by an import is
        rebound by one of the names defined by the tuple-unpacking form of a
        C{with} statement.
        """
        self.flakes('''
        from __future__ import with_statement
        import bar
        with open('foo') as (bar, baz):
            pass
        ''', m.RedefinedWhileUnused) 
Example #24
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_withStatementListNames(self):
        """
        No warnings are emitted for using any of the list of names defined by a
        C{with} statement within the suite or afterwards.
        """
        self.flakes('''
        from __future__ import with_statement
        with open('foo') as [bar, baz]:
            bar, baz
        bar, baz
        ''') 
Example #25
Source File: test_bad_kwarg_use.py    From dlint with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_kwargs_present_from_module_path(self):
        python_node = self.get_ast_node(
            """
            from foo import bar

            bar.baz(kwarg="test")
            """
        )

        linter = get_bad_kwarg_use_implementation(
            [
                {
                    "module_path": "foo.bar.baz",
                    "kwarg_name": "kwarg",
                    "predicate": dlint.tree.kwarg_present,
                },
            ]
        )
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=0,
                message=linter._error_tmpl
            )
        ]

        assert result == expected 
Example #26
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_withStatementTupleNames(self):
        """
        No warnings are emitted for using any of the tuple of names defined by
        a C{with} statement within the suite or afterwards.
        """
        self.flakes('''
        from __future__ import with_statement
        with open('foo') as (bar, baz):
            bar, baz
        bar, baz
        ''') 
Example #27
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_attrAugmentedAssignment(self):
        """
        Augmented assignment of attributes is supported.
        We don't care about attr refs.
        """
        self.flakes('''
        foo = None
        foo.bar += foo.baz
        ''') 
Example #28
Source File: test_other.py    From Transcrypt with Apache License 2.0 5 votes vote down vote up
def test_doubleClosedOver(self):
        """
        Don't warn when the assignment is used in an inner function, even if
        that inner function itself is in an inner function.
        """
        self.flakes('''
        def barMaker():
            foo = 5
            def bar():
                def baz():
                    return foo
            return bar
        ''') 
Example #29
Source File: test_other.py    From pyflakes with MIT License 5 votes vote down vote up
def test_withStatementNameDefinedInBody(self):
        """
        A name defined in the body of a C{with} statement can be used after
        the body ends without warning.
        """
        self.flakes('''
        from __future__ import with_statement
        with open('foo') as bar:
            baz = 10
        baz
        ''') 
Example #30
Source File: test_pkgutil.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_simple(self):
        pkgname = 'foo'
        dirname_0 = self.create_init(pkgname)
        dirname_1 = self.create_init(pkgname)
        self.create_submodule(dirname_0, pkgname, 'bar', 0)
        self.create_submodule(dirname_1, pkgname, 'baz', 1)
        import foo.bar
        import foo.baz
        # Ensure we read the expected values
        self.assertEqual(foo.bar.value, 0)
        self.assertEqual(foo.baz.value, 1)

        # Ensure the path is set up correctly
        self.assertEqual(sorted(foo.__path__),
                         sorted([os.path.join(dirname_0, pkgname),
                                 os.path.join(dirname_1, pkgname)]))

        # Cleanup
        shutil.rmtree(dirname_0)
        shutil.rmtree(dirname_1)
        del sys.path[0]
        del sys.path[0]
        del sys.modules['foo']
        del sys.modules['foo.bar']
        del sys.modules['foo.baz']


    # Another awful testing hack to be cleaned up once the test_runpy
    # helpers are factored out to a common location