|
21 | 21 | except ImportError: |
22 | 22 | _testcapi = None |
23 | 23 |
|
| 24 | +try: |
| 25 | + import xxsubtype |
| 26 | +except ImportError: |
| 27 | + xxsubtype = None |
| 28 | + |
24 | 29 |
|
25 | 30 | class OperatorsTest(unittest.TestCase): |
26 | 31 |
|
@@ -299,6 +304,7 @@ def test_explicit_reverse_methods(self): |
299 | 304 | self.assertEqual(float.__rsub__(3.0, 1), -2.0) |
300 | 305 |
|
301 | 306 | @support.impl_detail("the module 'xxsubtype' is internal") |
| 307 | + @unittest.skipIf(xxsubtype is None, "requires xxsubtype module") |
302 | 308 | def test_spam_lists(self): |
303 | 309 | # Testing spamlist operations... |
304 | 310 | import copy, xxsubtype as spam |
@@ -343,6 +349,7 @@ def foo(self): return 1 |
343 | 349 | self.assertEqual(a.getstate(), 42) |
344 | 350 |
|
345 | 351 | @support.impl_detail("the module 'xxsubtype' is internal") |
| 352 | + @unittest.skipIf(xxsubtype is None, "requires xxsubtype module") |
346 | 353 | def test_spam_dicts(self): |
347 | 354 | # Testing spamdict operations... |
348 | 355 | import copy, xxsubtype as spam |
@@ -426,7 +433,7 @@ def __init__(self_local, *a, **kw): |
426 | 433 | def __getitem__(self, key): |
427 | 434 | return self.get(key, 0) |
428 | 435 | def __setitem__(self_local, key, value): |
429 | | - self.assertIsInstance(key, type(0)) |
| 436 | + self.assertIsInstance(key, int) |
430 | 437 | dict.__setitem__(self_local, key, value) |
431 | 438 | def setstate(self, state): |
432 | 439 | self.state = state |
@@ -842,7 +849,7 @@ def __delattr__(self, name): |
842 | 849 | ("getattr", "foo"), |
843 | 850 | ("delattr", "foo")]) |
844 | 851 |
|
845 | | - # http://python.org/sf/1174712 |
| 852 | + # https://bugs.python.org/issue1174712 |
846 | 853 | try: |
847 | 854 | class Module(types.ModuleType, str): |
848 | 855 | pass |
@@ -875,7 +882,7 @@ def setstate(self, state): |
875 | 882 | self.assertEqual(a.getstate(), 10) |
876 | 883 | class D(dict, C): |
877 | 884 | def __init__(self): |
878 | | - type({}).__init__(self) |
| 885 | + dict.__init__(self) |
879 | 886 | C.__init__(self) |
880 | 887 | d = D() |
881 | 888 | self.assertEqual(list(d.keys()), []) |
@@ -1627,6 +1634,7 @@ def test_refleaks_in_classmethod___init__(self): |
1627 | 1634 | self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10) |
1628 | 1635 |
|
1629 | 1636 | @support.impl_detail("the module 'xxsubtype' is internal") |
| 1637 | + @unittest.skipIf(xxsubtype is None, "requires xxsubtype module") |
1630 | 1638 | def test_classmethods_in_c(self): |
1631 | 1639 | # Testing C-based class methods... |
1632 | 1640 | import xxsubtype as spam |
@@ -1712,6 +1720,7 @@ def test_refleaks_in_staticmethod___init__(self): |
1712 | 1720 | self.assertAlmostEqual(gettotalrefcount() - refs_before, 0, delta=10) |
1713 | 1721 |
|
1714 | 1722 | @support.impl_detail("the module 'xxsubtype' is internal") |
| 1723 | + @unittest.skipIf(xxsubtype is None, "requires xxsubtype module") |
1715 | 1724 | def test_staticmethods_in_c(self): |
1716 | 1725 | # Testing C-based static methods... |
1717 | 1726 | import xxsubtype as spam |
@@ -1848,9 +1857,7 @@ def __init__(self, foo): |
1848 | 1857 | object.__init__(A(3)) |
1849 | 1858 | self.assertRaises(TypeError, object.__init__, A(3), 5) |
1850 | 1859 |
|
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 |
1854 | 1861 | def test_restored_object_new(self): |
1855 | 1862 | class A(object): |
1856 | 1863 | def __new__(cls, *args, **kwargs): |
@@ -2006,7 +2013,7 @@ def __getattr__(self, attr): |
2006 | 2013 | ns = {} |
2007 | 2014 | exec(code, ns) |
2008 | 2015 | number_attrs = ns["number_attrs"] |
2009 | | - # Warm up the the function for quickening (PEP 659) |
| 2016 | + # Warm up the function for quickening (PEP 659) |
2010 | 2017 | for _ in range(30): |
2011 | 2018 | self.assertEqual(number_attrs(Numbers()), list(range(280))) |
2012 | 2019 |
|
@@ -3298,12 +3305,8 @@ def __get__(self, object, otype): |
3298 | 3305 | if otype: |
3299 | 3306 | otype = otype.__name__ |
3300 | 3307 | return 'object=%s; type=%s' % (object, otype) |
3301 | | - class OldClass: |
3302 | | - __doc__ = DocDescr() |
3303 | | - class NewClass(object): |
| 3308 | + class NewClass: |
3304 | 3309 | __doc__ = DocDescr() |
3305 | | - self.assertEqual(OldClass.__doc__, 'object=None; type=OldClass') |
3306 | | - self.assertEqual(OldClass().__doc__, 'object=OldClass instance; type=OldClass') |
3307 | 3310 | self.assertEqual(NewClass.__doc__, 'object=None; type=NewClass') |
3308 | 3311 | self.assertEqual(NewClass().__doc__, 'object=NewClass instance; type=NewClass') |
3309 | 3312 |
|
@@ -3345,7 +3348,7 @@ class Int(int): __slots__ = [] |
3345 | 3348 | cant(True, int) |
3346 | 3349 | cant(2, bool) |
3347 | 3350 | o = object() |
3348 | | - cant(o, type(1)) |
| 3351 | + cant(o, int) |
3349 | 3352 | cant(o, type(None)) |
3350 | 3353 | del o |
3351 | 3354 | class G(object): |
@@ -3622,7 +3625,6 @@ class MyInt(int): |
3622 | 3625 | def test_str_of_str_subclass(self): |
3623 | 3626 | # Testing __str__ defined in subclass of str ... |
3624 | 3627 | import binascii |
3625 | | - import io |
3626 | 3628 |
|
3627 | 3629 | class octetstring(str): |
3628 | 3630 | def __str__(self): |
@@ -4528,7 +4530,7 @@ class Oops(object): |
4528 | 4530 | o.whatever = Provoker(o) |
4529 | 4531 | del o |
4530 | 4532 |
|
4531 | | - @unittest.skip("TODO: RUSTPYTHON, rustpython segmentation fault") |
| 4533 | + @support.requires_resource('cpu') |
4532 | 4534 | def test_wrapper_segfault(self): |
4533 | 4535 | # SF 927248: deeply nested wrappers could cause stack overflow |
4534 | 4536 | f = lambda:None |
@@ -5095,6 +5097,32 @@ class Child(Parent): |
5095 | 5097 | gc.collect() |
5096 | 5098 | self.assertEqual(Parent.__subclasses__(), []) |
5097 | 5099 |
|
| 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 | + |
5098 | 5126 |
|
5099 | 5127 | class DictProxyTests(unittest.TestCase): |
5100 | 5128 | def setUp(self): |
|
0 commit comments