mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #7068 from ShaharNaveh/update-support-init
Update `support.__init__.py` from 3.14.3
This commit is contained in:
88
Lib/test/support/__init__.py
vendored
88
Lib/test/support/__init__.py
vendored
@@ -3,11 +3,12 @@
|
||||
if __name__ != 'test.support':
|
||||
raise ImportError('support must be imported from the test package')
|
||||
|
||||
import _opcode
|
||||
import annotationlib
|
||||
import contextlib
|
||||
import functools
|
||||
import inspect
|
||||
import logging
|
||||
import _opcode
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
@@ -19,7 +20,6 @@ import types
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
import annotationlib
|
||||
|
||||
__all__ = [
|
||||
# globals
|
||||
@@ -30,7 +30,8 @@ __all__ = [
|
||||
"record_original_stdout", "get_original_stdout", "captured_stdout",
|
||||
"captured_stdin", "captured_stderr", "captured_output",
|
||||
# unittest
|
||||
"is_resource_enabled", "requires", "requires_freebsd_version",
|
||||
"is_resource_enabled", "get_resource_value", "requires", "requires_resource",
|
||||
"requires_freebsd_version",
|
||||
"requires_gil_enabled", "requires_linux_version", "requires_mac_ver",
|
||||
"check_syntax_error",
|
||||
"requires_gzip", "requires_bz2", "requires_lzma", "requires_zstd",
|
||||
@@ -43,6 +44,7 @@ __all__ = [
|
||||
"check__all__", "skip_if_buggy_ucrt_strfptime",
|
||||
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
|
||||
"requires_limited_api", "requires_specialization", "thread_unsafe",
|
||||
"skip_if_unlimited_stack_size",
|
||||
# sys
|
||||
"MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
|
||||
"is_apple_mobile", "check_impl_detail", "unix_shell", "setswitchinterval",
|
||||
@@ -184,7 +186,7 @@ def get_attribute(obj, name):
|
||||
return attribute
|
||||
|
||||
verbose = 1 # Flag set to 0 by regrtest.py
|
||||
use_resources = None # Flag set to [] by regrtest.py
|
||||
use_resources = None # Flag set to {} by regrtest.py
|
||||
max_memuse = 0 # Disable bigmem tests (they will still be run with
|
||||
# small sizes, to make sure they work.)
|
||||
real_max_memuse = 0
|
||||
@@ -299,6 +301,16 @@ def is_resource_enabled(resource):
|
||||
"""
|
||||
return use_resources is None or resource in use_resources
|
||||
|
||||
def get_resource_value(resource):
|
||||
"""Test whether a resource is enabled.
|
||||
|
||||
Known resources are set by regrtest.py. If not running under regrtest.py,
|
||||
all resources are assumed enabled unless use_resources has been set.
|
||||
"""
|
||||
if use_resources is None:
|
||||
return None
|
||||
return use_resources.get(resource)
|
||||
|
||||
def requires(resource, msg=None):
|
||||
"""Raise ResourceDenied if the specified resource is not available."""
|
||||
if not is_resource_enabled(resource):
|
||||
@@ -562,52 +574,6 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
|
||||
return unittest.skipIf(skip, reason)
|
||||
|
||||
|
||||
# XXX: RUSTPYTHON; this is not belong to 3.14
|
||||
def can_use_suppress_immortalization(suppress=True):
|
||||
"""Check if suppress_immortalization(suppress) can be used.
|
||||
|
||||
Use this helper in code where SkipTest must be eagerly handled.
|
||||
"""
|
||||
if not suppress:
|
||||
return True
|
||||
try:
|
||||
import _testinternalcapi
|
||||
except ImportError:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def suppress_immortalization(suppress=True):
|
||||
"""Suppress immortalization of deferred objects.
|
||||
|
||||
If _testinternalcapi is not available, the decorated test or class
|
||||
is skipped. Use can_use_suppress_immortalization() outside test cases
|
||||
to check if this decorator can be used.
|
||||
"""
|
||||
if not suppress:
|
||||
yield # no-op
|
||||
return
|
||||
|
||||
from .import_helper import import_module
|
||||
|
||||
_testinternalcapi = import_module("_testinternalcapi")
|
||||
_testinternalcapi.suppress_immortalization(True)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
_testinternalcapi.suppress_immortalization(False)
|
||||
|
||||
|
||||
def skip_if_suppress_immortalization():
|
||||
try:
|
||||
import _testinternalcapi
|
||||
except ImportError:
|
||||
return
|
||||
return unittest.skipUnless(_testinternalcapi.get_immortalize_deferred(),
|
||||
"requires immortalization of deferred objects")
|
||||
|
||||
|
||||
MS_WINDOWS = (sys.platform == 'win32')
|
||||
|
||||
# Is not actually used in tests, but is kept for compatibility.
|
||||
@@ -783,9 +749,7 @@ def check_syntax_error(testcase, statement, errtext='', *, lineno=None, offset=N
|
||||
|
||||
|
||||
def open_urlresource(url, *args, **kw):
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
import urllib.request, urllib.parse
|
||||
from .os_helper import unlink
|
||||
try:
|
||||
import gzip
|
||||
@@ -1410,7 +1374,6 @@ def refcount_test(test):
|
||||
def requires_limited_api(test):
|
||||
try:
|
||||
import _testcapi # noqa: F401
|
||||
|
||||
import _testlimitedcapi # noqa: F401
|
||||
except ImportError:
|
||||
return unittest.skip('needs _testcapi and _testlimitedcapi modules')(test)
|
||||
@@ -1666,8 +1629,8 @@ class PythonSymlink:
|
||||
|
||||
if sys.platform == "win32":
|
||||
def _platform_specific(self):
|
||||
import _winapi
|
||||
import glob
|
||||
import _winapi
|
||||
|
||||
if os.path.lexists(self.real) and not os.path.exists(self.real):
|
||||
# App symlink appears to not exist, but we want the
|
||||
@@ -1739,7 +1702,6 @@ def skip_if_pgo_task(test):
|
||||
return test if ok else unittest.skip(msg)(test)
|
||||
|
||||
|
||||
# XXX: RUSTPYTHON; Taken from 3.14.3
|
||||
def skip_if_unlimited_stack_size(test):
|
||||
"""Skip decorator for tests not run when an unlimited stack size is configured.
|
||||
|
||||
@@ -2083,10 +2045,9 @@ def missing_compiler_executable(cmd_names=[]):
|
||||
missing.
|
||||
|
||||
"""
|
||||
import shutil
|
||||
|
||||
from setuptools import errors
|
||||
from setuptools._distutils import ccompiler, sysconfig
|
||||
from setuptools import errors
|
||||
import shutil
|
||||
|
||||
compiler = ccompiler.new_compiler()
|
||||
sysconfig.customize_compiler(compiler)
|
||||
@@ -2576,7 +2537,6 @@ def _findwheel(pkgname):
|
||||
@contextlib.contextmanager
|
||||
def setup_venv_with_pip_setuptools(venv_dir):
|
||||
import subprocess
|
||||
|
||||
from .os_helper import temp_cwd
|
||||
|
||||
def run_command(cmd):
|
||||
@@ -2999,7 +2959,6 @@ def iter_slot_wrappers(cls):
|
||||
@contextlib.contextmanager
|
||||
def force_color(color: bool):
|
||||
import _colorize
|
||||
|
||||
from .os_helper import EnvironmentVarGuard
|
||||
|
||||
with (
|
||||
@@ -3278,3 +3237,10 @@ def linked_to_musl():
|
||||
return _linked_to_musl
|
||||
_linked_to_musl = tuple(map(int, version.split('.')))
|
||||
return _linked_to_musl
|
||||
|
||||
|
||||
def control_characters_c0() -> list[str]:
|
||||
"""Returns a list of C0 control characters as strings.
|
||||
C0 control characters defined as the byte range 0x00-0x1F, and 0x7F.
|
||||
"""
|
||||
return [chr(c) for c in range(0x00, 0x20)] + ["\x7F"]
|
||||
|
||||
228
Lib/test/test_descr.py
vendored
228
Lib/test/test_descr.py
vendored
@@ -7,6 +7,7 @@ import pickle
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
import textwrap
|
||||
import types
|
||||
import unittest
|
||||
import warnings
|
||||
@@ -15,7 +16,7 @@ import weakref
|
||||
from copy import deepcopy
|
||||
from contextlib import redirect_stdout
|
||||
from test import support
|
||||
from test.support.testcase import ExtraAssertions
|
||||
from test.support.script_helper import assert_python_ok
|
||||
|
||||
try:
|
||||
import _testcapi
|
||||
@@ -404,11 +405,11 @@ class OperatorsTest(unittest.TestCase):
|
||||
self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize)
|
||||
|
||||
|
||||
class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
class ClassPropertiesAndMethods(unittest.TestCase):
|
||||
|
||||
def test_python_dicts(self):
|
||||
# Testing Python subclass of dict...
|
||||
self.assertTrue(issubclass(dict, dict))
|
||||
self.assertIsSubclass(dict, dict)
|
||||
self.assertIsInstance({}, dict)
|
||||
d = dict()
|
||||
self.assertEqual(d, {})
|
||||
@@ -432,7 +433,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.state = state
|
||||
def getstate(self):
|
||||
return self.state
|
||||
self.assertTrue(issubclass(C, dict))
|
||||
self.assertIsSubclass(C, dict)
|
||||
a1 = C(12)
|
||||
self.assertEqual(a1.state, 12)
|
||||
a2 = C(foo=1, bar=2)
|
||||
@@ -1047,15 +1048,15 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
|
||||
m = types.ModuleType("m")
|
||||
self.assertTrue(m.__class__ is types.ModuleType)
|
||||
self.assertFalse(hasattr(m, "a"))
|
||||
self.assertNotHasAttr(m, "a")
|
||||
|
||||
m.__class__ = SubType
|
||||
self.assertTrue(m.__class__ is SubType)
|
||||
self.assertTrue(hasattr(m, "a"))
|
||||
self.assertHasAttr(m, "a")
|
||||
|
||||
m.__class__ = types.ModuleType
|
||||
self.assertTrue(m.__class__ is types.ModuleType)
|
||||
self.assertFalse(hasattr(m, "a"))
|
||||
self.assertNotHasAttr(m, "a")
|
||||
|
||||
# Make sure that builtin immutable objects don't support __class__
|
||||
# assignment, because the object instances may be interned.
|
||||
@@ -1102,7 +1103,8 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(TypeError):
|
||||
frozenset().__class__ = MyFrozenSet
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@support.thread_unsafe
|
||||
def test_slots(self):
|
||||
# Testing __slots__...
|
||||
class C0(object):
|
||||
@@ -1319,7 +1321,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaisesRegex(AttributeError, "'X' object has no attribute 'a'"):
|
||||
X().a
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_slots_special(self):
|
||||
# Testing __dict__ and __weakref__ in __slots__...
|
||||
class D(object):
|
||||
@@ -1358,7 +1360,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
a.foo = 42
|
||||
self.assertEqual(a.__dict__, {"foo": 42})
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_slots_special2(self):
|
||||
# Testing __qualname__ and __classcell__ in __slots__
|
||||
class Meta(type):
|
||||
@@ -1543,6 +1545,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
else:
|
||||
self.fail("finding the most derived metaclass should have failed")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_classmethods(self):
|
||||
# Testing class methods...
|
||||
class C(object):
|
||||
@@ -1588,8 +1591,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.fail("classmethod shouldn't accept keyword args")
|
||||
|
||||
cm = classmethod(f)
|
||||
cm_dict = {'__annotations__': {},
|
||||
'__doc__': (
|
||||
cm_dict = {'__doc__': (
|
||||
"f docstring"
|
||||
if support.HAVE_PY_DOCSTRINGS
|
||||
else None
|
||||
@@ -1605,6 +1607,56 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
del cm.x
|
||||
self.assertNotHasAttr(cm, "x")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_classmethod_staticmethod_annotations(self):
|
||||
for deco in (classmethod, staticmethod):
|
||||
@deco
|
||||
def unannotated(cls): pass
|
||||
@deco
|
||||
def annotated(cls) -> int: pass
|
||||
|
||||
for method in (annotated, unannotated):
|
||||
with self.subTest(deco=deco, method=method):
|
||||
with self.assertRaises(AttributeError):
|
||||
del unannotated.__annotations__
|
||||
|
||||
original_annotations = dict(method.__wrapped__.__annotations__)
|
||||
self.assertNotIn('__annotations__', method.__dict__)
|
||||
self.assertEqual(method.__annotations__, original_annotations)
|
||||
self.assertIn('__annotations__', method.__dict__)
|
||||
|
||||
new_annotations = {"a": "b"}
|
||||
method.__annotations__ = new_annotations
|
||||
self.assertEqual(method.__annotations__, new_annotations)
|
||||
self.assertEqual(method.__wrapped__.__annotations__, original_annotations)
|
||||
|
||||
del method.__annotations__
|
||||
self.assertEqual(method.__annotations__, original_annotations)
|
||||
|
||||
original_annotate = method.__wrapped__.__annotate__
|
||||
self.assertNotIn('__annotate__', method.__dict__)
|
||||
self.assertIs(method.__annotate__, original_annotate)
|
||||
self.assertIn('__annotate__', method.__dict__)
|
||||
|
||||
new_annotate = lambda: {"annotations": 1}
|
||||
method.__annotate__ = new_annotate
|
||||
self.assertIs(method.__annotate__, new_annotate)
|
||||
self.assertIs(method.__wrapped__.__annotate__, original_annotate)
|
||||
|
||||
del method.__annotate__
|
||||
self.assertIs(method.__annotate__, original_annotate)
|
||||
|
||||
def test_staticmethod_annotations_without_dict_access(self):
|
||||
# gh-125017: this used to crash
|
||||
class Spam:
|
||||
def __new__(cls, x, y):
|
||||
pass
|
||||
|
||||
self.assertEqual(Spam.__new__.__annotations__, {})
|
||||
obj = Spam.__dict__['__new__']
|
||||
self.assertIsInstance(obj, staticmethod)
|
||||
self.assertEqual(obj.__annotations__, {})
|
||||
|
||||
@support.refcount_test
|
||||
def test_refleaks_in_classmethod___init__(self):
|
||||
gettotalrefcount = support.get_attribute(sys, 'gettotalrefcount')
|
||||
@@ -1733,7 +1785,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
class E: # *not* subclassing from C
|
||||
foo = C.foo
|
||||
self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound
|
||||
self.assertTrue(repr(C.foo.__get__(C())).startswith("<bound method "))
|
||||
self.assertStartsWith(repr(C.foo.__get__(C())), "<bound method ")
|
||||
|
||||
def test_compattr(self):
|
||||
# Testing computed attributes...
|
||||
@@ -1787,6 +1839,8 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(b.foo, 3)
|
||||
self.assertEqual(b.__class__, D)
|
||||
|
||||
# TODO: RUSTPYTHON; The `expectedFailure` here is from CPython, so this test must fail
|
||||
# @unittest.expectedFailure
|
||||
def test_bad_new(self):
|
||||
self.assertRaises(TypeError, object.__new__)
|
||||
self.assertRaises(TypeError, object.__new__, '')
|
||||
@@ -1799,7 +1853,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
__new__ = object.__new__
|
||||
self.assertRaises(TypeError, C)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_object_new(self):
|
||||
class A(object):
|
||||
pass
|
||||
@@ -1859,7 +1913,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(b.foo, 3)
|
||||
self.assertEqual(b.__class__, B)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_altmro(self):
|
||||
# Testing mro() and overriding it...
|
||||
class A(object):
|
||||
@@ -2013,7 +2067,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
class E(object):
|
||||
foo = C.foo
|
||||
self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound
|
||||
self.assertTrue(repr(C.foo.__get__(C(1))).startswith("<bound method "))
|
||||
self.assertStartsWith(repr(C.foo.__get__(C(1))), "<bound method ")
|
||||
|
||||
@support.impl_detail("testing error message from implementation")
|
||||
def test_methods_in_c(self):
|
||||
@@ -2038,7 +2092,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
set_add.__get__(0)
|
||||
self.assertEqual(cm.exception.args[0], expected_errmsg)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_special_method_lookup(self):
|
||||
# The lookup of special methods bypasses __getattr__ and
|
||||
# __getattribute__, but they still can be descriptors.
|
||||
@@ -2241,7 +2295,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertIn(i, p10)
|
||||
self.assertNotIn(10, p10)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_weakrefs(self):
|
||||
# Testing weak references...
|
||||
import weakref
|
||||
@@ -2273,7 +2327,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(r(), None)
|
||||
del r
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_properties(self):
|
||||
# Testing property...
|
||||
class C(object):
|
||||
@@ -2601,7 +2655,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
|
||||
dir(C()) # This used to segfault
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_supers(self):
|
||||
# Testing super...
|
||||
|
||||
@@ -2714,7 +2768,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(TypeError):
|
||||
super(Base, kw=1)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_basic_inheritance(self):
|
||||
# Testing inheritance from basic types...
|
||||
|
||||
@@ -3047,7 +3101,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
## pass
|
||||
## os_helper.unlink(os_helper.TESTFN)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_keywords(self):
|
||||
# Testing keyword args to basic type constructors ...
|
||||
with self.assertRaisesRegex(TypeError, 'keyword argument'):
|
||||
@@ -3194,8 +3248,6 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
class C(base):
|
||||
def __init__(self, value):
|
||||
self.value = int(value)
|
||||
def __cmp__(self_, other):
|
||||
self.fail("shouldn't call __cmp__")
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, C):
|
||||
return self.value == other.value
|
||||
@@ -3250,7 +3302,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
eval("x %s y" % op),
|
||||
"x=%d, y=%d" % (x, y))
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_descrdoc(self):
|
||||
# Testing descriptor doc strings...
|
||||
from _io import FileIO
|
||||
@@ -3274,7 +3326,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass')
|
||||
self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_set_class(self):
|
||||
# Testing __class__ assignment...
|
||||
class C(object): pass
|
||||
@@ -3364,7 +3416,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
l = [A() for x in range(100)]
|
||||
del l
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_set_dict(self):
|
||||
# Testing __dict__ assignment...
|
||||
class C(object): pass
|
||||
@@ -3480,6 +3532,10 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(repr(2 ** I(3)), "I(8)")
|
||||
self.assertEqual(repr(I(2) ** 3), "I(8)")
|
||||
self.assertEqual(repr(pow(I(2), I(3), I(5))), "I(3)")
|
||||
self.assertEqual(repr(pow(I(2), I(3), 5)), "I(3)")
|
||||
self.assertEqual(repr(pow(I(2), 3, 5)), "I(3)")
|
||||
self.assertEqual(repr(pow(2, I(3), 5)), "I(3)")
|
||||
self.assertEqual(repr(pow(2, 3, I(5))), "3")
|
||||
class S(str):
|
||||
def __eq__(self, other):
|
||||
return self.lower() == other.lower()
|
||||
@@ -3623,7 +3679,9 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
encoding='latin1', errors='replace')
|
||||
self.assertEqual(ba, b'abc\xbd?')
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON; rustpython segmentation fault')
|
||||
@unittest.skip("TODO: RUSTPYTHON; rustpython segmentation fault")
|
||||
@support.skip_wasi_stack_overflow()
|
||||
@support.skip_emscripten_stack_overflow()
|
||||
def test_recursive_call(self):
|
||||
# Testing recursive __call__() by setting to instance of class...
|
||||
class A(object):
|
||||
@@ -3742,7 +3800,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
m.foo = 1
|
||||
self.assertEqual(m.__dict__, {"foo": 1})
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_funny_new(self):
|
||||
# Testing __new__ returning something unexpected...
|
||||
class C(object):
|
||||
@@ -3904,7 +3962,9 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
# it as a leak.
|
||||
del C.__del__
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON; rustpython segmentation fault')
|
||||
@unittest.skip("TODO: RUSTPYTHON; rustpython segmentation fault")
|
||||
@support.skip_emscripten_stack_overflow()
|
||||
@support.skip_wasi_stack_overflow()
|
||||
def test_slots_trash(self):
|
||||
# Testing slot trash...
|
||||
# Deallocating deeply nested slotted trash caused stack overflows
|
||||
@@ -3917,7 +3977,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
o = trash(o)
|
||||
del o
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_slots_multiple_inheritance(self):
|
||||
# SF bug 575229, multiple inheritance w/ slots dumps core
|
||||
class A(object):
|
||||
@@ -3997,6 +4057,21 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
y = x ** 2
|
||||
self.assertIn('unsupported operand type(s) for **', str(cm.exception))
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_pow_wrapper_error_messages(self):
|
||||
self.assertRaisesRegex(TypeError,
|
||||
'expected 1 or 2 arguments, got 0',
|
||||
int().__pow__)
|
||||
self.assertRaisesRegex(TypeError,
|
||||
'expected 1 or 2 arguments, got 3',
|
||||
int().__pow__, 1, 2, 3)
|
||||
self.assertRaisesRegex(TypeError,
|
||||
'expected 1 or 2 arguments, got 0',
|
||||
int().__rpow__)
|
||||
self.assertRaisesRegex(TypeError,
|
||||
'expected 1 or 2 arguments, got 3',
|
||||
int().__rpow__, 1, 2, 3)
|
||||
|
||||
def test_mutable_bases(self):
|
||||
# Testing mutable bases...
|
||||
|
||||
@@ -4062,7 +4137,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
else:
|
||||
self.fail("shouldn't be able to create inheritance cycles")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_builtin_bases(self):
|
||||
# Make sure all the builtin types can have their base queried without
|
||||
# segfaulting. See issue #5787.
|
||||
@@ -4107,7 +4182,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
else:
|
||||
self.fail("best_base calculation found wanting")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_unsubclassable_types(self):
|
||||
with self.assertRaises(TypeError):
|
||||
class X(type(None)):
|
||||
@@ -4140,7 +4215,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(TypeError):
|
||||
X.__bases__ = type(None), O
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_mutable_bases_with_failing_mro(self):
|
||||
# Testing mutable bases with failing mro...
|
||||
class WorkOnce(type):
|
||||
@@ -4247,7 +4322,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
C.__name__ = Nasty("abc")
|
||||
C.__name__ = "normal"
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_subclass_right_op(self):
|
||||
# Testing correct dispatch of subclass overloading __r<op>__...
|
||||
|
||||
@@ -4382,7 +4457,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertIsInstance(a, C) # Baseline
|
||||
self.assertIsInstance(pa, C) # Test
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_proxy_super(self):
|
||||
# Testing super() for a proxy object...
|
||||
class Proxy(object):
|
||||
@@ -4406,7 +4481,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
p = Proxy(obj)
|
||||
self.assertEqual(C.__dict__["f"](p), "B.f->C.f")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_carloverre(self):
|
||||
# Testing prohibition of Carlo Verre's hack...
|
||||
try:
|
||||
@@ -4439,7 +4514,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
except TypeError:
|
||||
self.fail("setattr through direct base types should be legal")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_carloverre_multi_inherit_invalid(self):
|
||||
class A(type):
|
||||
def __setattr__(cls, key, value):
|
||||
@@ -4478,7 +4553,9 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
o.whatever = Provoker(o)
|
||||
del o
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON; rustpython segmentation fault')
|
||||
@unittest.skip("TODO: RUSTPYTHON; rustpython segmentation fault")
|
||||
@support.skip_wasi_stack_overflow()
|
||||
@support.skip_emscripten_stack_overflow()
|
||||
@support.requires_resource('cpu')
|
||||
def test_wrapper_segfault(self):
|
||||
# SF 927248: deeply nested wrappers could cause stack overflow
|
||||
@@ -4553,7 +4630,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(TypeError):
|
||||
a >= b
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_method_wrapper(self):
|
||||
# Testing method-wrapper objects...
|
||||
# <type 'method-wrapper'> did not support any reflection before 2.5
|
||||
@@ -4766,7 +4843,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(AttributeError):
|
||||
del X.__abstractmethods__
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON; crash. "dict has non-string keys: [PyObject PyInt { value: 1 }]"')
|
||||
@unittest.skip("TODO: RUSTPYTHON; crash. \"dict has non-string keys: [PyObject PyInt { value: 1 }]\"")
|
||||
def test_gh55664(self):
|
||||
# gh-55664: issue a warning when the
|
||||
# __dict__ of a class contains non-string keys
|
||||
@@ -4824,6 +4901,8 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
# CALL_METHOD_DESCRIPTOR_O
|
||||
deque.append(thing, thing)
|
||||
|
||||
@support.skip_emscripten_stack_overflow()
|
||||
@support.skip_wasi_stack_overflow()
|
||||
def test_repr_as_str(self):
|
||||
# Issue #11603: crash or infinite loop when rebinding __str__ as
|
||||
# __repr__.
|
||||
@@ -4855,7 +4934,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
with self.assertRaises(TypeError):
|
||||
a + a
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_slot_shadows_class_variable(self):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
class X:
|
||||
@@ -4864,7 +4943,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
m = str(cm.exception)
|
||||
self.assertEqual("'foo' in __slots__ conflicts with class variable", m)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_set_doc(self):
|
||||
class X:
|
||||
"elephant"
|
||||
@@ -4880,7 +4959,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertIn("cannot delete '__doc__' attribute of immutable type 'X'", str(cm.exception))
|
||||
self.assertEqual(X.__doc__, "banana")
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_qualname(self):
|
||||
descriptors = [str.lower, complex.real, float.real, int.__add__]
|
||||
types = ['method', 'member', 'getset', 'wrapper']
|
||||
@@ -4913,7 +4992,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
self.assertEqual(Y.__qualname__, 'Y')
|
||||
self.assertEqual(Y.Inside.__qualname__, 'Y.Inside')
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_qualname_dict(self):
|
||||
ns = {'__qualname__': 'some.name'}
|
||||
tp = type('Foo', (), ns)
|
||||
@@ -4924,7 +5003,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
ns = {'__qualname__': 1}
|
||||
self.assertRaises(TypeError, type, 'Foo', (), ns)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_cycle_through_dict(self):
|
||||
# See bug #1469629
|
||||
class X(dict):
|
||||
@@ -5039,7 +5118,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
cls.lst = [2**i for i in range(10000)]
|
||||
X.descr
|
||||
|
||||
@support.suppress_immortalization()
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_remove_subclass(self):
|
||||
# bpo-46417: when the last subclass of a type is deleted,
|
||||
# remove_subclass() clears the internal dictionary of subclasses:
|
||||
@@ -5057,7 +5136,7 @@ class ClassPropertiesAndMethods(unittest.TestCase, ExtraAssertions):
|
||||
gc.collect()
|
||||
self.assertEqual(Parent.__subclasses__(), [])
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_instance_method_get_behavior(self):
|
||||
# test case for gh-113157
|
||||
|
||||
@@ -5107,7 +5186,7 @@ class DictProxyTests(unittest.TestCase):
|
||||
pass
|
||||
self.C = C
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __local__')
|
||||
def test_iter_keys(self):
|
||||
@@ -5121,7 +5200,7 @@ class DictProxyTests(unittest.TestCase):
|
||||
'__static_attributes__', '__weakref__',
|
||||
'meth'])
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 5 != 7
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 5 != 7
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __local__')
|
||||
def test_iter_values(self):
|
||||
@@ -5131,7 +5210,7 @@ class DictProxyTests(unittest.TestCase):
|
||||
values = list(it)
|
||||
self.assertEqual(len(values), 7)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
|
||||
'trace function introduces __local__')
|
||||
def test_iter_items(self):
|
||||
@@ -5161,8 +5240,8 @@ class DictProxyTests(unittest.TestCase):
|
||||
# We can't blindly compare with the repr of another dict as ordering
|
||||
# of keys and values is arbitrary and may differ.
|
||||
r = repr(self.C.__dict__)
|
||||
self.assertTrue(r.startswith('mappingproxy('), r)
|
||||
self.assertTrue(r.endswith(')'), r)
|
||||
self.assertStartsWith(r, 'mappingproxy(')
|
||||
self.assertEndsWith(r, ')')
|
||||
for k, v in self.C.__dict__.items():
|
||||
self.assertIn('{!r}: {!r}'.format(k, v), r)
|
||||
|
||||
@@ -5198,6 +5277,7 @@ class MiscTests(unittest.TestCase):
|
||||
# Issue #14199: _PyType_Lookup() has to keep a strong reference to
|
||||
# the type MRO because it may be modified during the lookup, if
|
||||
# __bases__ is set during the lookup for example.
|
||||
code = textwrap.dedent("""
|
||||
class MyKey(object):
|
||||
def __hash__(self):
|
||||
return hash('mykey')
|
||||
@@ -5213,17 +5293,29 @@ class MiscTests(unittest.TestCase):
|
||||
mykey = 'from Base2'
|
||||
mykey2 = 'from Base2'
|
||||
|
||||
with self.assertWarnsRegex(RuntimeWarning, 'X'):
|
||||
X = type('X', (Base,), {MyKey(): 5})
|
||||
X = type('X', (Base,), {MyKey(): 5})
|
||||
|
||||
# Note that the access below uses getattr() rather than normally
|
||||
# accessing the attribute. That is done to avoid the bytecode
|
||||
# specializer activating on repeated runs of the test.
|
||||
bases_before = ",".join([c.__name__ for c in X.__bases__])
|
||||
print(f"before={bases_before}")
|
||||
|
||||
# mykey is read from Base
|
||||
self.assertEqual(getattr(X, 'mykey'), 'from Base')
|
||||
# mykey2 is read from Base2 because MyKey.__eq__ has set __bases__
|
||||
self.assertEqual(getattr(X, 'mykey2'), 'from Base2')
|
||||
# mykey is initially read from Base, however, the lookup will be perfomed
|
||||
# again if specialization fails. The second lookup will use the new
|
||||
# mro set by __eq__.
|
||||
print(X.mykey)
|
||||
|
||||
bases_after = ",".join([c.__name__ for c in X.__bases__])
|
||||
print(f"after={bases_after}")
|
||||
|
||||
# mykey2 is read from Base2 because MyKey.__eq__ has set __bases_
|
||||
print(f"mykey2={X.mykey2}")
|
||||
""")
|
||||
_, out, err = assert_python_ok("-c", code)
|
||||
err = err.decode()
|
||||
self.assertRegex(err, "RuntimeWarning: .*X")
|
||||
out = out.decode()
|
||||
self.assertRegex(out, "before=Base")
|
||||
self.assertRegex(out, "after=Base2")
|
||||
self.assertRegex(out, "mykey2=from Base2")
|
||||
|
||||
|
||||
class PicklingTests(unittest.TestCase):
|
||||
@@ -5446,6 +5538,7 @@ class PicklingTests(unittest.TestCase):
|
||||
{pickle.dumps, pickle._dumps},
|
||||
{pickle.loads, pickle._loads}))
|
||||
|
||||
@support.thread_unsafe
|
||||
def test_pickle_slots(self):
|
||||
# Tests pickling of classes with __slots__.
|
||||
|
||||
@@ -5513,6 +5606,7 @@ class PicklingTests(unittest.TestCase):
|
||||
y = pickle_copier.copy(x)
|
||||
self._assert_is_copy(x, y)
|
||||
|
||||
@support.thread_unsafe
|
||||
def test_reduce_copying(self):
|
||||
# Tests pickling and copying new-style classes and objects.
|
||||
global C1
|
||||
@@ -5637,7 +5731,7 @@ class PicklingTests(unittest.TestCase):
|
||||
objcopy2 = deepcopy(objcopy)
|
||||
self._assert_is_copy(obj, objcopy2)
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON')
|
||||
@unittest.skip("TODO: RUSTPYTHON")
|
||||
def test_issue24097(self):
|
||||
# Slot name is freed inside __getattr__ and is later used.
|
||||
class S(str): # Not interned
|
||||
@@ -5778,7 +5872,7 @@ class MroTest(unittest.TestCase):
|
||||
class C(B):
|
||||
pass
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_reent_set_bases_tp_base_cycle(self):
|
||||
"""
|
||||
type_set_bases must check for an inheritance cycle not only through
|
||||
@@ -5815,7 +5909,7 @@ class MroTest(unittest.TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
B1.__bases__ += ()
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_tp_subclasses_cycle_in_update_slots(self):
|
||||
"""
|
||||
type_set_bases must check for reentrancy upon finishing its job
|
||||
@@ -5852,7 +5946,7 @@ class MroTest(unittest.TestCase):
|
||||
self.assertEqual(B1.__bases__, (C,))
|
||||
self.assertEqual(C.__subclasses__(), [B1])
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_tp_subclasses_cycle_error_return_path(self):
|
||||
"""
|
||||
The same as test_tp_subclasses_cycle_in_update_slots, but tests
|
||||
@@ -5921,7 +6015,7 @@ class MroTest(unittest.TestCase):
|
||||
class A(metaclass=M):
|
||||
pass
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_disappearing_custom_mro(self):
|
||||
"""
|
||||
gh-92112: A custom mro() returning a result conflicting with
|
||||
|
||||
19
Lib/test/test_support.py
vendored
19
Lib/test/test_support.py
vendored
@@ -17,13 +17,11 @@ import unittest
|
||||
import warnings
|
||||
|
||||
from test import support
|
||||
from test.support import (
|
||||
import_helper,
|
||||
os_helper,
|
||||
script_helper,
|
||||
socket_helper,
|
||||
warnings_helper,
|
||||
)
|
||||
from test.support import import_helper
|
||||
from test.support import os_helper
|
||||
from test.support import script_helper
|
||||
from test.support import socket_helper
|
||||
from test.support import warnings_helper
|
||||
|
||||
TESTFN = os_helper.TESTFN
|
||||
|
||||
@@ -460,7 +458,7 @@ class TestSupport(unittest.TestCase):
|
||||
self.OtherClass, self.RefClass, ignore=ignore)
|
||||
self.assertEqual(set(), missing_items)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON
|
||||
def test_check__all__(self):
|
||||
extra = {'tempdir'}
|
||||
not_exported = {'template'}
|
||||
@@ -623,7 +621,7 @@ class TestSupport(unittest.TestCase):
|
||||
else:
|
||||
self.assertTrue(support.has_strftime_extensions)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; - _testinternalcapi module not available
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON; - _testinternalcapi module not available
|
||||
def test_get_recursion_depth(self):
|
||||
# test support.get_recursion_depth()
|
||||
code = textwrap.dedent("""
|
||||
@@ -667,7 +665,8 @@ class TestSupport(unittest.TestCase):
|
||||
""")
|
||||
script_helper.assert_python_ok("-c", code)
|
||||
|
||||
@unittest.skip('TODO: RUSTPYTHON; - causes segfault in debug builds')
|
||||
@unittest.skip("TODO: RUSTPYTHON; - causes segfault in debug builds")
|
||||
@support.skip_if_unlimited_stack_size
|
||||
def test_recursion(self):
|
||||
# Test infinite_recursion() and get_recursion_available() functions.
|
||||
def recursive_function(depth):
|
||||
|
||||
Reference in New Issue
Block a user