diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/__init__.py | 4 | ||||
-rw-r--r-- | Lib/inspect.py | 1 | ||||
-rw-r--r-- | Lib/logging/__init__.py | 11 | ||||
-rw-r--r-- | Lib/test/support/script_helper.py | 25 | ||||
-rw-r--r-- | Lib/test/test_curses.py | 4 | ||||
-rw-r--r-- | Lib/test/test_functools.py | 15 | ||||
-rw-r--r-- | Lib/test/test_imaplib.py | 2 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 8 | ||||
-rw-r--r-- | Lib/test/test_pow.py | 3 | ||||
-rw-r--r-- | Lib/test/test_socket.py | 10 | ||||
-rw-r--r-- | Lib/test/test_sysconfig.py | 6 | ||||
-rw-r--r-- | Lib/test/test_typing.py | 11 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 7 | ||||
-rw-r--r-- | Lib/test/test_urllib.py | 3 | ||||
-rw-r--r-- | Lib/typing.py | 10 | ||||
-rw-r--r-- | Lib/urllib/request.py | 1 | ||||
-rw-r--r-- | Lib/venv/scripts/common/activate (renamed from Lib/venv/scripts/posix/activate) | 0 |
17 files changed, 94 insertions, 27 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index 0d86078..1469b8b 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -327,6 +327,10 @@ class CDLL(object): """ _func_flags_ = _FUNCFLAG_CDECL _func_restype_ = c_int + # default values for repr + _name = '<uninitialized>' + _handle = 0 + _FuncPtr = None def __init__(self, name, mode=DEFAULT_MODE, handle=None, use_errno=False, diff --git a/Lib/inspect.py b/Lib/inspect.py index 6b9e0b0..9f9fcfe 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1416,7 +1416,6 @@ def getframeinfo(frame, context=1): except OSError: lines = index = None else: - start = max(start, 0) start = max(0, min(start, len(lines) - context)) lines = lines[start:start+context] index = lineno - 1 - start diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 22744e1..6455f39 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -129,9 +129,14 @@ def getLevelName(level): Otherwise, the string "Level %s" % level is returned. """ - # See Issues #22386 and #27937 for why it's this way - return (_levelToName.get(level) or _nameToLevel.get(level) or - "Level %s" % level) + # See Issues #22386, #27937 and #29220 for why it's this way + result = _levelToName.get(level) + if result is not None: + return result + result = _nameToLevel.get(level) + if result is not None: + return result + return "Level %s" % level def addLevelName(level, levelName): """ diff --git a/Lib/test/support/script_helper.py b/Lib/test/support/script_helper.py index 80889b1..ca5f9c20 100644 --- a/Lib/test/support/script_helper.py +++ b/Lib/test/support/script_helper.py @@ -70,17 +70,28 @@ def run_python_until_end(*args, **env_vars): elif not env_vars and not env_required: # ignore Python environment variables cmd_line.append('-E') - # Need to preserve the original environment, for in-place testing of - # shared library builds. - env = os.environ.copy() - # set TERM='' unless the TERM environment variable is passed explicitly - # see issues #11390 and #18300 - if 'TERM' not in env_vars: - env['TERM'] = '' + # But a special flag that can be set to override -- in this case, the # caller is responsible to pass the full environment. if env_vars.pop('__cleanenv', None): env = {} + if sys.platform == 'win32': + # Windows requires at least the SYSTEMROOT environment variable to + # start Python. + env['SYSTEMROOT'] = os.environ['SYSTEMROOT'] + + # Other interesting environment variables, not copied currently: + # COMSPEC, HOME, PATH, TEMP, TMPDIR, TMP. + else: + # Need to preserve the original environment, for in-place testing of + # shared library builds. + env = os.environ.copy() + + # set TERM='' unless the TERM environment variable is passed explicitly + # see issues #11390 and #18300 + if 'TERM' not in env_vars: + env['TERM'] = '' + env.update(env_vars) cmd_line.extend(args) proc = subprocess.Popen(cmd_line, stdin=subprocess.PIPE, diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index 14ba87f..3d8c50b 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -244,7 +244,7 @@ class TestCurses(unittest.TestCase): # Functions only available on a few platforms def test_colors_funcs(self): if not curses.has_colors(): - self.skip('requires colors support') + self.skipTest('requires colors support') curses.start_color() curses.init_pair(2, 1,1) curses.color_content(1) @@ -267,7 +267,7 @@ class TestCurses(unittest.TestCase): def test_getmouse(self): (availmask, oldmask) = curses.mousemask(curses.BUTTON1_PRESSED) if availmask == 0: - self.skip('mouse stuff not available') + self.skipTest('mouse stuff not available') curses.mouseinterval(10) # just verify these don't cause errors curses.ungetmouse(0, 0, 0, 0, curses.BUTTON1_PRESSED) diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py index b431e05..9ccd0ca 100644 --- a/Lib/test/test_functools.py +++ b/Lib/test/test_functools.py @@ -7,6 +7,7 @@ import pickle from random import choice import sys from test import support +import time import unittest from weakref import proxy try: @@ -1364,6 +1365,20 @@ class TestLRU: pause.reset() self.assertEqual(f.cache_info(), (0, (i+1)*n, m*n, i+1)) + @unittest.skipUnless(threading, 'This test requires threading.') + def test_lru_cache_threaded3(self): + @self.module.lru_cache(maxsize=2) + def f(x): + time.sleep(.01) + return 3 * x + def test(i, x): + with self.subTest(thread=i): + self.assertEqual(f(x), 3 * x, i) + threads = [threading.Thread(target=test, args=(i, v)) + for i, v in enumerate([1, 2, 2, 3, 2])] + with support.start_threads(threads): + pass + def test_need_for_rlock(self): # This will deadlock on an LRU cache that uses a regular lock diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 6e4a90f..a29b40a 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -477,7 +477,7 @@ class NewIMAPTests(NewIMAPTestsMixin, unittest.TestCase): @unittest.skipUnless(ssl, "SSL not available") class NewIMAPSSLTests(NewIMAPTestsMixin, unittest.TestCase): - imap_class = imaplib.IMAP4_SSL + imap_class = IMAP4_SSL server_class = SecureTCPServer def test_ssl_raises(self): diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 0e70ccd..1c85045 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -308,6 +308,14 @@ class BuiltinLevelsTest(BaseTest): self.assertEqual(logging.getLevelName('INFO'), logging.INFO) self.assertEqual(logging.getLevelName(logging.INFO), 'INFO') + def test_regression_29220(self): + """See issue #29220 for more information.""" + logging.addLevelName(logging.INFO, '') + self.addCleanup(logging.addLevelName, logging.INFO, 'INFO') + self.assertEqual(logging.getLevelName(logging.INFO), '') + self.assertEqual(logging.getLevelName(logging.NOTSET), 'NOTSET') + self.assertEqual(logging.getLevelName('NOTSET'), logging.NOTSET) + class BasicFilterTest(BaseTest): """Test the bundled Filter class.""" diff --git a/Lib/test/test_pow.py b/Lib/test/test_pow.py index 6feac40..ba608fb 100644 --- a/Lib/test/test_pow.py +++ b/Lib/test/test_pow.py @@ -59,9 +59,6 @@ class PowTest(unittest.TestCase): def test_powint(self): self.powtest(int) - def test_powlong(self): - self.powtest(int) - def test_powfloat(self): self.powtest(float) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index ea3ca28..70c03f9 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4719,14 +4719,10 @@ def isTipcAvailable(): return False try: f = open("/proc/modules") - except IOError as e: + except (FileNotFoundError, IsADirectoryError, PermissionError): # It's ok if the file does not exist, is a directory or if we - # have not the permission to read it. In any other case it's a - # real error, so raise it again. - if e.errno in (errno.ENOENT, errno.EISDIR, errno.EACCES): - return False - else: - raise + # have not the permission to read it. + return False with f: for line in f: if line.startswith("tipc "): diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py index a23bf06a..3830679 100644 --- a/Lib/test/test_sysconfig.py +++ b/Lib/test/test_sysconfig.py @@ -5,7 +5,8 @@ import subprocess import shutil from copy import copy -from test.support import (run_unittest, TESTFN, unlink, check_warnings, +from test.support import (run_unittest, + import_module, TESTFN, unlink, check_warnings, captured_stdout, skip_unless_symlink, change_cwd) import sysconfig @@ -387,7 +388,8 @@ class TestSysConfig(unittest.TestCase): @unittest.skipUnless(sys.platform == 'linux', 'Linux-specific test') def test_triplet_in_ext_suffix(self): - import ctypes, platform, re + ctypes = import_module('ctypes') + import platform, re machine = platform.machine() suffix = sysconfig.get_config_var('EXT_SUFFIX') if re.match('(aarch64|arm|mips|ppc|powerpc|s390|sparc)', machine): diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index d203ce3..7585412 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1572,6 +1572,9 @@ class CollectionsAbcTests(BaseTestCase): def test_list(self): self.assertIsSubclass(list, typing.List) + def test_deque(self): + self.assertIsSubclass(collections.deque, typing.Deque) + def test_set(self): self.assertIsSubclass(set, typing.Set) self.assertNotIsSubclass(frozenset, typing.Set) @@ -1642,6 +1645,14 @@ class CollectionsAbcTests(BaseTestCase): self.assertIsSubclass(MyDefDict, collections.defaultdict) self.assertNotIsSubclass(collections.defaultdict, MyDefDict) + def test_no_deque_instantiation(self): + with self.assertRaises(TypeError): + typing.Deque() + with self.assertRaises(TypeError): + typing.Deque[T]() + with self.assertRaises(TypeError): + typing.Deque[int]() + def test_no_set_instantiation(self): with self.assertRaises(TypeError): typing.Set() diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index f696a5b..3136ea1 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -464,6 +464,13 @@ class UnicodeTest(string_tests.CommonTest, self.checkraises(TypeError, ' ', 'join', [1, 2, 3]) self.checkraises(TypeError, ' ', 'join', ['1', '2', 3]) + @unittest.skipIf(sys.maxsize > 2**32, + 'needs too much memory on a 64-bit platform') + def test_join_overflow(self): + size = int(sys.maxsize**0.5) + 1 + seq = ('A' * size,) * size + self.assertRaises(OverflowError, ''.join, seq) + def test_replace(self): string_tests.CommonTest.test_replace(self) diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 247598a..1772399 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -247,11 +247,12 @@ class ProxyTests(unittest.TestCase): def test_proxy_bypass_environment_host_match(self): bypass = urllib.request.proxy_bypass_environment self.env.set('NO_PROXY', - 'localhost, anotherdomain.com, newdomain.com:1234') + 'localhost, anotherdomain.com, newdomain.com:1234, .d.o.t') self.assertTrue(bypass('localhost')) self.assertTrue(bypass('LocalHost')) # MixedCase self.assertTrue(bypass('LOCALHOST')) # UPPERCASE self.assertTrue(bypass('newdomain.com:1234')) + self.assertTrue(bypass('foo.d.o.t')) # issue 29142 self.assertTrue(bypass('anotherdomain.com:8888')) self.assertTrue(bypass('www.newdomain.com:1234')) self.assertFalse(bypass('prelocalhost')) diff --git a/Lib/typing.py b/Lib/typing.py index 34845b7..2821c3c 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -59,6 +59,7 @@ __all__ = [ 'SupportsRound', # Concrete collection types. + 'Deque', 'Dict', 'DefaultDict', 'List', @@ -1771,6 +1772,15 @@ class List(list, MutableSequence[T], extra=list): "use list() instead") return _generic_new(list, cls, *args, **kwds) +class Deque(collections.deque, MutableSequence[T], extra=collections.deque): + + __slots__ = () + + def __new__(cls, *args, **kwds): + if _geqv(cls, Deque): + raise TypeError("Type Deque cannot be instantiated; " + "use deque() instead") + return _generic_new(collections.deque, cls, *args, **kwds) class Set(set, MutableSet[T], extra=set): diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index a4bf97d..a46c689 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2450,6 +2450,7 @@ def proxy_bypass_environment(host, proxies=None): no_proxy_list = [proxy.strip() for proxy in no_proxy.split(',')] for name in no_proxy_list: if name: + name = name.lstrip('.') # ignore leading dots name = re.escape(name) pattern = r'(.+\.)?%s$' % name if (re.match(pattern, hostonly, re.I) diff --git a/Lib/venv/scripts/posix/activate b/Lib/venv/scripts/common/activate index c78a4ef..c78a4ef 100644 --- a/Lib/venv/scripts/posix/activate +++ b/Lib/venv/scripts/common/activate |