Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bad_compile_usage(self):
python_node = self.get_ast_node(
"""
var = 1
result = compile('var + 1', '', 'eval')
"""
)
linter = dlint.linters.BadCompileUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=4,
col_offset=9,
message=dlint.linters.BadCompileUseLinter._error_tmpl
)
]
assert result == expected
import foo
import bar
"""
)
linter = get_bad_module_use_implementation(["foo", "bar"])
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=2,
col_offset=0,
message=linter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=3,
col_offset=0,
message=linter._error_tmpl
)
]
assert result == expected
linter = dlint.linters.BadPickleUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=0,
message=dlint.linters.BadPickleUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=9,
col_offset=4,
message=dlint.linters.BadPickleUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=10,
col_offset=9,
message=dlint.linters.BadPickleUseLinter._error_tmpl
)
]
assert result == expected
def test_bad_dl_usage(self):
python_node = self.get_ast_node(
"""
import dl
"""
)
linter = dlint.linters.BadDlUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=2,
col_offset=0,
message=dlint.linters.BadDlUseLinter._error_tmpl
)
]
assert result == expected
"""
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
def test_bad_urllib3_module_attribute_usage_from_import(self):
python_node = self.get_ast_node(
"""
from urllib3 import disable_warnings
disable_warnings()
"""
)
linter = dlint.linters.BadUrllib3ModuleAttributeUseLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [
dlint.linters.base.Flake8Result(
lineno=3,
col_offset=0,
message=dlint.linters.BadUrllib3ModuleAttributeUseLinter._error_tmpl
),
]
assert result == expected
dlint.linters.base.Flake8Result(
lineno=13,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=14,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=15,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=16,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=17,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=18,
col_offset=0,
message=dlint.linters.BadDuoClientUseLinter._error_tmpl
),
dlint.linters.base.Flake8Result(
lineno=19,
def get_results(self):
return [
base.Flake8Result(
lineno=node.lineno,
col_offset=node.col_offset,
message=self._error_tmpl
)
for node in self.bad_nodes
]