How to use the dlint.test 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_helpers / test_bad_name_attribute_use.py View on Github external
IS_PYTHON_3_5 = sys.version_info >= (3, 5)


def get_bad_name_attribute_use_implementation(illegal_name_attributes):
    class Cls(dlint.linters.helpers.bad_name_attribute_use.BadNameAttributeUseLinter):
        _code = 'DUOXXX'
        _error_tmpl = 'DUOXXX error message'

        @property
        def illegal_name_attributes(self):
            return illegal_name_attributes

    return Cls()


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

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

        linter = get_bad_name_attribute_use_implementation(
            {
                'foo': [
                    'bar.Baz',
                ],
            }
        )
        linter.visit(python_node)
github duo-labs / dlint / tests / test_bad_pickle_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 TestBadPickleUse(dlint.test.base.BaseTest):

    def test_bad_pickle_usage(self):
        python_node = self.get_ast_node(
            """
            import pickle

            var = 'test'

            pickle.loads(var)

            with open('data.pickle', 'r') as f:
                pickle.load(f)
                up = pickle.Unpickler(f)
                up.load()
            """
        )
github duo-labs / dlint / tests / test_bad_os_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 TestBadOSUse(dlint.test.base.BaseTest):

    def test_bad_os_usage(self):
        python_node = self.get_ast_node(
            """
            import os

            var = 'echo "TEST"'

            os.popen('ls')
            os.popen2('ls')
            os.popen3('ls')
            os.popen4('ls')
            os.system(var)
            os.tempnam()
            os.tmpnam()
            """
github duo-labs / dlint / tests / test_bad_itsdangerous_kwarg_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 TestBadItsDangerousKwargUse(dlint.test.base.BaseTest):

    def test_bad_itsdangerous_kwarg_usage(self):
        python_node = self.get_ast_node(
            """
            import itsdangerous

            itsdangerous.signer.Signer("key", algorithm=itsdangerous.signer.NoneAlgorithm())
            itsdangerous.signer.Signer("key", algorithm=itsdangerous.NoneAlgorithm())
            itsdangerous.Signer("key", algorithm=itsdangerous.NoneAlgorithm())
            itsdangerous.Signer("key", algorithm=itsdangerous.signer.NoneAlgorithm())

            itsdangerous.timed.TimestampSigner("key", algorithm=itsdangerous.signer.NoneAlgorithm())
            itsdangerous.timed.TimestampSigner("key", algorithm=itsdangerous.NoneAlgorithm())
            itsdangerous.TimestampSigner("key", algorithm=itsdangerous.NoneAlgorithm())
            itsdangerous.TimestampSigner("key", algorithm=itsdangerous.signer.NoneAlgorithm())