How to use the dlint.test.base.BaseTest 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_random_generator_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 TestBadRandomGeneratorUse(dlint.test.base.BaseTest):

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

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

        result = linter.get_results()
        expected = []

        assert result == expected

    def test_good_import(self):
github duo-labs / dlint / tests / test_bad_xmlrpc_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 TestBadXmlrpcUse(dlint.test.base.BaseTest):

    def test_bad_xmlrpc_usage(self):
        python_node = self.get_ast_node(
            """
            import SimpleXMLRPCServer

            SimpleXMLRPCServer.register_instance(allow_dotted_names=True)
            """
        )

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

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
github duo-labs / dlint / tests / test_helpers / test_bad_builtin_use.py View on Github external
import dlint


def get_builtin_use_implementation(illegal_builtin):
    class Cls(dlint.linters.helpers.bad_builtin_use.BadBuiltinUseLinter):
        _code = 'DUOXXX'
        _error_tmpl = 'DUOXXX error message'

        @property
        def illegal_builtin(self):
            return illegal_builtin

    return Cls()


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

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

        linter = get_builtin_use_implementation('foo')
        linter.visit(python_node)

        result = linter.get_results()
        expected = []

        assert result == expected

    def test_bad_builtin_usage(self):
github duo-labs / dlint / tests / test_bad_tempfile_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 TestBadTempfileUse(dlint.test.base.BaseTest):

    def test_bad_tempfile_usage(self):
        python_node = self.get_ast_node(
            """
            import tempfile

            tempfile.mktemp()
            """
        )

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

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

import sys
import unittest

import dlint

IS_PYTHON_2 = sys.version_info < (3, 0)


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

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

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

        result = linter.get_results()
        expected = []

        assert result == expected

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

import sys
import unittest

import dlint

IS_PYTHON_3_8 = sys.version_info >= (3, 8)


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

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

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

        result = linter.get_results()
        expected = []

        assert result == expected

    def test_not_inlinecallbacks_decorator(self):
github duo-labs / dlint / tests / test_bad_eval_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 TestBadEvalUse(dlint.test.base.BaseTest):

    def test_bad_eval_usage(self):
        python_node = self.get_ast_node(
            """
            var = 1

            result = eval('var + 1')
            """
        )

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

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
github duo-labs / dlint / tests / test_helpers / test_bad_module_attribute_use.py View on Github external
import dlint


def get_bad_module_attribute_use_implementation(illegal_module_attributes):
    class Cls(dlint.linters.helpers.bad_module_attribute_use.BadModuleAttributeUseLinter):
        _code = 'DUOXXX'
        _error_tmpl = 'DUOXXX error message'

        @property
        def illegal_module_attributes(self):
            return illegal_module_attributes

    return Cls()


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

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

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

        result = linter.get_results()
        expected = []

        assert result == expected

    def test_empty_illegal_module_attributes(self):
github duo-labs / dlint / tests / test_bad_tarfile_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 TestBadTarfileUse(dlint.test.base.BaseTest):

    def test_bad_tarfile_usage(self):
        python_node = self.get_ast_node(
            """
            import tarfile

            def func():
                tf1 = tarfile.TarFile()
                tf2 = tarfile.TarFile.open()
                tf1.extract()
                tf2.extractall()
                tf1.extractall()
                tf2.extract()
            """
        )
github duo-labs / dlint / tests / test_bad_duo_client_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 TestBadDuoClientUse(dlint.test.base.BaseTest):

    def test_bad_duo_client_usage(self):
        python_node = self.get_ast_node(
            """
            import duo_client

            duo_client.Client(ca_certs="HTTP")
            duo_client.Client(ca_certs="DISABLE")
            duo_client.AsyncDuoClient(ca_certs="HTTP")
            duo_client.AsyncDuoClient(ca_certs="DISABLE")
            duo_client.Auth(ca_certs="HTTP")
            duo_client.Auth(ca_certs="DISABLE")
            duo_client.AuthAPI(ca_certs="HTTP")
            duo_client.AuthAPI(ca_certs="DISABLE")
            duo_client.Admin(ca_certs="HTTP")
            duo_client.Admin(ca_certs="DISABLE")