The following issues were found
Lib/test/test_resource.py
31 issues
Line: 25
Column: 19
"setting RLIMIT_FSIZE is not supported on VxWorks")
def test_fsize_ismax(self):
try:
(cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
except AttributeError:
pass
else:
# RLIMIT_FSIZE should be RLIM_INFINITY, which will be a really big
# number on a platform with large file support. On these platforms,
Reported by Pylint.
Line: 39
Column: 19
def test_fsize_enforced(self):
try:
(cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
except AttributeError:
pass
else:
# Check to see what happens when the RLIMIT_FSIZE is small. Some
# versions of Python were terminated by an uncaught SIGXFSZ, but
Reported by Pylint.
Line: 67
Column: 29
# does eventually. Try flushing several times in
# an attempt to ensure the file is really synced and
# the exception raised.
for i in range(5):
time.sleep(.1)
f.flush()
except OSError:
if not limit_set:
raise
Reported by Pylint.
Line: 88
Column: 14
# Be sure that setrlimit is checking for really large values
too_big = 10**50
try:
(cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
except AttributeError:
pass
else:
try:
resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
Reported by Pylint.
Line: 88
Column: 19
# Be sure that setrlimit is checking for really large values
too_big = 10**50
try:
(cur, max) = resource.getrlimit(resource.RLIMIT_FSIZE)
except AttributeError:
pass
else:
try:
resource.setrlimit(resource.RLIMIT_FSIZE, (too_big, max))
Reported by Pylint.
Line: 104
Column: 9
def test_getrusage(self):
self.assertRaises(TypeError, resource.getrusage)
self.assertRaises(TypeError, resource.getrusage, 42, 42)
usageself = resource.getrusage(resource.RUSAGE_SELF)
usagechildren = resource.getrusage(resource.RUSAGE_CHILDREN)
# May not be available on all systems.
try:
usageboth = resource.getrusage(resource.RUSAGE_BOTH)
except (ValueError, AttributeError):
Reported by Pylint.
Line: 105
Column: 9
self.assertRaises(TypeError, resource.getrusage)
self.assertRaises(TypeError, resource.getrusage, 42, 42)
usageself = resource.getrusage(resource.RUSAGE_SELF)
usagechildren = resource.getrusage(resource.RUSAGE_CHILDREN)
# May not be available on all systems.
try:
usageboth = resource.getrusage(resource.RUSAGE_BOTH)
except (ValueError, AttributeError):
pass
Reported by Pylint.
Line: 108
Column: 13
usagechildren = resource.getrusage(resource.RUSAGE_CHILDREN)
# May not be available on all systems.
try:
usageboth = resource.getrusage(resource.RUSAGE_BOTH)
except (ValueError, AttributeError):
pass
try:
usage_thread = resource.getrusage(resource.RUSAGE_THREAD)
except (ValueError, AttributeError):
Reported by Pylint.
Line: 112
Column: 13
except (ValueError, AttributeError):
pass
try:
usage_thread = resource.getrusage(resource.RUSAGE_THREAD)
except (ValueError, AttributeError):
pass
# Issue 6083: Reference counting bug
@unittest.skipIf(sys.platform == "vxworks",
Reported by Pylint.
Line: 121
Column: 13
"setting RLIMIT_CPU is not supported on VxWorks")
def test_setrusage_refcount(self):
try:
limits = resource.getrlimit(resource.RLIMIT_CPU)
except AttributeError:
pass
else:
class BadSequence:
def __len__(self):
Reported by Pylint.
Lib/test/test_select.py
31 issues
Line: 77
Column: 17
print('EOF')
break
continue
self.fail('Unexpected return values from select():',
rfd, wfd, xfd)
# Issue 16230: Crash on select resized list
def test_select_mutated(self):
a = []
Reported by Pylint.
Line: 94
Column: 61
support.check_disallow_instantiation(self, type(select.poll()))
if hasattr(select, 'devpoll'):
support.check_disallow_instantiation(self, type(select.devpoll()))
def tearDownModule():
support.reap_children()
if __name__ == "__main__":
Reported by Pylint.
Line: 1
Column: 1
import errno
import os
import select
import subprocess
import sys
import textwrap
import unittest
from test import support
Reported by Pylint.
Line: 4
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
import errno
import os
import select
import subprocess
import sys
import textwrap
import unittest
from test import support
Reported by Bandit.
Line: 12
Column: 1
@unittest.skipIf((sys.platform[:3]=='win'),
"can't easily test on this system")
class SelectTestCase(unittest.TestCase):
class Nope:
pass
class Almost:
Reported by Pylint.
Line: 14
Column: 5
"can't easily test on this system")
class SelectTestCase(unittest.TestCase):
class Nope:
pass
class Almost:
def fileno(self):
return 'fileno'
Reported by Pylint.
Line: 14
Column: 5
"can't easily test on this system")
class SelectTestCase(unittest.TestCase):
class Nope:
pass
class Almost:
def fileno(self):
return 'fileno'
Reported by Pylint.
Line: 17
Column: 5
class Nope:
pass
class Almost:
def fileno(self):
return 'fileno'
def test_error_conditions(self):
self.assertRaises(TypeError, select.select, 1, 2, 3)
Reported by Pylint.
Line: 17
Column: 5
class Nope:
pass
class Almost:
def fileno(self):
return 'fileno'
def test_error_conditions(self):
self.assertRaises(TypeError, select.select, 1, 2, 3)
Reported by Pylint.
Line: 18
Column: 9
pass
class Almost:
def fileno(self):
return 'fileno'
def test_error_conditions(self):
self.assertRaises(TypeError, select.select, 1, 2, 3)
self.assertRaises(TypeError, select.select, [self.Nope()], [], [])
Reported by Pylint.
Lib/turtledemo/planet_and_moon.py
31 issues
Line: 20
Column: 1
mouse over the scrollbar of the canvas.
"""
from turtle import Shape, Turtle, mainloop, Vec2D as Vec
G = 8
class GravSys(object):
def __init__(self):
Reported by Pylint.
Line: 33
Column: 13
for p in self.planets:
p.init()
def start(self):
for i in range(10000):
self.t += self.dt
for p in self.planets:
p.step()
class Star(Turtle):
Reported by Pylint.
Line: 51
Column: 9
self.pendown()
def init(self):
dt = self.gravSys.dt
self.a = self.acc()
self.v = self.v + 0.5*dt*self.a
def acc(self):
a = Vec(0,0)
for planet in self.gravSys.planets:
if planet != self:
Reported by Pylint.
Line: 65
Column: 9
self.setpos(self.pos() + dt*self.v)
if self.gravSys.planets.index(self) != 0:
self.setheading(self.towards(self.gravSys.planets[0]))
self.a = self.acc()
self.v = self.v + dt*self.a
## create compound yellow/blue turtleshape for planets
def main():
Reported by Pylint.
Line: 24
Column: 1
G = 8
class GravSys(object):
def __init__(self):
self.planets = []
self.t = 0
self.dt = 0.01
def init(self):
Reported by Pylint.
Line: 24
Column: 1
G = 8
class GravSys(object):
def __init__(self):
self.planets = []
self.t = 0
self.dt = 0.01
def init(self):
Reported by Pylint.
Line: 27
Column: 9
class GravSys(object):
def __init__(self):
self.planets = []
self.t = 0
self.dt = 0.01
def init(self):
for p in self.planets:
p.init()
def start(self):
Reported by Pylint.
Line: 28
Column: 9
def __init__(self):
self.planets = []
self.t = 0
self.dt = 0.01
def init(self):
for p in self.planets:
p.init()
def start(self):
for i in range(10000):
Reported by Pylint.
Line: 29
Column: 5
self.planets = []
self.t = 0
self.dt = 0.01
def init(self):
for p in self.planets:
p.init()
def start(self):
for i in range(10000):
self.t += self.dt
Reported by Pylint.
Line: 30
Column: 13
self.t = 0
self.dt = 0.01
def init(self):
for p in self.planets:
p.init()
def start(self):
for i in range(10000):
self.t += self.dt
for p in self.planets:
Reported by Pylint.
Tools/freeze/checkextensions_win32.py
31 issues
Line: 131
Column: 15
# print "Processing", dsp
# For now, only support
ret = []
dsp_path, dsp_name = os.path.split(dsp)
try:
with open(dsp, "r") as fp:
lines = fp.readlines()
except IOError as msg:
sys.stderr.write("%s: %s\n" % (dsp, msg))
Reported by Pylint.
Line: 25
Column: 1
but an obvious enhancement would be to provide command line options.
"""
import os, sys
try:
import win32api
except ImportError:
win32api = None # User has already been warned
Reported by Pylint.
Line: 37
Column: 9
def __init__(self, name, sourceFiles):
self.name = name
# A list of strings defining additional compiler options.
self.sourceFiles = sourceFiles
# A list of special compiler options to be applied to
# all source modules in this extension.
self.compilerOptions = []
# A list of .lib files the final .EXE will need.
self.linkerLibs = []
Reported by Pylint.
Line: 40
Column: 9
self.sourceFiles = sourceFiles
# A list of special compiler options to be applied to
# all source modules in this extension.
self.compilerOptions = []
# A list of .lib files the final .EXE will need.
self.linkerLibs = []
def GetSourceFiles(self):
return self.sourceFiles
Reported by Pylint.
Line: 42
Column: 9
# all source modules in this extension.
self.compilerOptions = []
# A list of .lib files the final .EXE will need.
self.linkerLibs = []
def GetSourceFiles(self):
return self.sourceFiles
def AddCompilerOption(self, option):
Reported by Pylint.
Line: 44
Column: 5
# A list of .lib files the final .EXE will need.
self.linkerLibs = []
def GetSourceFiles(self):
return self.sourceFiles
def AddCompilerOption(self, option):
self.compilerOptions.append(option)
def GetCompilerOptions(self):
Reported by Pylint.
Line: 44
Column: 5
# A list of .lib files the final .EXE will need.
self.linkerLibs = []
def GetSourceFiles(self):
return self.sourceFiles
def AddCompilerOption(self, option):
self.compilerOptions.append(option)
def GetCompilerOptions(self):
Reported by Pylint.
Line: 47
Column: 5
def GetSourceFiles(self):
return self.sourceFiles
def AddCompilerOption(self, option):
self.compilerOptions.append(option)
def GetCompilerOptions(self):
return self.compilerOptions
def AddLinkerLib(self, lib):
Reported by Pylint.
Line: 47
Column: 5
def GetSourceFiles(self):
return self.sourceFiles
def AddCompilerOption(self, option):
self.compilerOptions.append(option)
def GetCompilerOptions(self):
return self.compilerOptions
def AddLinkerLib(self, lib):
Reported by Pylint.
Line: 49
Column: 5
def AddCompilerOption(self, option):
self.compilerOptions.append(option)
def GetCompilerOptions(self):
return self.compilerOptions
def AddLinkerLib(self, lib):
self.linkerLibs.append(lib)
def GetLinkerLibs(self):
Reported by Pylint.
Modules/_struct.c
31 issues
Line: 423
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_short(_structmodulestate *state, const char *p, const formatdef *f)
{
short x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLong((long)x);
}
static PyObject *
nu_ushort(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 431
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_ushort(_structmodulestate *state, const char *p, const formatdef *f)
{
unsigned short x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLong((long)x);
}
static PyObject *
nu_int(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 439
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_int(_structmodulestate *state, const char *p, const formatdef *f)
{
int x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLong((long)x);
}
static PyObject *
nu_uint(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 447
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_uint(_structmodulestate *state, const char *p, const formatdef *f)
{
unsigned int x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromUnsignedLong((unsigned long)x);
}
static PyObject *
nu_long(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 455
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_long(_structmodulestate *state, const char *p, const formatdef *f)
{
long x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLong(x);
}
static PyObject *
nu_ulong(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 463
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_ulong(_structmodulestate *state, const char *p, const formatdef *f)
{
unsigned long x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromUnsignedLong(x);
}
static PyObject *
nu_ssize_t(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 471
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_ssize_t(_structmodulestate *state, const char *p, const formatdef *f)
{
Py_ssize_t x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromSsize_t(x);
}
static PyObject *
nu_size_t(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 479
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_size_t(_structmodulestate *state, const char *p, const formatdef *f)
{
size_t x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromSize_t(x);
}
static PyObject *
nu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 487
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{
long long x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLongLong(x);
}
static PyObject *
nu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Line: 495
Column: 5
CWE codes:
120
Suggestion:
Make sure destination can always hold the source data
nu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{
unsigned long long x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromUnsignedLongLong(x);
}
static PyObject *
nu_bool(_structmodulestate *state, const char *p, const formatdef *f)
Reported by FlawFinder.
Lib/unittest/async_case.py
31 issues
Line: 5
Column: 1
import inspect
import warnings
from .case import TestCase
class IsolatedAsyncioTestCase(TestCase):
# Names intentionally have a long prefix
Reported by Pylint.
Line: 110
Column: 20
fut.set_result(ret)
except (SystemExit, KeyboardInterrupt):
raise
except (BaseException, asyncio.CancelledError) as ex:
if not fut.cancelled():
fut.set_exception(ex)
def _setupAsyncioLoop(self):
assert self._asyncioTestLoop is None
Reported by Pylint.
Line: 121
Column: 9
loop.set_debug(True)
self._asyncioTestLoop = loop
fut = loop.create_future()
self._asyncioCallsTask = loop.create_task(self._asyncioLoopRunner(fut))
loop.run_until_complete(fut)
def _tearDownAsyncioLoop(self):
assert self._asyncioTestLoop is not None
loop = self._asyncioTestLoop
Reported by Pylint.
Line: 1
Column: 1
import asyncio
import inspect
import warnings
from .case import TestCase
class IsolatedAsyncioTestCase(TestCase):
Reported by Pylint.
Line: 9
Column: 1
class IsolatedAsyncioTestCase(TestCase):
# Names intentionally have a long prefix
# to reduce a chance of clashing with user-defined attributes
# from inherited test case
#
# The class doesn't call loop.run_until_complete(self.setUp()) and family
Reported by Pylint.
Line: 35
Column: 5
# should reset a policy in every test module
# by calling asyncio.set_event_loop_policy(None) in tearDownModule()
def __init__(self, methodName='runTest'):
super().__init__(methodName)
self._asyncioTestLoop = None
self._asyncioCallsQueue = None
async def asyncSetUp(self):
Reported by Pylint.
Line: 37
Column: 9
def __init__(self, methodName='runTest'):
super().__init__(methodName)
self._asyncioTestLoop = None
self._asyncioCallsQueue = None
async def asyncSetUp(self):
pass
Reported by Pylint.
Line: 38
Column: 9
def __init__(self, methodName='runTest'):
super().__init__(methodName)
self._asyncioTestLoop = None
self._asyncioCallsQueue = None
async def asyncSetUp(self):
pass
async def asyncTearDown(self):
Reported by Pylint.
Line: 40
Column: 5
self._asyncioTestLoop = None
self._asyncioCallsQueue = None
async def asyncSetUp(self):
pass
async def asyncTearDown(self):
pass
Reported by Pylint.
Line: 40
Column: 5
self._asyncioTestLoop = None
self._asyncioCallsQueue = None
async def asyncSetUp(self):
pass
async def asyncTearDown(self):
pass
Reported by Pylint.
Lib/test/test_peg_generator/test_first_sets.py
31 issues
Line: 8
Column: 5
test_tools.skip_if_missing("peg_generator")
with test_tools.imports_under_tool("peg_generator"):
from pegen.grammar_parser import GeneratedParser as GrammarParser
from pegen.testutil import parse_string
from pegen.first_sets import FirstSetCalculator
from pegen.grammar import Grammar
Reported by Pylint.
Line: 9
Column: 5
test_tools.skip_if_missing("peg_generator")
with test_tools.imports_under_tool("peg_generator"):
from pegen.grammar_parser import GeneratedParser as GrammarParser
from pegen.testutil import parse_string
from pegen.first_sets import FirstSetCalculator
from pegen.grammar import Grammar
class TestFirstSets(unittest.TestCase):
Reported by Pylint.
Line: 10
Column: 5
with test_tools.imports_under_tool("peg_generator"):
from pegen.grammar_parser import GeneratedParser as GrammarParser
from pegen.testutil import parse_string
from pegen.first_sets import FirstSetCalculator
from pegen.grammar import Grammar
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
Reported by Pylint.
Line: 11
Column: 5
from pegen.grammar_parser import GeneratedParser as GrammarParser
from pegen.testutil import parse_string
from pegen.first_sets import FirstSetCalculator
from pegen.grammar import Grammar
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
grammar: Grammar = parse_string(grammar_source, GrammarParser)
Reported by Pylint.
Line: 235
Column: 3
)
def test_nasty_left_recursion(self) -> None:
# TODO: Validate this
grammar = """
start: target '='
target: maybe '+' | NAME
maybe: maybe '-' | target
"""
Reported by Pylint.
Line: 1
Column: 1
import unittest
from test import test_tools
from typing import Dict, Set
test_tools.skip_if_missing("peg_generator")
with test_tools.imports_under_tool("peg_generator"):
from pegen.grammar_parser import GeneratedParser as GrammarParser
from pegen.testutil import parse_string
Reported by Pylint.
Line: 14
Column: 1
from pegen.grammar import Grammar
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
grammar: Grammar = parse_string(grammar_source, GrammarParser)
return FirstSetCalculator(grammar.rules).calculate()
def test_alternatives(self) -> None:
Reported by Pylint.
Line: 14
Column: 1
from pegen.grammar import Grammar
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
grammar: Grammar = parse_string(grammar_source, GrammarParser)
return FirstSetCalculator(grammar.rules).calculate()
def test_alternatives(self) -> None:
Reported by Pylint.
Line: 15
Column: 5
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
grammar: Grammar = parse_string(grammar_source, GrammarParser)
return FirstSetCalculator(grammar.rules).calculate()
def test_alternatives(self) -> None:
grammar = """
Reported by Pylint.
Line: 15
Column: 5
class TestFirstSets(unittest.TestCase):
def calculate_first_sets(self, grammar_source: str) -> Dict[str, Set[str]]:
grammar: Grammar = parse_string(grammar_source, GrammarParser)
return FirstSetCalculator(grammar.rules).calculate()
def test_alternatives(self) -> None:
grammar = """
Reported by Pylint.
Lib/test/test_sundry.py
31 issues
Line: 32
Column: 17
import distutils.command.bdist_dumb
if sys.platform.startswith('win') and not platform.win32_is_iot():
import distutils.command.bdist_msi
import distutils.command.bdist
import distutils.command.bdist_rpm
import distutils.command.build_clib
import distutils.command.build_ext
import distutils.command.build
Reported by Pylint.
Line: 32
Column: 1
import distutils.command.bdist_dumb
if sys.platform.startswith('win') and not platform.win32_is_iot():
import distutils.command.bdist_msi
import distutils.command.bdist
import distutils.command.bdist_rpm
import distutils.command.build_clib
import distutils.command.build_ext
import distutils.command.build
Reported by Pylint.
Line: 23
Column: 13
self.fail('{} has tests even though test_sundry claims '
'otherwise'.format(name))
import distutils.bcppcompiler
import distutils.ccompiler
import distutils.cygwinccompiler
import distutils.filelist
import distutils.text_file
import distutils.unixccompiler
Reported by Pylint.
Line: 48
Column: 13
import distutils.command.sdist
import distutils.command.upload
import html.entities
try:
import tty # Not available on Windows
except ImportError:
if support.verbose:
Reported by Pylint.
Line: 51
Column: 17
import html.entities
try:
import tty # Not available on Windows
except ImportError:
if support.verbose:
print("skipping tty")
Reported by Pylint.
Line: 10
Column: 1
from test.support import warnings_helper
import unittest
class TestUntestedModules(unittest.TestCase):
def test_untested_modules_can_be_imported(self):
untested = ('encodings',)
with warnings_helper.check_warnings(quiet=True):
for name in untested:
try:
Reported by Pylint.
Line: 11
Column: 5
import unittest
class TestUntestedModules(unittest.TestCase):
def test_untested_modules_can_be_imported(self):
untested = ('encodings',)
with warnings_helper.check_warnings(quiet=True):
for name in untested:
try:
import_helper.import_module('test.test_{}'.format(name))
Reported by Pylint.
Line: 23
Column: 13
self.fail('{} has tests even though test_sundry claims '
'otherwise'.format(name))
import distutils.bcppcompiler
import distutils.ccompiler
import distutils.cygwinccompiler
import distutils.filelist
import distutils.text_file
import distutils.unixccompiler
Reported by Pylint.
Line: 24
Column: 13
'otherwise'.format(name))
import distutils.bcppcompiler
import distutils.ccompiler
import distutils.cygwinccompiler
import distutils.filelist
import distutils.text_file
import distutils.unixccompiler
Reported by Pylint.
Line: 25
Column: 13
import distutils.bcppcompiler
import distutils.ccompiler
import distutils.cygwinccompiler
import distutils.filelist
import distutils.text_file
import distutils.unixccompiler
import distutils.command.bdist_dumb
Reported by Pylint.
Lib/test/test_importlib/test_read.py
31 issues
Line: 4
Column: 1
import unittest
from importlib import import_module, resources
from . import data01
from .resources import util
class CommonBinaryTests(util.CommonTests, unittest.TestCase):
def execute(self, package, path):
Reported by Pylint.
Line: 5
Column: 1
from importlib import import_module, resources
from . import data01
from .resources import util
class CommonBinaryTests(util.CommonTests, unittest.TestCase):
def execute(self, package, path):
resources.read_binary(package, path)
Reported by Pylint.
Line: 20
Column: 40
class ReadTests:
def test_read_binary(self):
result = resources.read_binary(self.data, 'binary.file')
self.assertEqual(result, b'\0\1\2\3')
def test_read_text_default_encoding(self):
result = resources.read_text(self.data, 'utf-8.file')
self.assertEqual(result, 'Hello, UTF-8 world!\n')
Reported by Pylint.
Line: 21
Column: 9
class ReadTests:
def test_read_binary(self):
result = resources.read_binary(self.data, 'binary.file')
self.assertEqual(result, b'\0\1\2\3')
def test_read_text_default_encoding(self):
result = resources.read_text(self.data, 'utf-8.file')
self.assertEqual(result, 'Hello, UTF-8 world!\n')
Reported by Pylint.
Line: 24
Column: 38
self.assertEqual(result, b'\0\1\2\3')
def test_read_text_default_encoding(self):
result = resources.read_text(self.data, 'utf-8.file')
self.assertEqual(result, 'Hello, UTF-8 world!\n')
def test_read_text_given_encoding(self):
result = resources.read_text(self.data, 'utf-16.file', encoding='utf-16')
self.assertEqual(result, 'Hello, UTF-16 world!\n')
Reported by Pylint.
Line: 25
Column: 9
def test_read_text_default_encoding(self):
result = resources.read_text(self.data, 'utf-8.file')
self.assertEqual(result, 'Hello, UTF-8 world!\n')
def test_read_text_given_encoding(self):
result = resources.read_text(self.data, 'utf-16.file', encoding='utf-16')
self.assertEqual(result, 'Hello, UTF-16 world!\n')
Reported by Pylint.
Line: 28
Column: 38
self.assertEqual(result, 'Hello, UTF-8 world!\n')
def test_read_text_given_encoding(self):
result = resources.read_text(self.data, 'utf-16.file', encoding='utf-16')
self.assertEqual(result, 'Hello, UTF-16 world!\n')
def test_read_text_with_errors(self):
# Raises UnicodeError without the 'errors' argument.
self.assertRaises(UnicodeError, resources.read_text, self.data, 'utf-16.file')
Reported by Pylint.
Line: 29
Column: 9
def test_read_text_given_encoding(self):
result = resources.read_text(self.data, 'utf-16.file', encoding='utf-16')
self.assertEqual(result, 'Hello, UTF-16 world!\n')
def test_read_text_with_errors(self):
# Raises UnicodeError without the 'errors' argument.
self.assertRaises(UnicodeError, resources.read_text, self.data, 'utf-16.file')
result = resources.read_text(self.data, 'utf-16.file', errors='ignore')
Reported by Pylint.
Line: 33
Column: 9
def test_read_text_with_errors(self):
# Raises UnicodeError without the 'errors' argument.
self.assertRaises(UnicodeError, resources.read_text, self.data, 'utf-16.file')
result = resources.read_text(self.data, 'utf-16.file', errors='ignore')
self.assertEqual(
result,
'H\x00e\x00l\x00l\x00o\x00,\x00 '
'\x00U\x00T\x00F\x00-\x001\x006\x00 '
Reported by Pylint.
Line: 33
Column: 62
def test_read_text_with_errors(self):
# Raises UnicodeError without the 'errors' argument.
self.assertRaises(UnicodeError, resources.read_text, self.data, 'utf-16.file')
result = resources.read_text(self.data, 'utf-16.file', errors='ignore')
self.assertEqual(
result,
'H\x00e\x00l\x00l\x00o\x00,\x00 '
'\x00U\x00T\x00F\x00-\x001\x006\x00 '
Reported by Pylint.
Lib/test/test_importlib/test_lazy.py
31 issues
Line: 8
Column: 1
import types
import unittest
from . import util as test_util
class CollectInit:
def __init__(self, *args, **kwargs):
Reported by Pylint.
Line: 17
Column: 27
self.args = args
self.kwargs = kwargs
def exec_module(self, module):
return self
class LazyLoaderFactoryTests(unittest.TestCase):
Reported by Pylint.
Line: 45
Column: 37
loaded = None
source_code = 'attr = 42; __name__ = {!r}'.format(mutated_name)
def find_spec(self, name, path, target=None):
if name != self.module_name:
return None
return util.spec_from_loader(name, util.LazyLoader(self))
def exec_module(self, module):
Reported by Pylint.
Line: 45
Column: 31
loaded = None
source_code = 'attr = 42; __name__ = {!r}'.format(mutated_name)
def find_spec(self, name, path, target=None):
if name != self.module_name:
return None
return util.spec_from_loader(name, util.LazyLoader(self))
def exec_module(self, module):
Reported by Pylint.
Line: 51
Column: 9
return util.spec_from_loader(name, util.LazyLoader(self))
def exec_module(self, module):
exec(self.source_code, module.__dict__)
self.loaded = module
class LazyLoaderTests(unittest.TestCase):
Reported by Pylint.
Line: 51
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html
return util.spec_from_loader(name, util.LazyLoader(self))
def exec_module(self, module):
exec(self.source_code, module.__dict__)
self.loaded = module
class LazyLoaderTests(unittest.TestCase):
Reported by Bandit.
Line: 134
Column: 17
sys.modules[TestingImporter.module_name] = fresh_module
module = self.new_module()
with self.assertRaisesRegex(ValueError, "substituted"):
module.__name__
def test_module_already_in_sys(self):
with test_util.uncache(TestingImporter.module_name):
module = self.new_module()
sys.modules[TestingImporter.module_name] = module
Reported by Pylint.
Line: 141
Column: 13
module = self.new_module()
sys.modules[TestingImporter.module_name] = module
# Force the load; just care that no exception is raised.
module.__name__
if __name__ == '__main__':
unittest.main()
Reported by Pylint.
Line: 1
Column: 1
import importlib
from importlib import abc
from importlib import util
import sys
import types
import unittest
from . import util as test_util
Reported by Pylint.
Line: 11
Column: 1
from . import util as test_util
class CollectInit:
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
Reported by Pylint.