The following issues were found
Tools/ssl/multissltests.py
44 issues
Line: 38
Column: 1
from urllib2 import urlopen, HTTPError
import re
import shutil
import string
import subprocess
import sys
import tarfile
Reported by Pylint.
Line: 232
Column: 19
return os.path.isfile(self.src_file)
def _subprocess_call(self, cmd, env=None, **kwargs):
log.debug("Call '{}'".format(" ".join(cmd)))
return subprocess.check_call(cmd, env=env, **kwargs)
def _subprocess_output(self, cmd, env=None, **kwargs):
log.debug("Call '{}'".format(" ".join(cmd)))
if env is None:
Reported by Pylint.
Line: 236
Column: 19
return subprocess.check_call(cmd, env=env, **kwargs)
def _subprocess_output(self, cmd, env=None, **kwargs):
log.debug("Call '{}'".format(" ".join(cmd)))
if env is None:
env = os.environ.copy()
env["LD_LIBRARY_PATH"] = self.lib_dir
out = subprocess.check_output(cmd, env=env, **kwargs)
return out.strip().decode("utf-8")
Reported by Pylint.
Line: 251
Column: 22
data = None
for url_template in self.url_templates:
url = url_template.format(v=self.version, s=self.short_version)
log.info("Downloading from {}".format(url))
try:
req = urlopen(url)
# KISS, read all, write all
data = req.read()
except HTTPError as e:
Reported by Pylint.
Line: 253
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b310-urllib-urlopen
url = url_template.format(v=self.version, s=self.short_version)
log.info("Downloading from {}".format(url))
try:
req = urlopen(url)
# KISS, read all, write all
data = req.read()
except HTTPError as e:
log.error(
"Download from {} has from failed: {}".format(url, e)
Reported by Bandit.
Line: 258
Column: 21
data = req.read()
except HTTPError as e:
log.error(
"Download from {} has from failed: {}".format(url, e)
)
else:
log.info("Successfully downloaded from {}".format(url))
break
if data is None:
Reported by Pylint.
Line: 261
Column: 26
"Download from {} has from failed: {}".format(url, e)
)
else:
log.info("Successfully downloaded from {}".format(url))
break
if data is None:
raise ValueError("All download URLs have failed")
log.info("Storing {}".format(self.src_file))
with open(self.src_file, "wb") as f:
Reported by Pylint.
Line: 265
Column: 18
break
if data is None:
raise ValueError("All download URLs have failed")
log.info("Storing {}".format(self.src_file))
with open(self.src_file, "wb") as f:
f.write(data)
def _unpack_src(self):
"""Unpack tar.gz bundle"""
Reported by Pylint.
Line: 287
Column: 18
elif not member.name.startswith(base):
raise ValueError(member.name, base)
member.name = member.name[len(base):].lstrip('/')
log.info("Unpacking files to {}".format(self.build_dir))
tf.extractall(self.build_dir, members)
def _build_src(self, config_args=()):
"""Now build openssl"""
log.info("Running build in {}".format(self.build_dir))
Reported by Pylint.
Line: 292
Column: 18
def _build_src(self, config_args=()):
"""Now build openssl"""
log.info("Running build in {}".format(self.build_dir))
cwd = self.build_dir
cmd = [
"./config", *config_args,
"shared", "--debug",
"--prefix={}".format(self.install_dir)
Reported by Pylint.
Lib/test/test_format.py
44 issues
Line: 470
Column: 47
f = 1.2
self.assertEqual(format(f, ".0f"), "1")
self.assertEqual(format(f, ".3f"), "1.200")
with self.assertRaises(ValueError) as cm:
format(f, ".%sf" % (sys.maxsize + 1))
c = complex(f)
self.assertEqual(format(c, ".0f"), "1+0j")
self.assertEqual(format(c, ".3f"), "1.200+0.000j")
Reported by Pylint.
Line: 484
Column: 47
from _testcapi import INT_MAX
f = 1.2
with self.assertRaises(ValueError) as cm:
format(f, ".%sf" % (INT_MAX + 1))
c = complex(f)
with self.assertRaises(ValueError) as cm:
format(c, ".%sf" % (INT_MAX + 1))
Reported by Pylint.
Line: 1
Column: 1
from test.support import verbose, TestFailed
import locale
import sys
import re
import test.support as support
import unittest
maxsize = support.MAX_Py_ssize_t
Reported by Pylint.
Line: 8
Column: 1
import test.support as support
import unittest
maxsize = support.MAX_Py_ssize_t
# test string formatting operator (I am not sure if this is being tested
# elsewhere but, surely, some of the given cases are *not* tested because
# they crash python)
# test on bytes object as well
Reported by Pylint.
Line: 15
Column: 1
# they crash python)
# test on bytes object as well
def testformat(formatstr, args, output=None, limit=None, overflowok=False):
if verbose:
if output:
print("{!a} % {!a} =? {!a} ...".format(formatstr, args, output),
end=' ')
else:
Reported by Pylint.
Line: 30
Column: 9
if verbose:
print('overflow (this is fine)')
else:
if output and limit is None and result != output:
if verbose:
print('no')
raise AssertionError("%r %% %r == %r != %r" %
(formatstr, args, result, output))
# when 'limit' is specified, it determines how many characters
Reported by Pylint.
Line: 50
Column: 1
if verbose:
print('yes')
def testcommon(formatstr, args, output=None, limit=None, overflowok=False):
# if formatstr is a str, test str, bytes, and bytearray;
# otherwise, test bytes and bytearray
if isinstance(formatstr, str):
testformat(formatstr, args, output, limit, overflowok)
b_format = formatstr.encode('ascii')
Reported by Pylint.
Line: 74
Column: 1
testformat(b_format, b_args, b_output, limit, overflowok)
testformat(ba_format, b_args, ba_output, limit, overflowok)
def test_exc(formatstr, args, exception, excmsg):
try:
testformat(formatstr, args)
except exception as exc:
if str(exc) == excmsg:
if verbose:
Reported by Pylint.
Line: 82
Column: 25
if verbose:
print("yes")
else:
if verbose: print('no')
print('Unexpected ', exception, ':', repr(str(exc)))
except:
if verbose: print('no')
print('Unexpected exception')
raise
Reported by Pylint.
Line: 85
Column: 21
if verbose: print('no')
print('Unexpected ', exception, ':', repr(str(exc)))
except:
if verbose: print('no')
print('Unexpected exception')
raise
else:
raise TestFailed('did not get expected exception: %s' % excmsg)
Reported by Pylint.
Lib/test/test_linecache.py
44 issues
Line: 44
Column: 9
class TempFile:
def setUp(self):
super().setUp()
with tempfile.NamedTemporaryFile(delete=False) as fp:
self.file_name = fp.name
fp.write(self.file_byte_string)
self.addCleanup(os_helper.unlink, self.file_name)
Reported by Pylint.
Line: 47
Column: 22
super().setUp()
with tempfile.NamedTemporaryFile(delete=False) as fp:
self.file_name = fp.name
fp.write(self.file_byte_string)
self.addCleanup(os_helper.unlink, self.file_name)
class GetLineTestsGoodData(TempFile):
# file_list = ['list\n', 'of\n', 'good\n', 'strings\n']
Reported by Pylint.
Line: 48
Column: 9
with tempfile.NamedTemporaryFile(delete=False) as fp:
self.file_name = fp.name
fp.write(self.file_byte_string)
self.addCleanup(os_helper.unlink, self.file_name)
class GetLineTestsGoodData(TempFile):
# file_list = ['list\n', 'of\n', 'good\n', 'strings\n']
Reported by Pylint.
Line: 55
Column: 41
# file_list = ['list\n', 'of\n', 'good\n', 'strings\n']
def setUp(self):
self.file_byte_string = ''.join(self.file_list).encode('utf-8')
super().setUp()
def test_getline(self):
with tokenize.open(self.file_name) as fp:
for index, line in enumerate(fp):
Reported by Pylint.
Line: 65
Column: 17
line += '\n'
cached_line = linecache.getline(self.file_name, index + 1)
self.assertEqual(line, cached_line)
def test_getlines(self):
lines = linecache.getlines(self.file_name)
self.assertEqual(lines, self.file_list)
Reported by Pylint.
Line: 69
Column: 33
def test_getlines(self):
lines = linecache.getlines(self.file_name)
self.assertEqual(lines, self.file_list)
class GetLineTestsBadData(TempFile):
# file_byte_string = b'Bad data goes here'
Reported by Pylint.
Line: 69
Column: 9
def test_getlines(self):
lines = linecache.getlines(self.file_name)
self.assertEqual(lines, self.file_list)
class GetLineTestsBadData(TempFile):
# file_byte_string = b'Bad data goes here'
Reported by Pylint.
Line: 76
Column: 9
# file_byte_string = b'Bad data goes here'
def test_getline(self):
self.assertRaises((SyntaxError, UnicodeDecodeError),
linecache.getline, self.file_name, 1)
def test_getlines(self):
self.assertRaises((SyntaxError, UnicodeDecodeError),
linecache.getlines, self.file_name)
Reported by Pylint.
Line: 80
Column: 9
linecache.getline, self.file_name, 1)
def test_getlines(self):
self.assertRaises((SyntaxError, UnicodeDecodeError),
linecache.getlines, self.file_name)
class EmptyFile(GetLineTestsGoodData, unittest.TestCase):
file_list = []
Reported by Pylint.
Line: 220
Column: 9
def test_lazycache_already_cached(self):
linecache.clearcache()
lines = linecache.getlines(NONEXISTENT_FILENAME, globals())
self.assertEqual(
False,
linecache.lazycache(NONEXISTENT_FILENAME, globals()))
self.assertEqual(4, len(linecache.cache[NONEXISTENT_FILENAME]))
Reported by Pylint.
Lib/test/test_importlib/source/test_finder.py
44 issues
Line: 1
Column: 1
from .. import abc
from .. import util
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
Reported by Pylint.
Line: 2
Column: 1
from .. import abc
from .. import util
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
Reported by Pylint.
Line: 142
Column: 9
# invalidate_caches() should reset the mtime.
finder = self.machinery.FileFinder('', (self.machinery.SourceFileLoader,
self.machinery.SOURCE_SUFFIXES))
finder._path_mtime = 42
finder.invalidate_caches()
self.assertEqual(finder._path_mtime, -1)
# Regression test for http://bugs.python.org/issue14846
def test_dir_removal_handling(self):
Reported by Pylint.
Line: 144
Column: 26
self.machinery.SOURCE_SUFFIXES))
finder._path_mtime = 42
finder.invalidate_caches()
self.assertEqual(finder._path_mtime, -1)
# Regression test for http://bugs.python.org/issue14846
def test_dir_removal_handling(self):
mod = 'mod'
with util.create_modules(mod) as mapping:
Reported by Pylint.
Line: 194
Column: 35
NOT_FOUND = None
def _find(self, finder, name, loader_only=False):
spec = finder.find_spec(name)
return spec.loader if spec is not None else spec
(Frozen_FinderTestsPEP451,
Reported by Pylint.
Line: 224
Column: 35
NOT_FOUND = None
def _find(self, finder, name, loader_only=False):
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
return finder.find_module(name)
Reported by Pylint.
Line: 1
Column: 1
from .. import abc
from .. import util
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
Reported by Pylint.
Line: 6
Column: 1
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
import sys
import tempfile
Reported by Pylint.
Line: 6
Column: 1
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
import sys
import tempfile
Reported by Pylint.
Line: 7
Column: 1
machinery = util.import_importlib('importlib.machinery')
import errno
import os
import py_compile
import stat
import sys
import tempfile
from test.support.import_helper import make_legacy_pyc
Reported by Pylint.
Lib/test/inspect_stringized_annotations.py
44 issues
Line: 9
Column: 27
class MyClass:
a:int=4
b:str="bar"
def __init__(self, a, b):
self.a = a
self.b = b
def __eq__(self, other):
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b
Reported by Pylint.
Line: 9
Column: 24
class MyClass:
a:int=4
b:str="bar"
def __init__(self, a, b):
self.a = a
self.b = b
def __eq__(self, other):
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b
Reported by Pylint.
Line: 15
Column: 14
def __eq__(self, other):
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b
def function(a:int, b:str) -> MyClass:
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
Reported by Pylint.
Line: 15
Column: 21
def __eq__(self, other):
return isinstance(other, MyClass) and self.a == other.a and self.b == other.b
def function(a:int, b:str) -> MyClass:
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
Reported by Pylint.
Line: 19
Column: 31
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
Reported by Pylint.
Line: 19
Column: 15
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
Reported by Pylint.
Line: 19
Column: 15
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
Reported by Pylint.
Line: 19
Column: 22
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
Reported by Pylint.
Line: 19
Column: 22
return MyClass(a, b)
def function2(a:int, b:"str", c:MyClass) -> MyClass:
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
Reported by Pylint.
Line: 23
Column: 24
pass
def function3(a:"int", b:"str", c:"MyClass"):
pass
class UnannotatedClass:
pass
Reported by Pylint.
Lib/test/test_json/test_dump.py
43 issues
Line: 9
Column: 9
class TestDump:
def test_dump(self):
sio = StringIO()
self.json.dump({}, sio)
self.assertEqual(sio.getvalue(), '{}')
def test_dumps(self):
self.assertEqual(self.dumps({}), '{}')
Reported by Pylint.
Line: 10
Column: 9
def test_dump(self):
sio = StringIO()
self.json.dump({}, sio)
self.assertEqual(sio.getvalue(), '{}')
def test_dumps(self):
self.assertEqual(self.dumps({}), '{}')
def test_dump_skipkeys(self):
Reported by Pylint.
Line: 13
Column: 26
self.assertEqual(sio.getvalue(), '{}')
def test_dumps(self):
self.assertEqual(self.dumps({}), '{}')
def test_dump_skipkeys(self):
v = {b'invalid_key': False, 'valid_key': True}
with self.assertRaises(TypeError):
self.json.dumps(v)
Reported by Pylint.
Line: 13
Column: 9
self.assertEqual(sio.getvalue(), '{}')
def test_dumps(self):
self.assertEqual(self.dumps({}), '{}')
def test_dump_skipkeys(self):
v = {b'invalid_key': False, 'valid_key': True}
with self.assertRaises(TypeError):
self.json.dumps(v)
Reported by Pylint.
Line: 17
Column: 14
def test_dump_skipkeys(self):
v = {b'invalid_key': False, 'valid_key': True}
with self.assertRaises(TypeError):
self.json.dumps(v)
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
Reported by Pylint.
Line: 18
Column: 13
def test_dump_skipkeys(self):
v = {b'invalid_key': False, 'valid_key': True}
with self.assertRaises(TypeError):
self.json.dumps(v)
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
Reported by Pylint.
Line: 20
Column: 13
with self.assertRaises(TypeError):
self.json.dumps(v)
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
def test_encode_truefalse(self):
Reported by Pylint.
Line: 21
Column: 13
self.json.dumps(v)
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
def test_encode_truefalse(self):
self.assertEqual(self.dumps(
Reported by Pylint.
Line: 22
Column: 9
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
def test_encode_truefalse(self):
self.assertEqual(self.dumps(
{True: False, False: True}, sort_keys=True),
Reported by Pylint.
Line: 23
Column: 9
s = self.json.dumps(v, skipkeys=True)
o = self.json.loads(s)
self.assertIn('valid_key', o)
self.assertNotIn(b'invalid_key', o)
def test_encode_truefalse(self):
self.assertEqual(self.dumps(
{True: False, False: True}, sort_keys=True),
'{"false": true, "true": false}')
Reported by Pylint.
Lib/test/test_importlib/import_/test_meta_path.py
43 issues
Line: 1
Column: 1
from .. import util
import importlib._bootstrap
import sys
from types import MethodType
import unittest
import warnings
class CallingOrder:
Reported by Pylint.
Line: 22
Column: 31
mod = 'top_level'
with util.mock_spec(mod) as first, util.mock_spec(mod) as second:
with util.import_state(meta_path=[first, second]):
self.assertIs(self.__import__(mod), first.modules[mod])
def test_continuing(self):
# [continuing]
mod_name = 'for_real'
with util.mock_spec('nonexistent') as first, \
Reported by Pylint.
Line: 22
Column: 17
mod = 'top_level'
with util.mock_spec(mod) as first, util.mock_spec(mod) as second:
with util.import_state(meta_path=[first, second]):
self.assertIs(self.__import__(mod), first.modules[mod])
def test_continuing(self):
# [continuing]
mod_name = 'for_real'
with util.mock_spec('nonexistent') as first, \
Reported by Pylint.
Line: 31
Column: 17
util.mock_spec(mod_name) as second:
first.find_spec = lambda self, fullname, path=None, parent=None: None
with util.import_state(meta_path=[first, second]):
self.assertIs(self.__import__(mod_name), second.modules[mod_name])
def test_empty(self):
# Raise an ImportWarning if sys.meta_path is empty.
module_name = 'nothing'
try:
Reported by Pylint.
Line: 31
Column: 31
util.mock_spec(mod_name) as second:
first.find_spec = lambda self, fullname, path=None, parent=None: None
with util.import_state(meta_path=[first, second]):
self.assertIs(self.__import__(mod_name), second.modules[mod_name])
def test_empty(self):
# Raise an ImportWarning if sys.meta_path is empty.
module_name = 'nothing'
try:
Reported by Pylint.
Line: 43
Column: 17
with util.import_state(meta_path=[]):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
self.assertIsNone(importlib._bootstrap._find_spec('nothing',
None))
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning))
Reported by Pylint.
Line: 45
Column: 17
warnings.simplefilter('always')
self.assertIsNone(importlib._bootstrap._find_spec('nothing',
None))
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning))
(Frozen_CallingOrder,
Source_CallingOrder
Reported by Pylint.
Line: 46
Column: 17
self.assertIsNone(importlib._bootstrap._find_spec('nothing',
None))
self.assertEqual(len(w), 1)
self.assertTrue(issubclass(w[-1].category, ImportWarning))
(Frozen_CallingOrder,
Source_CallingOrder
) = util.test_both(CallingOrder, __import__=util.__import__)
Reported by Pylint.
Line: 61
Column: 33
argument [path set]."""
def log_finder(self, importer):
fxn = getattr(importer, self.finder_name)
log = []
def wrapper(self, *args, **kwargs):
log.append([args, kwargs])
return fxn(*args, **kwargs)
return log, wrapper
Reported by Pylint.
Line: 72
Column: 14
# [no path]
mod_name = 'top_level'
assert '.' not in mod_name
with self.mock_modules(mod_name) as importer:
log, wrapped_call = self.log_finder(importer)
setattr(importer, self.finder_name, MethodType(wrapped_call, importer))
with util.import_state(meta_path=[importer]):
self.__import__(mod_name)
assert len(log) == 1
Reported by Pylint.
Lib/test/support/os_helper.py
43 issues
Line: 39
Column: 8
TESTFN_UNENCODABLE = None
if os.name == 'nt':
# skip win32s (0) or Windows 9x/ME (1)
if sys.getwindowsversion().platform >= 2:
# Different kinds of characters from various languages to minimize the
# probability that the whole name is encodable to MBCS (issue #9819)
TESTFN_UNENCODABLE = TESTFN_ASCII + "-\u5171\u0141\u2661\u0363\uDC80"
try:
TESTFN_UNENCODABLE.encode(sys.getfilesystemencoding())
Reported by Pylint.
Line: 171
Column: 5
def can_symlink():
global _can_symlink
if _can_symlink is not None:
return _can_symlink
symlink_path = TESTFN + "can_symlink"
try:
os.symlink(TESTFN, symlink_path)
Reported by Pylint.
Line: 198
Column: 5
def can_xattr():
import tempfile
global _can_xattr
if _can_xattr is not None:
return _can_xattr
if not hasattr(os, "setxattr"):
can = False
else:
Reported by Pylint.
Line: 251
Column: 22
if waitall:
dirname = pathname
else:
dirname, name = os.path.split(pathname)
dirname = dirname or '.'
# Check for `pathname` to be removed from the filesystem.
# The exponential backoff of the timeout amounts to a total
# of ~1 second after which the deletion is probably an error
# anyway.
Reported by Pylint.
Line: 287
Column: 17
from test.support import _force_run
def _rmtree_inner(path):
for name in _force_run(path, os.listdir, path):
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
except OSError as exc:
print("support.rmtree(): os.lstat(%r) failed with %s"
Reported by Pylint.
Line: 331
Column: 17
def _rmtree_inner(path):
from test.support import _force_run
for name in _force_run(path, os.listdir, path):
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
except OSError:
mode = 0
Reported by Pylint.
Line: 433
Column: 14
@contextlib.contextmanager
def temp_cwd(name='tempcwd', quiet=False):
"""
Context manager that temporarily creates and changes the CWD.
The function temporarily changes the current working directory
after creating a temporary directory in the current directory with
Reported by Pylint.
Line: 516
Column: 13
# on invalid file descriptor if Python is compiled in debug mode
try:
import msvcrt
msvcrt.CrtSetReportMode
except (AttributeError, ImportError):
# no msvcrt or a release build
pass
else:
old_modes = {}
Reported by Pylint.
Line: 1
Column: 1
import collections.abc
import contextlib
import errno
import os
import re
import stat
import sys
import time
import unittest
Reported by Pylint.
Line: 167
Column: 1
unlink(TESTFN)
_can_symlink = None
def can_symlink():
global _can_symlink
if _can_symlink is not None:
Reported by Pylint.
Lib/test/test_winsound.py
43 issues
Line: 1
Column: 1
# Ridiculously simple test of the winsound module for Windows.
import functools
import time
import unittest
from test import support
from test.support import import_helper
Reported by Pylint.
Line: 19
Column: 1
# actually plays, and it's incredibly flaky trying to figure out if a sound
# even *should* play. Instead of guessing, just call the function and assume
# it either passed or raised the RuntimeError we expect in case of failure.
def sound_func(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
ret = func(*args, **kwargs)
except RuntimeError as e:
Reported by Pylint.
Line: 21
Column: 5
# it either passed or raised the RuntimeError we expect in case of failure.
def sound_func(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
try:
ret = func(*args, **kwargs)
except RuntimeError as e:
if support.verbose:
print(func.__name__, 'failed:', e)
Reported by Pylint.
Line: 24
Column: 9
def wrapper(*args, **kwargs):
try:
ret = func(*args, **kwargs)
except RuntimeError as e:
if support.verbose:
print(func.__name__, 'failed:', e)
else:
if support.verbose:
print(func.__name__, 'returned')
Reported by Pylint.
Line: 39
Column: 1
safe_PlaySound = sound_func(winsound.PlaySound)
class BeepTest(unittest.TestCase):
def test_errors(self):
self.assertRaises(TypeError, winsound.Beep)
self.assertRaises(ValueError, winsound.Beep, 36, 75)
self.assertRaises(ValueError, winsound.Beep, 32768, 75)
Reported by Pylint.
Line: 41
Column: 5
class BeepTest(unittest.TestCase):
def test_errors(self):
self.assertRaises(TypeError, winsound.Beep)
self.assertRaises(ValueError, winsound.Beep, 36, 75)
self.assertRaises(ValueError, winsound.Beep, 32768, 75)
def test_extremes(self):
Reported by Pylint.
Line: 46
Column: 5
self.assertRaises(ValueError, winsound.Beep, 36, 75)
self.assertRaises(ValueError, winsound.Beep, 32768, 75)
def test_extremes(self):
safe_Beep(37, 75)
safe_Beep(32767, 75)
def test_increasingfrequency(self):
for i in range(100, 2000, 100):
Reported by Pylint.
Line: 46
Column: 5
self.assertRaises(ValueError, winsound.Beep, 36, 75)
self.assertRaises(ValueError, winsound.Beep, 32768, 75)
def test_extremes(self):
safe_Beep(37, 75)
safe_Beep(32767, 75)
def test_increasingfrequency(self):
for i in range(100, 2000, 100):
Reported by Pylint.
Line: 50
Column: 5
safe_Beep(37, 75)
safe_Beep(32767, 75)
def test_increasingfrequency(self):
for i in range(100, 2000, 100):
safe_Beep(i, 75)
def test_keyword_args(self):
safe_Beep(duration=75, frequency=2000)
Reported by Pylint.
Line: 50
Column: 5
safe_Beep(37, 75)
safe_Beep(32767, 75)
def test_increasingfrequency(self):
for i in range(100, 2000, 100):
safe_Beep(i, 75)
def test_keyword_args(self):
safe_Beep(duration=75, frequency=2000)
Reported by Pylint.
Lib/test/test_peg_generator/test_c_parser.py
43 issues
Line: 21
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,
generate_parser_c_extension,
generate_c_parser_source,
)
Reported by Pylint.
Line: 22
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,
generate_parser_c_extension,
generate_c_parser_source,
)
from pegen.ast_dump import ast_dump
Reported by Pylint.
Line: 27
Column: 5
generate_parser_c_extension,
generate_c_parser_source,
)
from pegen.ast_dump import ast_dump
TEST_TEMPLATE = """
tmp_dir = {extension_path!r}
Reported by Pylint.
Line: 82
Column: 9
self.old_cwd = os.getcwd()
self.tmp_path = tempfile.mkdtemp()
change_cwd = os_helper.change_cwd(self.tmp_path)
change_cwd.__enter__()
self.addCleanup(change_cwd.__exit__, None, None, None)
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.tmp_path)
Reported by Pylint.
Line: 83
Column: 25
self.tmp_path = tempfile.mkdtemp()
change_cwd = os_helper.change_cwd(self.tmp_path)
change_cwd.__enter__()
self.addCleanup(change_cwd.__exit__, None, None, None)
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.tmp_path)
sysconfig._CONFIG_VARS.clear()
Reported by Pylint.
Line: 27
Column: 5
generate_parser_c_extension,
generate_c_parser_source,
)
from pegen.ast_dump import ast_dump
TEST_TEMPLATE = """
tmp_dir = {extension_path!r}
Reported by Pylint.
Line: 75
Column: 41
class TestCParser(unittest.TestCase):
def setUp(self):
self._backup_config_vars = dict(sysconfig._CONFIG_VARS)
cmd = support.missing_compiler_executable()
if cmd is not None:
self.skipTest("The %r command is not found" % cmd)
self.old_cwd = os.getcwd()
self.tmp_path = tempfile.mkdtemp()
Reported by Pylint.
Line: 88
Column: 9
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.tmp_path)
sysconfig._CONFIG_VARS.clear()
sysconfig._CONFIG_VARS.update(self._backup_config_vars)
def build_extension(self, grammar_source):
grammar = parse_string(grammar_source, GrammarParser)
generate_parser_c_extension(grammar, Path(self.tmp_path))
Reported by Pylint.
Line: 89
Column: 9
os.chdir(self.old_cwd)
shutil.rmtree(self.tmp_path)
sysconfig._CONFIG_VARS.clear()
sysconfig._CONFIG_VARS.update(self._backup_config_vars)
def build_extension(self, grammar_source):
grammar = parse_string(grammar_source, GrammarParser)
generate_parser_c_extension(grammar, Path(self.tmp_path))
Reported by Pylint.
Line: 1
Column: 1
import sysconfig
import textwrap
import unittest
import os
import shutil
import tempfile
from pathlib import Path
from test import test_tools
Reported by Pylint.