How to use the dlint.test.base 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_bad_gl_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadGlUse(dlint.test.base.BaseTest):

    def test_bad_gl_usage(self):
        python_node = self.get_ast_node(
            """
            import gl
            """
        )

        linter = dlint.linters.BadGlUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
github duo-labs / dlint / tests / test_bad_sys_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadSysUse(dlint.test.base.BaseTest):

    def test_bad_sys_usage(self):
        python_node = self.get_ast_node(
            """
            import sys

            sys.call_tracing(lambda: 42, ())
            sys.setprofile(lambda: 42)
            sys.settrace(lambda: 42)
            """
        )

        linter = dlint.linters.BadSysUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
github duo-labs / dlint / tests / test_bad_commands_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadCommandsUse(dlint.test.base.BaseTest):

    def test_bad_commands_usage(self):
        python_node = self.get_ast_node(
            """
            import commands
            """
        )

        linter = dlint.linters.BadCommandsUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
github duo-labs / dlint / tests / test_bad_pycrypto_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadPycryptoUse(dlint.test.base.BaseTest):

    def test_bad_pycrypto_usage(self):
        python_node = self.get_ast_node(
            """
            import Crypto
            """
        )

        linter = dlint.linters.BadPycryptoUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
github duo-labs / dlint / tests / test_bad_onelogin_module_attribute_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadOneLoginModuleAttributeUse(dlint.test.base.BaseTest):

    def test_bad_onelogin_module_attribute_usage(self):
        python_node = self.get_ast_node(
            """
            import onelogin.saml2.utils.OneLogin_Saml2_Constants

            onelogin.saml2.utils.OneLogin_Saml2_Constants.SHA1
            onelogin.saml2.utils.OneLogin_Saml2_Constants.RSA_SHA1
            onelogin.saml2.utils.OneLogin_Saml2_Constants.DSA_SHA1
            onelogin.saml2.utils.OneLogin_Saml2_Constants.TRIPLEDES_CBC
            """
        )

        linter = dlint.linters.BadOneLoginModuleAttributeUseLinter()
        linter.visit(python_node)
github duo-labs / dlint / tests / test_bad_popen2_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadPopen2Use(dlint.test.base.BaseTest):

    def test_bad_popen2_usage(self):
        python_node = self.get_ast_node(
            """
            import popen2
            """
        )

        linter = dlint.linters.BadPopen2UseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=2,
                col_offset=0,
github duo-labs / dlint / tests / test_namespace.py View on Github external
from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import pytest

import dlint


class TestNamespace(dlint.test.base.BaseTest):

    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

    def test_basic_from_import(self):
github duo-labs / dlint / tests / test_bad_requests_use.py View on Github external
#!/usr/bin/env python

from __future__ import (
    absolute_import,
    division,
    print_function,
    unicode_literals,
)

import unittest

import dlint


class TestBadRequestsUse(dlint.test.base.BaseTest):

    def test_bad_requests_usage(self):
        python_node = self.get_ast_node(
            """
            import requests

            requests.request(verify=False)
            requests.get(verify=False)
            requests.options(verify=False)
            requests.head(verify=False)
            requests.post(verify=False)
            requests.put(verify=False)
            requests.patch(verify=False)
            requests.delete(verify=False)
            """
        )
github duo-labs / dlint / tests / test_helpers / test_bad_kwarg_use.py View on Github external
import dlint


def get_bad_kwarg_use_implementation(kwargs):
    class Cls(dlint.linters.helpers.bad_kwarg_use.BadKwargUseLinter):
        _code = 'DUOXXX'
        _error_tmpl = 'DUOXXX error message'

        @property
        def kwargs(self):
            return kwargs

    return Cls()


class TestBadKwargUse(dlint.test.base.BaseTest):

    def test_empty(self):
        python_node = self.get_ast_node(
            """
            """
        )

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