How to use the dlint.namespace.Namespace.from_module_node function in dlint

To help you get started, we’ve selected a few dlint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_basic_import(self):
        python_node = self.get_ast_node(
            """
            import foo
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = namespace.name_imported("foo")
        expected = True

        assert result == expected
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_basic_as_from_import(self):
        python_node = self.get_ast_node(
            """
            from foo import bar as baz
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = namespace.name_imported("baz")
        expected = True

        assert result == expected
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_basic_from_import(self):
        python_node = self.get_ast_node(
            """
            from foo import bar
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = namespace.name_imported("bar")
        expected = True

        assert result == expected
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_from_module_node_unknown_type(self):
        unknown_type = None

        with pytest.raises(TypeError):
            dlint.namespace.Namespace.from_module_node(unknown_type)
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_as_import_mismatch(self):
        python_node = self.get_ast_node(
            """
            import foo as bar
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = namespace.name_imported("foo")
        expected = False

        assert result == expected
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_as_from_import_mismatch(self):
        python_node = self.get_ast_node(
            """
            from foo import bar as baz
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = (
            namespace.name_imported("foo")
            or namespace.name_imported("bar")
        )
        expected = False

        assert result == expected
github duo-labs / dlint / tests / test_namespace.py View on Github external
def test_basic_as_import(self):
        python_node = self.get_ast_node(
            """
            import foo as bar
            """
        )

        namespace = dlint.namespace.Namespace.from_module_node(python_node)

        result = namespace.name_imported("bar")
        expected = True

        assert result == expected
github duo-labs / dlint / dlint / linters / base.py View on Github external
def visit(self, node):
        if not self.namespace:
            # In MultiNodeVisitor runs this will have already been set since
            # the namespace remains the same for each linter. However, during
            # testing or single-linter runs we still need to initialize the
            # namespace for the linter.
            self.namespace = namespace.Namespace.from_module_node(node)

        super(BaseLinter, self).visit(node)