Skip to content

Commit b05d592

Browse files
committed
Update test_descr.py from CPython v3.12.0
1 parent 926c4ce commit b05d592

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

Lib/test/test_descr.py

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
except ImportError:
2222
_testcapi = None
2323

24+
try:
25+
import xxsubtype
26+
except ImportError:
27+
xxsubtype = None
28+
2429

2530
class OperatorsTest(unittest.TestCase):
2631

@@ -299,6 +304,7 @@ def test_explicit_reverse_methods(self):
299304
self.assertEqual(float.__rsub__(3.0, 1), -2.0)
300305

301306
@support.impl_detail("the module 'xxsubtype' is internal")
307+
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
302308
def test_spam_lists(self):
303309
# Testing spamlist operations...
304310
import copy, xxsubtype as spam
@@ -343,6 +349,7 @@ def foo(self): return 1
343349
self.assertEqual(a.getstate(), 42)
344350

345351
@support.impl_detail("the module 'xxsubtype' is internal")
352+
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
346353
def test_spam_dicts(self):
347354
# Testing spamdict operations...
348355
import copy, xxsubtype as spam
@@ -426,7 +433,7 @@ def __init__(self_local, *a, **kw):
426433
def __getitem__(self, key):
427434
return self.get(key, 0)
428435
def __setitem__(self_local, key, value):
429-
self.assertIsInstance(key, type(0))
436+
self.assertIsInstance(key, int)
430437
dict.__setitem__(self_local, key, value)
431438
def setstate(self, state):
432439
self.state = state
@@ -842,7 +849,7 @@ def __delattr__(self, name):
842849
("getattr", "foo"),
843850
("delattr", "foo")])
844851

845-
# http://python.org/sf/1174712
852+
# https://bugs.python.org/issue1174712
846853
try:
847854
class Module(types.ModuleType, str):
848855
pass
@@ -875,7 +882,7 @@ def setstate(self, state):
875882
self.assertEqual(a.getstate(), 10)
876883
class D(dict, C):
877884
def __init__(self):
878-
type({}).__init__(self)
885+
dict.__init__(self)
879886
C.__init__(self)
880887
d = D()
881888
self.assertEqual(list(d.keys()), [])
@@ -1627,6 +1634,7 @@ def test_refleaks_in_classmethod___init__(self):
16271634
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
16281635

16291636
@support.impl_detail("the module 'xxsubtype' is internal")
1637+
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
16301638
def test_classmethods_in_c(self):
16311639
# Testing C-based class methods...
16321640
import xxsubtype as spam
@@ -1712,6 +1720,7 @@ def test_refleaks_in_staticmethod___init__(self):
17121720
self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10)
17131721

17141722
@support.impl_detail("the module 'xxsubtype' is internal")
1723+
@unittest.skipIf(xxsubtype is None, "requires xxsubtype module")
17151724
def test_staticmethods_in_c(self):
17161725
# Testing C-based static methods...
17171726
import xxsubtype as spam
@@ -1848,9 +1857,7 @@ def __init__(self, foo):
18481857
object.__init__(A(3))
18491858
self.assertRaises(TypeError, object.__init__, A(3), 5)
18501859

1851-
# TODO: RUSTPYTHON, CPython 3.5 and above expect this test case to fail, but in RustPython this currently passes.
1852-
# See https://github.com/python/cpython/issues/49572 for more details.
1853-
# @unittest.expectedFailure
1860+
@unittest.expectedFailure
18541861
def test_restored_object_new(self):
18551862
class A(object):
18561863
def __new__(cls, *args, **kwargs):
@@ -2006,7 +2013,7 @@ def __getattr__(self, attr):
20062013
ns = {}
20072014
exec(code, ns)
20082015
number_attrs = ns["number_attrs"]
2009-
# Warm up the the function for quickening (PEP 659)
2016+
# Warm up the function for quickening (PEP 659)
20102017
for _ in range(30):
20112018
self.assertEqual(number_attrs(Numbers()), list(range(280)))
20122019

@@ -3298,12 +3305,8 @@ def __get__(self, object, otype):
32983305
if otype:
32993306
otype = otype.__name__
33003307
return 'object=%s; type=%s' % (object, otype)
3301-
class OldClass:
3302-
__doc__ = DocDescr()
3303-
class NewClass(object):
3308+
class NewClass:
33043309
__doc__ = DocDescr()
3305-
self.assertEqual(OldClass.__doc__, 'object=None; type=OldClass')
3306-
self.assertEqual(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
33073310
self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass')
33083311
self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
33093312

@@ -3345,7 +3348,7 @@ class Int(int): __slots__ = []
33453348
cant(True, int)
33463349
cant(2, bool)
33473350
o = object()
3348-
cant(o, type(1))
3351+
cant(o, int)
33493352
cant(o, type(None))
33503353
del o
33513354
class G(object):
@@ -3622,7 +3625,6 @@ class MyInt(int):
36223625
def test_str_of_str_subclass(self):
36233626
# Testing __str__ defined in subclass of str ...
36243627
import binascii
3625-
import io
36263628

36273629
class octetstring(str):
36283630
def __str__(self):
@@ -4528,7 +4530,7 @@ class Oops(object):
45284530
o.whatever = Provoker(o)
45294531
del o
45304532

4531-
@unittest.skip("TODO: RUSTPYTHON, rustpython segmentation fault")
4533+
@support.requires_resource('cpu')
45324534
def test_wrapper_segfault(self):
45334535
# SF 927248: deeply nested wrappers could cause stack overflow
45344536
f = lambda:None
@@ -5095,6 +5097,32 @@ class Child(Parent):
50955097
gc.collect()
50965098
self.assertEqual(Parent.__subclasses__(), [])
50975099

5100+
def test_attr_raise_through_property(self):
5101+
# test case for gh-103272
5102+
class A:
5103+
def __getattr__(self, name):
5104+
raise ValueError("FOO")
5105+
5106+
@property
5107+
def foo(self):
5108+
return self.__getattr__("asdf")
5109+
5110+
with self.assertRaisesRegex(ValueError, "FOO"):
5111+
A().foo
5112+
5113+
# test case for gh-103551
5114+
class B:
5115+
@property
5116+
def __getattr__(self, name):
5117+
raise ValueError("FOO")
5118+
5119+
@property
5120+
def foo(self):
5121+
raise NotImplementedError("BAR")
5122+
5123+
with self.assertRaisesRegex(NotImplementedError, "BAR"):
5124+
B().foo
5125+
50985126

50995127
class DictProxyTests(unittest.TestCase):
51005128
def setUp(self):

0 commit comments

Comments
 (0)