How to use the dlint.linters.BadRandomGeneratorUseLinter 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
def test_bad_from_import(self):
        python_node = self.get_ast_node(
            """
            from random import random
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_good_import(self):
        python_node = self.get_ast_node(
            """
            import random

            _generator = random.SystemRandom()

            var1 = _generator.randint(256)
            var2 = random.SystemRandom().randint(256)
            """
        )

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

        result = linter.get_results()
        expected = []

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_bad_attribute_usage(self):
        python_node = self.get_ast_node(
            """
            import random

            var = random.random()
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
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
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_bad_attribute_usage_with_good_usage(self):
        python_node = self.get_ast_node(
            """
            import random

            _generator = random.SystemRandom()

            var1 = _generator.randint(256)
            var2 = random.randint(256)
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_bad_from_import_with_good_import(self):
        python_node = self.get_ast_node(
            """
            from random import SystemRandom, random
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_bad_from_import_with_good_import(self):
        python_node = self.get_ast_node(
            """
            from random import SystemRandom, random
            """
        )

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

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

        assert result == expected
github duo-labs / dlint / tests / test_bad_random_generator_use.py View on Github external
def test_good_from_import(self):
        python_node = self.get_ast_node(
            """
            from random import SystemRandom

            _generator = SystemRandom()

            var1 = _generator.randint(256)
            var2 = SystemRandom().randint(256)
            """
        )

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

        result = linter.get_results()
        expected = []

        assert result == expected