Update some of changed libs and tests from 3.14.5 -> 3.14.6 (part 3) (#8086)

This commit is contained in:
Shahar Naveh authored and GitHub committed 2026-06-12 23:50:07 +09:00
1 parent 057e968385
commit fa84378b71
12 files changed
+265 -107

No files matched your search

+2 -5
View File
@@ -2622,10 +2622,6 @@ class FreeThreadingTest(unittest.TestCase):
b.wait()
a += c
def irepeat(b, a): # MODIFIES!
b.wait()
a *= 2
def subscript(b, a):
b.wait()
try: assert a[0] != 0xdd
@@ -2747,9 +2743,10 @@ class FreeThreadingTest(unittest.TestCase):
check([clear] + [repeat] * 10)
check([clear] + [iconcat] * 10)
check([clear] + [irepeat] * 10)
check([clear] + [ass_subscript] * 10)
check([clear] + [repr_] * 10)
# gh-148605: Do not test "a *= 2" since it allocates up to 4 GiB using
# 10 threads
# value errors
+16
View File
@@ -1033,6 +1033,22 @@ class BZ2DecompressorTest(BaseTest):
# Previously, a second call could crash due to internal inconsistency
self.assertRaises(Exception, bzd.decompress, self.BAD_DATA * 30)
@unittest.expectedFailure # TODO: RUSTPYTHON; Wrong error message
def test_decompress_after_data_error(self):
data = bytes.fromhex(
"425a6839314159265359000000000000007fffff000000000000000000000000"
"00000000000000000000000000000000000000e0370000000000000000000000"
"000000000000000000000000000000000000000000000000000083f3"
)
bzd = BZ2Decompressor()
with self.assertRaisesRegex(OSError, "Invalid data stream"):
bzd.decompress(data)
# Previously, a second call could crash due to internal inconsistency
self.assertFalse(bzd.needs_input)
self.assertFalse(bzd.eof)
with self.assertRaisesRegex(ValueError, "previous error"):
bzd.decompress(b'\x00' * 18)
@support.refcount_test
def test_refleaks_in___init__(self):
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
+2
View File
@@ -1014,6 +1014,7 @@ class CmdLineTest(unittest.TestCase):
p = subprocess.run([sys.executable, "-c", code],
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=env)
support.skip_on_low_desktop_heap_memory_subprocess(p.returncode)
self.assertEqual(p.returncode, 0)
# Then test that FIleIO is used when PYTHONLEGACYWINDOWSSTDIO is set.
@@ -1022,6 +1023,7 @@ class CmdLineTest(unittest.TestCase):
p = subprocess.run([sys.executable, "-c", code],
creationflags=subprocess.CREATE_NEW_CONSOLE,
env=env)
support.skip_on_low_desktop_heap_memory_subprocess(p.returncode)
self.assertEqual(p.returncode, 0)
@unittest.expectedFailure # TODO: RUSTPYTHON
+16
View File
@@ -287,6 +287,22 @@ class TestBasic(unittest.TestCase):
else:
self.assertEqual(d.index(element, start, stop), target)
# Test stop argument
for elem in d:
index = d.index(elem)
self.assertEqual(
index,
d.index(elem, 0),
)
self.assertEqual(
index,
d.index(elem, 0, len(d)),
)
self.assertEqual(
index,
d.index(elem, 0, len(d) + 100),
)
# Test large start argument
d = deque(range(0, 10000, 10))
for step in range(100):
+10 -3
View File
@@ -55,15 +55,14 @@ from urllib.parse import SplitResult, ParseResult
from unittest.case import _AssertRaisesContext
from queue import Queue, SimpleQueue
from weakref import WeakSet, ReferenceType, ref
import typing
from typing import Unpack
try:
from tkinter import Event
except ImportError:
Event = None
from string.templatelib import Template, Interpolation
from typing import TypeVar
import typing
from typing import TypeVar, Unpack
T = TypeVar('T')
K = TypeVar('K')
V = TypeVar('V')
@@ -619,6 +618,14 @@ class BaseTest(unittest.TestCase):
self.assertEqual(deeply_nested_specialized.__args__, ([str, [float], int], float))
self.assertEqual(deeply_nested_specialized.__parameters__, ())
def test_gh150146(self):
# It used to crash:
for container in [memoryview, list, tuple]:
with self.subTest(container=container):
x = container[TypeVar("")]
with self.assertRaises(TypeError):
x[*typing.Mapping[..., ...]]
class TypeIterationTests(unittest.TestCase):
_UNITERABLE_TYPES = (list, tuple)
+41 -48
View File
@@ -1,5 +1,7 @@
"""Test script for the grp module."""
import random
import string
import unittest
from test.support import import_helper
@@ -47,64 +49,55 @@ class GroupDatabaseTestCase(unittest.TestCase):
# Discovered on Ubuntu 5.04 (custom).
self.assertEqual(e2.gr_name.lower(), name.lower())
@unittest.expectedFailure # TODO: RUSTPYTHON; KeyError: 'getgrgid: group id 340282366920938463463374607431768211456 not found'
def test_errors(self):
self.assertRaises(TypeError, grp.getgrgid)
self.assertRaises(TypeError, grp.getgrgid, 3.14)
self.assertRaises(TypeError, grp.getgrgid, 0.0)
self.assertRaises(TypeError, grp.getgrgid, 0, 0)
# should be out of gid_t range
self.assertRaises(OverflowError, grp.getgrgid, 2**128)
self.assertRaises(OverflowError, grp.getgrgid, -2**128)
self.assertRaises(TypeError, grp.getgrnam)
self.assertRaises(TypeError, grp.getgrnam, 42)
self.assertRaises(TypeError, grp.getgrall, 42)
self.assertRaises(TypeError, grp.getgrnam, b'root')
self.assertRaises(TypeError, grp.getgrnam, 'root', 0)
# embedded null character
self.assertRaisesRegex(ValueError, 'null', grp.getgrnam, 'a\x00b')
self.assertRaisesRegex(ValueError, 'null', grp.getgrnam, 'root\x00')
self.assertRaises(UnicodeEncodeError, grp.getgrnam, 'roo\udc74')
self.assertRaises(KeyError, grp.getgrnam, '')
self.assertRaises(TypeError, grp.getgrall, 42)
# try to get some errors
bynames = {}
bygids = {}
for (n, p, g, mem) in grp.getgrall():
if not n or n == '+':
continue # skip NIS entries etc.
bynames[n] = g
bygids[g] = n
# Find a non-existent group name.
# getgrall() will not necessarily report all existing groups
# (typical for LDAP based directories in big organizations).
for _ in range(30):
fakename = ''.join(random.choices(string.ascii_lowercase, k=6))
try:
grp.getgrnam(fakename)
except KeyError:
break
else:
self.fail('Cannot find non-existent group name')
allnames = list(bynames.keys())
namei = 0
fakename = allnames[namei]
while fakename in bynames:
chars = list(fakename)
for i in range(len(chars)):
if chars[i] == 'z':
chars[i] = 'A'
break
elif chars[i] == 'Z':
continue
# Find a non-existent gid.
maxgid = 2**31
for _ in range(30):
fakegid = random.randrange(maxgid)
try:
grp.getgrgid(fakegid)
except KeyError:
break
except OverflowError:
if maxgid == 2**31:
maxgid = 2**16-1
elif maxgid == 2**16-1:
maxgid = 2**15
else:
chars[i] = chr(ord(chars[i]) + 1)
break
else:
namei = namei + 1
try:
fakename = allnames[namei]
except IndexError:
# should never happen... if so, just forget it
break
fakename = ''.join(chars)
self.assertRaises(KeyError, grp.getgrnam, fakename)
# Choose a non-existent gid.
fakegid = 4127
while fakegid in bygids:
fakegid = (fakegid * 3) % 0x10000
self.assertRaises(KeyError, grp.getgrgid, fakegid)
def test_noninteger_gid(self):
entries = grp.getgrall()
if not entries:
self.skipTest('no groups')
# Choose an existent gid.
gid = entries[0][2]
self.assertRaises(TypeError, grp.getgrgid, float(gid))
self.assertRaises(TypeError, grp.getgrgid, str(gid))
raise
else:
self.fail('Cannot find non-existent gid')
if __name__ == "__main__":
+10
View File
@@ -435,6 +435,16 @@ class NewIMAPTestsMixin:
r'\[AUTHENTICATIONFAILED\] invalid'):
client.authenticate('MYAUTH', lambda x: b'fake')
def test_invalid_login(self):
class MyServer(SimpleIMAPHandler):
def cmd_LOGIN(self, tag, args):
self.server.logged = args[0]
self._send_tagged(tag, 'NO', '[LOGIN] failed')
client, _ = self._setup(MyServer)
with self.assertRaisesRegex(imaplib.IMAP4.error,
r'\[LOGIN\] failed'):
client.login('user', 'wrongpass')
def test_valid_authentication_bytes(self):
class MyServer(SimpleIMAPHandler):
def cmd_AUTHENTICATE(self, tag, args):
+9
View File
@@ -360,6 +360,15 @@ class ImportTests(unittest.TestCase):
with self.assertRaises(ModuleNotFoundError):
import something_that_should_not_exist_anywhere
def test_import_null_byte_in_name_raises_ModuleNotFoundError(self):
# gh-150633: module names containing null bytes should not
# lead to duplicates in sys.modules
before = set(sys.modules.keys())
with self.assertRaises(ModuleNotFoundError):
__import__('zipimport\x00junk')
self.assertEqual(set(sys.modules.keys()), before)
def test_from_import_missing_module_raises_ModuleNotFoundError(self):
with self.assertRaises(ModuleNotFoundError):
from something_that_should_not_exist_anywhere import blah
+34
View File
@@ -171,6 +171,17 @@ class ListComprehensionTest(unittest.TestCase):
"""
self._check_in_scopes(code, raises=NameError)
def test_references___class___nested(self):
code = """
res = [(lambda: __class__)() for _ in [1]]
"""
self._check_in_scopes(code, raises=NameError)
def test_references___class___nested_used(self):
class _C:
res = [lambda: __class__ for _ in [1]]
self.assertIs(_C.res[0](), _C)
def test_references___class___defined(self):
code = """
__class__ = 2
@@ -180,18 +191,41 @@ class ListComprehensionTest(unittest.TestCase):
code, outputs={"res": [2]}, scopes=["module", "function"])
self._check_in_scopes(code, raises=NameError, scopes=["class"])
def test_references___class___defined_nested(self):
code = """
__class__ = 2
res = [(lambda: __class__)() for x in [1]]
"""
self._check_in_scopes(
code, outputs={"res": [2]}, scopes=["module", "function"])
self._check_in_scopes(code, raises=NameError, scopes=["class"])
def test_references___classdict__(self):
code = """
class i: [__classdict__ for x in y]
"""
self._check_in_scopes(code, raises=NameError)
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: compiler_make_closure: cannot find '__classdict__' in parent vars
def test_references___classdict___nested(self):
class _C:
# res = [(lambda: __classdict__)() for _ in [1]] # TODO: RUSTPYTHON
pass # TODO: RUSTPYTHON
self.assertIn("res", _C.res[0])
def test_references___conditional_annotations__(self):
code = """
class i: [__conditional_annotations__ for x in y]
"""
self._check_in_scopes(code, raises=NameError)
@unittest.expectedFailure # TODO: RUSTPYTHON; SyntaxError: compiler_make_closure: cannot find '__conditional_annotations__' in parent vars
def test_references___conditional_annotations___nested(self):
code = """
class i: [lambda: __conditional_annotations__ for x in y]
"""
self._check_in_scopes(code, raises=NameError)
def test_references___class___enclosing(self):
code = """
__class__ = 2
+19
View File
@@ -987,6 +987,25 @@ class CStringIOTest(PyStringIOTest):
memio.close()
self.assertRaises(ValueError, memio.__setstate__, ("closed", "", 0, None))
def test_write_str_subclass(self):
# Writing a str subclass should use the subclass's unicode data
# directly, not call __str__ on it (which may return a different
# value). gh-149047
class MyStr(str):
def __str__(self):
return "WRONG"
s = MyStr("correct")
memio = self.ioclass()
memio.write(s)
self.assertEqual(memio.getvalue(), "correct")
# Also test the fast path where pos == string_size (STATE_ACCUMULATING)
memio2 = self.ioclass()
memio2.write(MyStr("hello "))
memio2.write(MyStr("world"))
self.assertEqual(memio2.getvalue(), "hello world")
@unittest.expectedFailure # TODO: RUSTPYTHON; +
def test_issue5265(self):
return super().test_issue5265()
+56 -1
View File
@@ -6,8 +6,9 @@ import sys
import unittest.mock
from platform import win32_edition
from test import support
from test.support import cpython_only, force_not_colorized, os_helper
from test.support import cpython_only, force_not_colorized, os_helper, requires_subprocess
from test.support.import_helper import ensure_lazy_imports
from test.support.script_helper import assert_python_ok, assert_python_failure
try:
import _winapi
@@ -506,5 +507,59 @@ class CommandLineTest(unittest.TestCase):
self.assertEqual(result, expected)
@requires_subprocess()
class CommandLineSubprocessTest(unittest.TestCase):
def test_help(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '--help')
self.assertIn(b'mimetypes', stdout)
self.assertIn(b'--extension', stdout)
self.assertIn(b'--lenient', stdout)
def test_type_lookup(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf')
self.assertEqual(stdout.strip(), b'type: application/pdf encoding: None')
self.assertEqual(stderr, b'')
def test_type_lookup_unknown(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', 'foo.unknownext12345')
self.assertEqual(stdout.strip(), b'error: media type unknown for foo.unknownext12345')
self.assertEqual(stderr, b'')
def test_extension_flag(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', 'image/jpeg')
self.assertEqual(stdout.strip(), b'.jpg')
self.assertEqual(stderr, b'')
def test_extension_flag_unknown(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '-e', 'image/unknowntype12345')
self.assertEqual(stdout.strip(), b'error: unknown type image/unknowntype12345')
self.assertEqual(stderr, b'')
def test_lenient_flag(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', '-e', '--lenient', 'text/xul')
self.assertIn(b'.xul', stdout)
self.assertEqual(stderr, b'')
def test_multiple_inputs(self):
rc, stdout, stderr = assert_python_ok('-m', 'mimetypes', 'foo.pdf', 'foo.png')
self.assertIn(b'type: application/pdf encoding: None', stdout)
self.assertIn(b'type: image/png encoding: None', stdout)
self.assertEqual(stderr, b'')
def test_multiple_inputs_with_error(self):
rc, stdout, stderr = assert_python_failure(
'-m', 'mimetypes', 'foo.pdf', 'foo.unknownext12345'
)
self.assertIn(b'type: application/pdf encoding: None', stdout)
self.assertIn(b'error: media type unknown for foo.unknownext12345', stdout)
self.assertEqual(stderr, b'')
@force_not_colorized
def test_unknown_flag(self):
rc, stdout, stderr = assert_python_failure('-m', 'mimetypes', '--unknown-flag', 'foo.pdf')
self.assertEqual(stdout, b'')
self.assertIn(b'error: unrecognized arguments: --unknown-flag', stderr)
if __name__ == "__main__":
unittest.main()
+50 -50
View File
@@ -1,3 +1,5 @@
import random
import string
import sys
import unittest
from test.support import import_helper
@@ -56,59 +58,57 @@ class PwdTest(unittest.TestCase):
def test_errors(self):
self.assertRaises(TypeError, pwd.getpwuid)
self.assertRaises(TypeError, pwd.getpwuid, 3.14)
self.assertRaises(TypeError, pwd.getpwnam)
self.assertRaises(TypeError, pwd.getpwnam, 42)
self.assertRaises(TypeError, pwd.getpwall, 42)
# embedded null character
self.assertRaisesRegex(ValueError, 'null', pwd.getpwnam, 'a\x00b')
# try to get some errors
bynames = {}
byuids = {}
for (n, p, u, g, gecos, d, s) in pwd.getpwall():
bynames[n] = u
byuids[u] = n
allnames = list(bynames.keys())
namei = 0
fakename = allnames[namei] if allnames else "invaliduser"
while fakename in bynames:
chars = list(fakename)
for i in range(len(chars)):
if chars[i] == 'z':
chars[i] = 'A'
break
elif chars[i] == 'Z':
continue
else:
chars[i] = chr(ord(chars[i]) + 1)
break
else:
namei = namei + 1
try:
fakename = allnames[namei]
except IndexError:
# should never happen... if so, just forget it
break
fakename = ''.join(chars)
self.assertRaises(KeyError, pwd.getpwnam, fakename)
# In some cases, byuids isn't a complete list of all users in the
# system, so if we try to pick a value not in byuids (via a perturbing
# loop, say), pwd.getpwuid() might still be able to find data for that
# uid. Using sys.maxint may provoke the same problems, but hopefully
# it will be a more repeatable failure.
fakeuid = sys.maxsize
self.assertNotIn(fakeuid, byuids)
self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
# -1 shouldn't be a valid uid because it has a special meaning in many
# uid-related functions
self.assertRaises(KeyError, pwd.getpwuid, -1)
self.assertRaises(TypeError, pwd.getpwuid, 0.0)
self.assertRaises(TypeError, pwd.getpwuid, 0, 0)
# should be out of uid_t range
self.assertRaises(KeyError, pwd.getpwuid, 2**128)
self.assertRaises(KeyError, pwd.getpwuid, -2**128)
self.assertRaises(TypeError, pwd.getpwnam)
self.assertRaises(TypeError, pwd.getpwnam, 42)
self.assertRaises(TypeError, pwd.getpwnam, b'root')
self.assertRaises(TypeError, pwd.getpwnam, 'root', 0)
# embedded null character
self.assertRaisesRegex(ValueError, 'null', pwd.getpwnam, 'a\x00b')
self.assertRaisesRegex(ValueError, 'null', pwd.getpwnam, 'root\x00')
self.assertRaises(UnicodeEncodeError, pwd.getpwnam, 'roo\udc74')
self.assertRaises(KeyError, pwd.getpwnam, '')
self.assertRaises(TypeError, pwd.getpwall, 42)
# Find a non-existent user name.
# getpwall() will not necessarily report all existing users
# (typical for LDAP based directories in big organizations).
for _ in range(30):
fakename = ''.join(random.choices(string.ascii_lowercase, k=6))
try:
pwd.getpwnam(fakename)
except KeyError:
break
else:
self.fail('Cannot find non-existent user name')
# Find a non-existent uid.
maxuid = max(e.pw_uid for e in pwd.getpwall())
if maxuid < 2**15:
maxuid = 2**15
elif maxuid < 2**16:
maxuid = 2**16-1
else:
maxuid = 2**31
for _ in range(30):
fakeuid = random.randrange(maxuid)
try:
pwd.getpwuid(fakeuid)
except KeyError:
break
else:
self.fail('Cannot find non-existent uid')
# On Cygwin, getpwuid(-1) returns 'Unknown+User' user
if sys.platform != 'cygwin':
# -1 shouldn't be a valid uid because it has a special meaning in many
# uid-related functions
self.assertRaises(KeyError, pwd.getpwuid, -1)
if __name__ == "__main__":
unittest.main()