mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #7148 from ShaharNaveh/update-libs-1
Update some libs & tests to 3.14.3
This commit is contained in:
6
Lib/mailbox.py
vendored
6
Lib/mailbox.py
vendored
@@ -2183,11 +2183,7 @@ def _unlock_file(f):
|
||||
|
||||
def _create_carefully(path):
|
||||
"""Create a file if it doesn't exist and open for reading and writing."""
|
||||
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o666)
|
||||
try:
|
||||
return open(path, 'rb+')
|
||||
finally:
|
||||
os.close(fd)
|
||||
return open(path, 'xb+')
|
||||
|
||||
def _create_temporary(path):
|
||||
"""Create a temp file based on path and open for reading and writing."""
|
||||
|
||||
8
Lib/test/test_binascii.py
vendored
8
Lib/test/test_binascii.py
vendored
@@ -38,13 +38,13 @@ class BinASCIITest(unittest.TestCase):
|
||||
|
||||
def test_exceptions(self):
|
||||
# Check module exceptions
|
||||
self.assertTrue(issubclass(binascii.Error, Exception))
|
||||
self.assertTrue(issubclass(binascii.Incomplete, Exception))
|
||||
self.assertIsSubclass(binascii.Error, Exception)
|
||||
self.assertIsSubclass(binascii.Incomplete, Exception)
|
||||
|
||||
def test_functions(self):
|
||||
# Check presence of all functions
|
||||
for name in all_functions:
|
||||
self.assertTrue(hasattr(getattr(binascii, name), '__call__'))
|
||||
self.assertHasAttr(getattr(binascii, name), '__call__')
|
||||
self.assertRaises(TypeError, getattr(binascii, name))
|
||||
|
||||
def test_returned_value(self):
|
||||
@@ -117,7 +117,7 @@ class BinASCIITest(unittest.TestCase):
|
||||
# empty strings. TBD: shouldn't it raise an exception instead ?
|
||||
self.assertEqual(binascii.a2b_base64(self.type2test(fillers)), b'')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_base64_strict_mode(self):
|
||||
# Test base64 with strict mode on
|
||||
def _assertRegexTemplate(assert_regex: str, data: bytes, non_strict_mode_expected_result: bytes):
|
||||
|
||||
4
Lib/test/test_mailbox.py
vendored
4
Lib/test/test_mailbox.py
vendored
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import stat
|
||||
import socket
|
||||
import email
|
||||
import email.message
|
||||
@@ -13,7 +12,6 @@ from test.support import import_helper
|
||||
from test.support import os_helper
|
||||
from test.support import refleak_helper
|
||||
from test.support import socket_helper
|
||||
from test.support.testcase import ExtraAssertions
|
||||
import unittest
|
||||
import textwrap
|
||||
import mailbox
|
||||
@@ -1267,7 +1265,7 @@ class _TestMboxMMDF(_TestSingleFile):
|
||||
self._box.close()
|
||||
|
||||
|
||||
class TestMbox(_TestMboxMMDF, unittest.TestCase, ExtraAssertions):
|
||||
class TestMbox(_TestMboxMMDF, unittest.TestCase):
|
||||
|
||||
_factory = lambda self, path, factory=None: mailbox.mbox(path, factory)
|
||||
|
||||
|
||||
59
Lib/test/test_pyclbr.py
vendored
59
Lib/test/test_pyclbr.py
vendored
@@ -3,16 +3,17 @@
|
||||
Nick Mathewson
|
||||
'''
|
||||
|
||||
import importlib.machinery
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
from textwrap import dedent
|
||||
from types import FunctionType, MethodType, BuiltinFunctionType
|
||||
import pyclbr
|
||||
from unittest import TestCase, main as unittest_main
|
||||
from test.test_importlib import util as test_importlib_util
|
||||
import warnings
|
||||
from test.support.testcase import ExtraAssertions
|
||||
|
||||
import unittest # TODO: RUSTPYTHON
|
||||
import unittest # XXX: RUSTPYTHON; importing to be able to skip tests
|
||||
|
||||
|
||||
StaticMethodType = type(staticmethod(lambda: None))
|
||||
@@ -25,7 +26,30 @@ ClassMethodType = type(classmethod(lambda c: None))
|
||||
# is imperfect (as designed), testModule is called with a set of
|
||||
# members to ignore.
|
||||
|
||||
class PyclbrTest(TestCase, ExtraAssertions):
|
||||
|
||||
@contextmanager
|
||||
def temporary_main_spec():
|
||||
"""
|
||||
A context manager that temporarily sets the `__spec__` attribute
|
||||
of the `__main__` module if it's missing.
|
||||
"""
|
||||
main_mod = sys.modules.get("__main__")
|
||||
if main_mod is None:
|
||||
yield # Do nothing if __main__ is not present
|
||||
return
|
||||
|
||||
original_spec = getattr(main_mod, "__spec__", None)
|
||||
if original_spec is None:
|
||||
main_mod.__spec__ = importlib.machinery.ModuleSpec(
|
||||
name="__main__", loader=None, origin="built-in"
|
||||
)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
main_mod.__spec__ = original_spec
|
||||
|
||||
|
||||
class PyclbrTest(TestCase):
|
||||
|
||||
def assertListEq(self, l1, l2, ignore):
|
||||
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
|
||||
@@ -81,7 +105,7 @@ class PyclbrTest(TestCase, ExtraAssertions):
|
||||
for name, value in dict.items():
|
||||
if name in ignore:
|
||||
continue
|
||||
self.assertHasAttr(module, name, ignore)
|
||||
self.assertHasAttr(module, name)
|
||||
py_item = getattr(module, name)
|
||||
if isinstance(value, pyclbr.Function):
|
||||
self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
|
||||
@@ -105,6 +129,8 @@ class PyclbrTest(TestCase, ExtraAssertions):
|
||||
|
||||
actualMethods = []
|
||||
for m in py_item.__dict__.keys():
|
||||
if m == "__annotate__":
|
||||
continue
|
||||
if ismethod(py_item, getattr(py_item, m), m):
|
||||
actualMethods.append(m)
|
||||
|
||||
@@ -146,12 +172,12 @@ class PyclbrTest(TestCase, ExtraAssertions):
|
||||
self.checkModule('pyclbr')
|
||||
# XXX: Metaclasses are not supported
|
||||
# self.checkModule('ast')
|
||||
self.checkModule('doctest', ignore=("TestResults", "_SpoofOut",
|
||||
"DocTestCase", '_DocTestSuite'))
|
||||
with temporary_main_spec():
|
||||
self.checkModule('doctest', ignore=("TestResults", "_SpoofOut",
|
||||
"DocTestCase", '_DocTestSuite'))
|
||||
self.checkModule('difflib', ignore=("Match",))
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_cases(self):
|
||||
# see test.pyclbr_input for the rationale behind the ignored symbols
|
||||
self.checkModule('test.pyclbr_input', ignore=['om', 'f'])
|
||||
@@ -217,8 +243,7 @@ class PyclbrTest(TestCase, ExtraAssertions):
|
||||
|
||||
compare(None, actual, None, expected)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_others(self):
|
||||
cm = self.checkModule
|
||||
|
||||
@@ -228,12 +253,14 @@ class PyclbrTest(TestCase, ExtraAssertions):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', DeprecationWarning)
|
||||
cm('sre_parse', ignore=('dump', 'groups', 'pos')) # from sre_constants import *; property
|
||||
cm(
|
||||
'pdb',
|
||||
# pyclbr does not handle elegantly `typing` or properties
|
||||
ignore=('Union', '_ModuleTarget', '_ScriptTarget', '_ZipTarget'),
|
||||
)
|
||||
cm('pydoc', ignore=('input', 'output',)) # properties
|
||||
with temporary_main_spec():
|
||||
cm(
|
||||
'pdb',
|
||||
# pyclbr does not handle elegantly `typing` or properties
|
||||
ignore=('Union', '_ModuleTarget', '_ScriptTarget', '_ZipTarget', 'curframe_locals',
|
||||
'_InteractState', 'rlcompleter'),
|
||||
)
|
||||
cm('pydoc', ignore=('input', 'output',)) # properties
|
||||
|
||||
# Tests for modules inside packages
|
||||
cm('email.parser')
|
||||
|
||||
12
Lib/test/test_xmlrpc.py
vendored
12
Lib/test/test_xmlrpc.py
vendored
@@ -187,7 +187,7 @@ class XMLRPCTestCase(unittest.TestCase):
|
||||
xmlrpclib.loads(strg)[0][0])
|
||||
self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_dump_encoding(self):
|
||||
value = {'key\u20ac\xa4':
|
||||
'value\u20ac\xa4'}
|
||||
@@ -228,7 +228,7 @@ class XMLRPCTestCase(unittest.TestCase):
|
||||
self.assertIs(type(newvalue), xmlrpclib.Binary)
|
||||
self.assertIsNone(m)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_loads_unsupported(self):
|
||||
ResponseError = xmlrpclib.ResponseError
|
||||
data = '<params><param><value><spam/></value></param></params>'
|
||||
@@ -278,7 +278,7 @@ class XMLRPCTestCase(unittest.TestCase):
|
||||
'<member><name>a</name><value><int>1</int></value></member>'
|
||||
'</struct>', {'a': 1, 'b': 2})
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_load_extension_types(self):
|
||||
check = self.check_loads
|
||||
check('<nil/>', None)
|
||||
@@ -311,7 +311,7 @@ class XMLRPCTestCase(unittest.TestCase):
|
||||
|
||||
def test_ssl_presence(self):
|
||||
try:
|
||||
import ssl
|
||||
import ssl # noqa: F401
|
||||
except ImportError:
|
||||
has_ssl = False
|
||||
else:
|
||||
@@ -832,7 +832,7 @@ class SimpleServerTestCase(BaseServerTestCase):
|
||||
# protocol error; provide additional information in test output
|
||||
self.fail("%s\n%s" % (e, getattr(e, "headers", "")))
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_client_encoding(self):
|
||||
start_string = '\u20ac'
|
||||
end_string = '\xa4'
|
||||
@@ -1013,7 +1013,7 @@ class SimpleServerEncodingTestCase(BaseServerTestCase):
|
||||
def threadFunc(evt, numrequests, requestHandler=None, encoding=None):
|
||||
http_server(evt, numrequests, requestHandler, 'iso-8859-15')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_server_encoding(self):
|
||||
start_string = '\u20ac'
|
||||
end_string = '\xa4'
|
||||
|
||||
3
Lib/xmlrpc/server.py
vendored
3
Lib/xmlrpc/server.py
vendored
@@ -239,7 +239,7 @@ class SimpleXMLRPCDispatcher:
|
||||
|
||||
see http://www.xmlrpc.com/discuss/msgReader$1208"""
|
||||
|
||||
self.funcs.update({'system.multicall' : self.system_multicall})
|
||||
self.funcs['system.multicall'] = self.system_multicall
|
||||
|
||||
def _marshaled_dispatch(self, data, dispatch_method = None, path = None):
|
||||
"""Dispatches an XML-RPC method from marshalled (XML) data.
|
||||
@@ -578,6 +578,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer,
|
||||
"""
|
||||
|
||||
allow_reuse_address = True
|
||||
allow_reuse_port = False
|
||||
|
||||
# Warning: this is for debugging purposes only! Never set this to True in
|
||||
# production code, as will be sending out sensitive information (exception
|
||||
|
||||
@@ -701,9 +701,8 @@ pub mod _hashlib {
|
||||
if len < 1 {
|
||||
return Err(vm.new_value_error("key length must be greater than 0.".to_owned()));
|
||||
}
|
||||
usize::try_from(len).map_err(|_| {
|
||||
vm.new_overflow_error("key length is too great.".to_owned())
|
||||
})?
|
||||
usize::try_from(len)
|
||||
.map_err(|_| vm.new_overflow_error("key length is too great.".to_owned()))?
|
||||
}
|
||||
None => hash_digest_size(&name).ok_or_else(|| unsupported_hash(&name, vm))?,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user