The following issues were found
Lib/test/test_asyncio/test_buffered_proto.py
14 issues
Line: 17
Column: 9
self.con_lost_fut = con_lost_fut
def get_buffer(self, sizehint):
self.buffer = bytearray(100)
return self.buffer
def buffer_updated(self, nbytes):
self.cb(self.buffer[:nbytes])
Reported by Pylint.
Line: 50
Column: 17
conn_lost_fut = self.loop.create_future()
tr, pr = await self.loop.create_connection(
lambda: ReceiveStuffProto(on_buf, conn_lost_fut), *addr)
await conn_lost_fut
async def on_server_client(reader, writer):
Reported by Pylint.
Line: 1
Column: 1
import asyncio
import unittest
from test.test_asyncio import functional as func_tests
def tearDownModule():
asyncio.set_event_loop_policy(None)
Reported by Pylint.
Line: 7
Column: 1
from test.test_asyncio import functional as func_tests
def tearDownModule():
asyncio.set_event_loop_policy(None)
class ReceiveStuffProto(asyncio.BufferedProtocol):
def __init__(self, cb, con_lost_fut):
Reported by Pylint.
Line: 7
Column: 1
from test.test_asyncio import functional as func_tests
def tearDownModule():
asyncio.set_event_loop_policy(None)
class ReceiveStuffProto(asyncio.BufferedProtocol):
def __init__(self, cb, con_lost_fut):
Reported by Pylint.
Line: 11
Column: 1
asyncio.set_event_loop_policy(None)
class ReceiveStuffProto(asyncio.BufferedProtocol):
def __init__(self, cb, con_lost_fut):
self.cb = cb
self.con_lost_fut = con_lost_fut
def get_buffer(self, sizehint):
Reported by Pylint.
Line: 13
Column: 9
class ReceiveStuffProto(asyncio.BufferedProtocol):
def __init__(self, cb, con_lost_fut):
self.cb = cb
self.con_lost_fut = con_lost_fut
def get_buffer(self, sizehint):
self.buffer = bytearray(100)
return self.buffer
Reported by Pylint.
Line: 30
Column: 1
self.con_lost_fut.set_exception(exc)
class BaseTestBufferedProtocol(func_tests.FunctionalTestCaseMixin):
def new_loop(self):
raise NotImplementedError
def test_buffered_proto_create_connection(self):
Reported by Pylint.
Line: 35
Column: 5
def new_loop(self):
raise NotImplementedError
def test_buffered_proto_create_connection(self):
NOISE = b'12345678+' * 1024
async def client(addr):
data = b''
Reported by Pylint.
Line: 37
Column: 9
def test_buffered_proto_create_connection(self):
NOISE = b'12345678+' * 1024
async def client(addr):
data = b''
def on_buf(buf):
Reported by Pylint.
Lib/test/test_cgitb.py
14 issues
Line: 41
Column: 22
def test_syshook_no_logdir_default_format(self):
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(logdir=%s); '
'raise ValueError("Hello World")') % repr(tracedir),
PYTHONIOENCODING='utf-8')
out = out.decode()
Reported by Pylint.
Line: 41
Column: 13
def test_syshook_no_logdir_default_format(self):
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(logdir=%s); '
'raise ValueError("Hello World")') % repr(tracedir),
PYTHONIOENCODING='utf-8')
out = out.decode()
Reported by Pylint.
Line: 57
Column: 22
def test_syshook_no_logdir_text_format(self):
# Issue 12890: we were emitting the <p> tag in text mode.
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(format="text", logdir=%s); '
'raise ValueError("Hello World")') % repr(tracedir),
PYTHONIOENCODING='utf-8')
out = out.decode()
Reported by Pylint.
Line: 57
Column: 13
def test_syshook_no_logdir_text_format(self):
# Issue 12890: we were emitting the <p> tag in text mode.
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(format="text", logdir=%s); '
'raise ValueError("Hello World")') % repr(tracedir),
PYTHONIOENCODING='utf-8')
out = out.decode()
Reported by Pylint.
Line: 1
Column: 1
from test.support.os_helper import temp_dir
from test.support.script_helper import assert_python_failure
import unittest
import sys
import cgitb
class TestCgitb(unittest.TestCase):
def test_fonts(self):
Reported by Pylint.
Line: 7
Column: 1
import sys
import cgitb
class TestCgitb(unittest.TestCase):
def test_fonts(self):
text = "Hello Robbie!"
self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
Reported by Pylint.
Line: 9
Column: 5
class TestCgitb(unittest.TestCase):
def test_fonts(self):
text = "Hello Robbie!"
self.assertEqual(cgitb.small(text), "<small>{}</small>".format(text))
self.assertEqual(cgitb.strong(text), "<strong>{}</strong>".format(text))
self.assertEqual(cgitb.grey(text),
'<font color="#909090">{}</font>'.format(text))
Reported by Pylint.
Line: 16
Column: 5
self.assertEqual(cgitb.grey(text),
'<font color="#909090">{}</font>'.format(text))
def test_blanks(self):
self.assertEqual(cgitb.small(""), "")
self.assertEqual(cgitb.strong(""), "")
self.assertEqual(cgitb.grey(""), "")
def test_html(self):
Reported by Pylint.
Line: 21
Column: 5
self.assertEqual(cgitb.strong(""), "")
self.assertEqual(cgitb.grey(""), "")
def test_html(self):
try:
raise ValueError("Hello World")
except ValueError as err:
# If the html was templated we could do a bit more here.
# At least check that we get details on what we just raised.
Reported by Pylint.
Line: 31
Column: 5
self.assertIn("ValueError", html)
self.assertIn(str(err), html)
def test_text(self):
try:
raise ValueError("Hello World")
except ValueError:
text = cgitb.text(sys.exc_info())
self.assertIn("ValueError", text)
Reported by Pylint.
Lib/test/test_html.py
14 issues
Line: 25
Column: 17
self.assertEqual(html.unescape(text), expected,
msg=errmsg % (text, expected))
def check_num(num, expected):
for format in numeric_formats:
text = format % num
self.assertEqual(html.unescape(text), expected,
msg=errmsg % (text, expected))
# check text with no character references
check('no character references', 'no character references')
Reported by Pylint.
Line: 9
Column: 1
import unittest
class HtmlTests(unittest.TestCase):
def test_escape(self):
self.assertEqual(
html.escape('\'<script>"&foo;"</script>\''),
''<script>"&foo;"</script>'')
self.assertEqual(
Reported by Pylint.
Line: 10
Column: 5
class HtmlTests(unittest.TestCase):
def test_escape(self):
self.assertEqual(
html.escape('\'<script>"&foo;"</script>\''),
''<script>"&foo;"</script>'')
self.assertEqual(
html.escape('\'<script>"&foo;"</script>\'', False),
Reported by Pylint.
Line: 18
Column: 5
html.escape('\'<script>"&foo;"</script>\'', False),
'\'<script>"&foo;"</script>\'')
def test_unescape(self):
numeric_formats = ['&#%d', '&#%d;', '&#x%x', '&#x%x;']
errmsg = 'unescape(%r) should have returned %r'
def check(text, expected):
self.assertEqual(html.unescape(text), expected,
msg=errmsg % (text, expected))
Reported by Pylint.
Line: 36
Column: 13
# check & followed by numbers and letters
check('&0 &9 &a &0; &9; &a;', '&0 &9 &a &0; &9; &a;')
# check incomplete entities at the end of the string
for x in ['&', '&#', '&#x', '&#X', '&#y', '&#xy', '&#Xy']:
check(x, x)
check(x+';', x+';')
# check several combinations of numeric character references,
# possibly followed by different characters
formats = ['&#%d', '&#%07d', '&#%d;', '&#%07d;',
Reported by Pylint.
Line: 46
Column: 17
'&#x%X', '&#x%06X', '&#X%x;', '&#X%06x;']
for num, char in zip([65, 97, 34, 38, 0x2603, 0x101234],
['A', 'a', '"', '&', '\u2603', '\U00101234']):
for s in formats:
check(s % num, char)
for end in [' ', 'X']:
check((s+end) % num, char+end)
# check invalid code points
for cp in [0xD800, 0xDB00, 0xDC00, 0xDFFF, 0x110000]:
Reported by Pylint.
Line: 51
Column: 13
for end in [' ', 'X']:
check((s+end) % num, char+end)
# check invalid code points
for cp in [0xD800, 0xDB00, 0xDC00, 0xDFFF, 0x110000]:
check_num(cp, '\uFFFD')
# check more invalid code points
for cp in [0x1, 0xb, 0xe, 0x7f, 0xfffe, 0xffff, 0x10fffe, 0x10ffff]:
check_num(cp, '')
# check invalid numbers
Reported by Pylint.
Line: 54
Column: 13
for cp in [0xD800, 0xDB00, 0xDC00, 0xDFFF, 0x110000]:
check_num(cp, '\uFFFD')
# check more invalid code points
for cp in [0x1, 0xb, 0xe, 0x7f, 0xfffe, 0xffff, 0x10fffe, 0x10ffff]:
check_num(cp, '')
# check invalid numbers
for num, ch in zip([0x0d, 0x80, 0x95, 0x9d], '\r\u20ac\u2022\x9d'):
check_num(num, ch)
# check small numbers
Reported by Pylint.
Line: 57
Column: 18
for cp in [0x1, 0xb, 0xe, 0x7f, 0xfffe, 0xffff, 0x10fffe, 0x10ffff]:
check_num(cp, '')
# check invalid numbers
for num, ch in zip([0x0d, 0x80, 0x95, 0x9d], '\r\u20ac\u2022\x9d'):
check_num(num, ch)
# check small numbers
check_num(0, '\uFFFD')
check_num(9, '\t')
# check a big number
Reported by Pylint.
Line: 65
Column: 13
# check a big number
check_num(1000000000000000000, '\uFFFD')
# check that multiple trailing semicolons are handled correctly
for e in ['";', '";', '";', '";']:
check(e, '";')
# check that semicolons in the middle don't create problems
for e in ['"quot;', '"quot;', '"quot;', '"quot;']:
check(e, '"quot;')
# check triple adjacent charrefs
Reported by Pylint.
Lib/test/test_collections.py
14 issues
Line: 119
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle
# check deep copies
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
e = pickle.loads(pickle.dumps(d, proto))
self.assertEqual(d, e)
self.assertEqual(d.maps, e.maps)
self.assertIsNot(d, e)
for m1, m2 in zip(d.maps, e.maps):
self.assertIsNot(m1, m2, e)
Reported by Bandit.
Line: 126
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
for m1, m2 in zip(d.maps, e.maps):
self.assertIsNot(m1, m2, e)
for e in [copy.deepcopy(d),
eval(repr(d))
]:
self.assertEqual(d, e)
self.assertEqual(d.maps, e.maps)
self.assertIsNot(d, e)
for m1, m2 in zip(d.maps, e.maps):
Reported by Bandit.
Line: 680
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle
self.assertRaises(AttributeError, Point.x.__delete__, p)
class NewPoint(tuple):
x = pickle.loads(pickle.dumps(Point.x))
y = pickle.loads(pickle.dumps(Point.y))
np = NewPoint([1, 2])
self.assertEqual(np.x, 1)
Reported by Bandit.
Line: 681
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle
class NewPoint(tuple):
x = pickle.loads(pickle.dumps(Point.x))
y = pickle.loads(pickle.dumps(Point.y))
np = NewPoint([1, 2])
self.assertEqual(np.x, 1)
self.assertEqual(np.y, 2)
Reported by Bandit.
Line: 2169
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b301-pickle
check(copy.deepcopy(words))
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
check(pickle.loads(pickle.dumps(words, proto)))
check(eval(repr(words)))
update_test = Counter()
update_test.update(words)
check(update_test)
check(Counter(words))
Reported by Bandit.
Line: 2170
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
check(pickle.loads(pickle.dumps(words, proto)))
check(eval(repr(words)))
update_test = Counter()
update_test.update(words)
check(update_test)
check(Counter(words))
Reported by Bandit.
Line: 8
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b403-import-pickle
import doctest
import inspect
import operator
import pickle
from random import choice, randrange
from itertools import product, chain, combinations
import string
import sys
from test import support
Reported by Bandit.
Line: 541
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b311-random
self.assertEqual(Dot(1)._fields, ('d',))
n = 5000
names = list(set(''.join([choice(string.ascii_letters)
for j in range(10)]) for i in range(n)))
n = len(names)
Big = namedtuple('Big', names)
b = Big(*range(n))
self.assertEqual(b, tuple(range(n)))
Reported by Bandit.
Line: 2207
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b311-random
elements = 'abcd'
for i in range(1000):
# test random pairs of multisets
p = Counter(dict((elem, randrange(-2,4)) for elem in elements))
p.update(e=1, f=-1, g=0)
q = Counter(dict((elem, randrange(-2,4)) for elem in elements))
q.update(h=1, i=-1, j=0)
for counterop, numberop in [
(Counter.__add__, lambda x, y: max(0, x+y)),
Reported by Bandit.
Line: 2209
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b311-random
# test random pairs of multisets
p = Counter(dict((elem, randrange(-2,4)) for elem in elements))
p.update(e=1, f=-1, g=0)
q = Counter(dict((elem, randrange(-2,4)) for elem in elements))
q.update(h=1, i=-1, j=0)
for counterop, numberop in [
(Counter.__add__, lambda x, y: max(0, x+y)),
(Counter.__sub__, lambda x, y: max(0, x-y)),
(Counter.__or__, lambda x, y: max(0,x,y)),
Reported by Bandit.
Lib/test/test_opcache.py
14 issues
Line: 17
Column: 13
return o.x
o = C()
for i in range(1025):
assert f(o) == 1
Descriptor.__get__ = lambda self, instance, value: 2
Descriptor.__set__ = lambda *args: None
Reported by Pylint.
Line: 1
Column: 1
import unittest
class TestLoadAttrCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):
class Descriptor:
pass
class C:
def __init__(self):
Reported by Pylint.
Line: 3
Column: 1
import unittest
class TestLoadAttrCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):
class Descriptor:
pass
class C:
def __init__(self):
Reported by Pylint.
Line: 4
Column: 5
import unittest
class TestLoadAttrCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):
class Descriptor:
pass
class C:
def __init__(self):
Reported by Pylint.
Line: 5
Column: 9
class TestLoadAttrCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):
class Descriptor:
pass
class C:
def __init__(self):
self.x = 1
Reported by Pylint.
Line: 5
Column: 9
class TestLoadAttrCache(unittest.TestCase):
def test_descriptor_added_after_optimization(self):
class Descriptor:
pass
class C:
def __init__(self):
self.x = 1
Reported by Pylint.
Line: 8
Column: 9
class Descriptor:
pass
class C:
def __init__(self):
self.x = 1
x = Descriptor()
def f(o):
Reported by Pylint.
Line: 8
Column: 9
class Descriptor:
pass
class C:
def __init__(self):
self.x = 1
x = Descriptor()
def f(o):
Reported by Pylint.
Line: 8
Column: 9
class Descriptor:
pass
class C:
def __init__(self):
self.x = 1
x = Descriptor()
def f(o):
Reported by Pylint.
Line: 10
Column: 17
class C:
def __init__(self):
self.x = 1
x = Descriptor()
def f(o):
return o.x
Reported by Pylint.
Lib/test/test_email/torture_test.py
13 issues
Line: 30
Column: 5
try:
openfile('crispin-torture.txt')
except OSError:
raise unittest.SkipTest
class TortureBase(TestEmailBase):
def _msgobj(self, filename):
Reported by Pylint.
Line: 121
Column: 5
def suite():
suite = unittest.TestSuite()
for testclass in _testclasses():
suite.addTest(unittest.makeSuite(testclass))
return suite
Reported by Pylint.
Line: 1
Column: 1
# Copyright (C) 2002-2004 Python Software Foundation
#
# A torture test of the email package. This should not be run as part of the
# standard Python test suite since it requires several meg of email messages
# collected in the wild. These source messages are not checked into the
# Python distro, but are available as part of the standalone email package at
# http://sf.net/projects/mimelib
import sys
Reported by Pylint.
Line: 21
Column: 1
from email import __file__ as testfile
from email.iterators import _structure
def openfile(filename):
from os.path import join, dirname, abspath
path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))
return open(path, 'r')
# Prevent this test from running in the Python distro
Reported by Pylint.
Line: 22
Column: 5
from email.iterators import _structure
def openfile(filename):
from os.path import join, dirname, abspath
path = abspath(join(dirname(testfile), os.pardir, 'moredata', filename))
return open(path, 'r')
# Prevent this test from running in the Python distro
try:
Reported by Pylint.
Line: 34
Column: 1
class TortureBase(TestEmailBase):
def _msgobj(self, filename):
fp = openfile(filename)
try:
msg = email.message_from_file(fp)
finally:
Reported by Pylint.
Line: 36
Column: 9
class TortureBase(TestEmailBase):
def _msgobj(self, filename):
fp = openfile(filename)
try:
msg = email.message_from_file(fp)
finally:
fp.close()
return msg
Reported by Pylint.
Line: 45
Column: 1
class TestCrispinTorture(TortureBase):
# Mark Crispin's torture test from the SquirrelMail project
def test_mondo_message(self):
eq = self.assertEqual
neq = self.ndiffAssertEqual
msg = self._msgobj('crispin-torture.txt')
Reported by Pylint.
Line: 47
Column: 5
class TestCrispinTorture(TortureBase):
# Mark Crispin's torture test from the SquirrelMail project
def test_mondo_message(self):
eq = self.assertEqual
neq = self.ndiffAssertEqual
msg = self._msgobj('crispin-torture.txt')
payload = msg.get_payload()
eq(type(payload), list)
Reported by Pylint.
Line: 48
Column: 9
class TestCrispinTorture(TortureBase):
# Mark Crispin's torture test from the SquirrelMail project
def test_mondo_message(self):
eq = self.assertEqual
neq = self.ndiffAssertEqual
msg = self._msgobj('crispin-torture.txt')
payload = msg.get_payload()
eq(type(payload), list)
eq(len(payload), 12)
Reported by Pylint.
Lib/test/test_cprofile.py
13 issues
Line: 63
Column: 13
class TestCommandLine(unittest.TestCase):
def test_sort(self):
rc, out, err = assert_python_failure('-m', 'cProfile', '-s', 'demo')
self.assertGreater(rc, 0)
self.assertIn(b"option -s: invalid choice: 'demo'", err)
def main():
Reported by Pylint.
Line: 13
Column: 1
from test import support
class CProfileTest(ProfileTest):
profilerclass = cProfile.Profile
profilermodule = cProfile
expected_max_output = "{built-in method builtins.max}"
def get_expected_output(self):
Reported by Pylint.
Line: 21
Column: 5
def get_expected_output(self):
return _ProfileOutput
def test_bad_counter_during_dealloc(self):
# bpo-3895
import _lsprof
with support.catch_unraisable_exception() as cm:
obj = _lsprof.Profiler(lambda: int)
Reported by Pylint.
Line: 23
Column: 9
def test_bad_counter_during_dealloc(self):
# bpo-3895
import _lsprof
with support.catch_unraisable_exception() as cm:
obj = _lsprof.Profiler(lambda: int)
obj.enable()
obj = _lsprof.Profiler(1)
Reported by Pylint.
Line: 25
Column: 54
# bpo-3895
import _lsprof
with support.catch_unraisable_exception() as cm:
obj = _lsprof.Profiler(lambda: int)
obj.enable()
obj = _lsprof.Profiler(1)
obj.disable()
obj.clear()
Reported by Pylint.
Line: 34
Column: 5
self.assertEqual(cm.unraisable.exc_type, TypeError)
def test_profile_enable_disable(self):
prof = self.profilerclass()
# Make sure we clean ourselves up if the test fails for some reason.
self.addCleanup(prof.disable)
prof.enable()
Reported by Pylint.
Line: 45
Column: 5
prof.disable()
self.assertIs(sys.getprofile(), None)
def test_profile_as_context_manager(self):
prof = self.profilerclass()
# Make sure we clean ourselves up if the test fails for some reason.
self.addCleanup(prof.disable)
with prof as __enter__return_value:
Reported by Pylint.
Line: 61
Column: 1
# profile shouldn't be set once we leave the with-block.
self.assertIs(sys.getprofile(), None)
class TestCommandLine(unittest.TestCase):
def test_sort(self):
rc, out, err = assert_python_failure('-m', 'cProfile', '-s', 'demo')
self.assertGreater(rc, 0)
self.assertIn(b"option -s: invalid choice: 'demo'", err)
Reported by Pylint.
Line: 62
Column: 5
self.assertIs(sys.getprofile(), None)
class TestCommandLine(unittest.TestCase):
def test_sort(self):
rc, out, err = assert_python_failure('-m', 'cProfile', '-s', 'demo')
self.assertGreater(rc, 0)
self.assertIn(b"option -s: invalid choice: 'demo'", err)
Reported by Pylint.
Line: 63
Column: 9
class TestCommandLine(unittest.TestCase):
def test_sort(self):
rc, out, err = assert_python_failure('-m', 'cProfile', '-s', 'demo')
self.assertGreater(rc, 0)
self.assertIn(b"option -s: invalid choice: 'demo'", err)
def main():
Reported by Pylint.
Lib/test/test_dictcomps.py
13 issues
Line: 1
Column: 1
import unittest
# For scope testing.
g = "Global variable"
class DictComprehensionTest(unittest.TestCase):
def test_basics(self):
Reported by Pylint.
Line: 4
Column: 1
import unittest
# For scope testing.
g = "Global variable"
class DictComprehensionTest(unittest.TestCase):
def test_basics(self):
Reported by Pylint.
Line: 7
Column: 1
g = "Global variable"
class DictComprehensionTest(unittest.TestCase):
def test_basics(self):
expected = {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17,
8: 18, 9: 19}
actual = {k: k + 10 for k in range(10)}
Reported by Pylint.
Line: 9
Column: 5
class DictComprehensionTest(unittest.TestCase):
def test_basics(self):
expected = {0: 10, 1: 11, 2: 12, 3: 13, 4: 14, 5: 15, 6: 16, 7: 17,
8: 18, 9: 19}
actual = {k: k + 10 for k in range(10)}
self.assertEqual(actual, expected)
Reported by Pylint.
Line: 19
Column: 5
actual = {k: v for k in range(10) for v in range(10) if k == v}
self.assertEqual(actual, expected)
def test_scope_isolation(self):
k = "Local Variable"
expected = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None,
6: None, 7: None, 8: None, 9: None}
actual = {k: None for k in range(10)}
Reported by Pylint.
Line: 38
Column: 5
self.assertEqual(k, "Local Variable")
self.assertEqual(actual, expected)
def test_scope_isolation_from_global(self):
expected = {0: None, 1: None, 2: None, 3: None, 4: None, 5: None,
6: None, 7: None, 8: None, 9: None}
actual = {g: None for g in range(10)}
self.assertEqual(actual, expected)
self.assertEqual(g, "Global variable")
Reported by Pylint.
Line: 55
Column: 5
self.assertEqual(g, "Global variable")
self.assertEqual(actual, expected)
def test_global_visibility(self):
expected = {0: 'Global variable', 1: 'Global variable',
2: 'Global variable', 3: 'Global variable',
4: 'Global variable', 5: 'Global variable',
6: 'Global variable', 7: 'Global variable',
8: 'Global variable', 9: 'Global variable'}
Reported by Pylint.
Line: 64
Column: 5
actual = {k: g for k in range(10)}
self.assertEqual(actual, expected)
def test_local_visibility(self):
v = "Local variable"
expected = {0: 'Local variable', 1: 'Local variable',
2: 'Local variable', 3: 'Local variable',
4: 'Local variable', 5: 'Local variable',
6: 'Local variable', 7: 'Local variable',
Reported by Pylint.
Line: 65
Column: 9
self.assertEqual(actual, expected)
def test_local_visibility(self):
v = "Local variable"
expected = {0: 'Local variable', 1: 'Local variable',
2: 'Local variable', 3: 'Local variable',
4: 'Local variable', 5: 'Local variable',
6: 'Local variable', 7: 'Local variable',
8: 'Local variable', 9: 'Local variable'}
Reported by Pylint.
Line: 75
Column: 5
self.assertEqual(actual, expected)
self.assertEqual(v, "Local variable")
def test_illegal_assignment(self):
with self.assertRaisesRegex(SyntaxError, "cannot assign"):
compile("{x: y for y, x in ((1, 2), (3, 4))} = 5", "<test>",
"exec")
with self.assertRaisesRegex(SyntaxError, "illegal expression"):
Reported by Pylint.
Lib/test/test_importlib/test_contents.py
13 issues
Line: 4
Column: 1
import unittest
from importlib import resources
from . import data01
from .resources import util
class ContentsTests:
expected = {
Reported by Pylint.
Line: 5
Column: 1
from importlib import resources
from . import data01
from .resources import util
class ContentsTests:
expected = {
'__init__.py',
Reported by Pylint.
Line: 18
Column: 56
}
def test_contents(self):
assert self.expected <= set(resources.contents(self.data))
class ContentsDiskTests(ContentsTests, unittest.TestCase):
def setUp(self):
self.data = data01
Reported by Pylint.
Line: 40
Column: 9
}
def setUp(self):
from . import namespacedata01
self.data = namespacedata01
Reported by Pylint.
Line: 1
Column: 1
import unittest
from importlib import resources
from . import data01
from .resources import util
class ContentsTests:
expected = {
Reported by Pylint.
Line: 8
Column: 1
from .resources import util
class ContentsTests:
expected = {
'__init__.py',
'binary.file',
'subdirectory',
'utf-16.file',
Reported by Pylint.
Line: 8
Column: 1
from .resources import util
class ContentsTests:
expected = {
'__init__.py',
'binary.file',
'subdirectory',
'utf-16.file',
Reported by Pylint.
Line: 17
Column: 5
'utf-8.file',
}
def test_contents(self):
assert self.expected <= set(resources.contents(self.data))
class ContentsDiskTests(ContentsTests, unittest.TestCase):
def setUp(self):
Reported by Pylint.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
}
def test_contents(self):
assert self.expected <= set(resources.contents(self.data))
class ContentsDiskTests(ContentsTests, unittest.TestCase):
def setUp(self):
self.data = data01
Reported by Bandit.
Line: 21
Column: 1
assert self.expected <= set(resources.contents(self.data))
class ContentsDiskTests(ContentsTests, unittest.TestCase):
def setUp(self):
self.data = data01
class ContentsZipTests(ContentsTests, util.ZipSetup, unittest.TestCase):
Reported by Pylint.
Lib/test/test_datetime.py
13 issues
Line: 16
Column: 3
fast_tests = import_fresh_module(TESTS, fresh=['datetime',
'_datetime', '_strptime'])
finally:
# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
# XXX: but it does not, so we have to cleanup ourselves.
for modname in ['datetime', '_datetime', '_strptime']:
sys.modules.pop(modname, None)
test_modules = [pure_tests, fast_tests]
test_suffixes = ["_Pure", "_Fast"]
Reported by Pylint.
Line: 17
Column: 3
'_datetime', '_strptime'])
finally:
# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
# XXX: but it does not, so we have to cleanup ourselves.
for modname in ['datetime', '_datetime', '_strptime']:
sys.modules.pop(modname, None)
test_modules = [pure_tests, fast_tests]
test_suffixes = ["_Pure", "_Fast"]
# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
Reported by Pylint.
Line: 22
Column: 3
sys.modules.pop(modname, None)
test_modules = [pure_tests, fast_tests]
test_suffixes = ["_Pure", "_Fast"]
# XXX(gb) First run all the _Pure tests, then all the _Fast tests. You might
# not believe this, but in spite of all the sys.modules trickery running a _Pure
# test last will leave a mix of pure and native datetime stuff lying around.
all_test_classes = []
for module, suffix in zip(test_modules, test_suffixes):
Reported by Pylint.
Line: 42
Column: 30
cls.__name__ += suffix
cls.__qualname__ += suffix
@classmethod
def setUpClass(cls_, module=module):
cls_._save_sys_modules = sys.modules.copy()
sys.modules[TESTS] = module
sys.modules['datetime'] = module.datetime_module
sys.modules['_strptime'] = module._strptime
@classmethod
Reported by Pylint.
Line: 43
Column: 13
cls.__qualname__ += suffix
@classmethod
def setUpClass(cls_, module=module):
cls_._save_sys_modules = sys.modules.copy()
sys.modules[TESTS] = module
sys.modules['datetime'] = module.datetime_module
sys.modules['_strptime'] = module._strptime
@classmethod
def tearDownClass(cls_):
Reported by Pylint.
Line: 46
Column: 40
cls_._save_sys_modules = sys.modules.copy()
sys.modules[TESTS] = module
sys.modules['datetime'] = module.datetime_module
sys.modules['_strptime'] = module._strptime
@classmethod
def tearDownClass(cls_):
sys.modules.clear()
sys.modules.update(cls_._save_sys_modules)
cls.setUpClass = setUpClass
Reported by Pylint.
Line: 50
Column: 32
@classmethod
def tearDownClass(cls_):
sys.modules.clear()
sys.modules.update(cls_._save_sys_modules)
cls.setUpClass = setUpClass
cls.tearDownClass = tearDownClass
all_test_classes.extend(test_classes)
def test_main():
Reported by Pylint.
Line: 1
Column: 1
import unittest
import sys
from test.support import run_unittest
from test.support.import_helper import import_fresh_module
TESTS = 'test.datetimetester'
Reported by Pylint.
Line: 42
Column: 9
cls.__name__ += suffix
cls.__qualname__ += suffix
@classmethod
def setUpClass(cls_, module=module):
cls_._save_sys_modules = sys.modules.copy()
sys.modules[TESTS] = module
sys.modules['datetime'] = module.datetime_module
sys.modules['_strptime'] = module._strptime
@classmethod
Reported by Pylint.
Line: 42
Column: 9
cls.__name__ += suffix
cls.__qualname__ += suffix
@classmethod
def setUpClass(cls_, module=module):
cls_._save_sys_modules = sys.modules.copy()
sys.modules[TESTS] = module
sys.modules['datetime'] = module.datetime_module
sys.modules['_strptime'] = module._strptime
@classmethod
Reported by Pylint.