mirror of https://github.com/python/cpython
Backport the tests only.
Merged revisions 78800 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78800 | florent.xicluna | 2010-03-08 16:20:28 +0100 (lun, 08 mar 2010) | 2 lines #7624: Fix isinstance(foo(), collections.Callable) for old-style classes. ........
This commit is contained in:
parent
ad8c5ca4e7
commit
ce153f6f4d
|
@ -235,6 +235,17 @@ class ABCTestCase(unittest.TestCase):
|
|||
C = type('C', (abc,), stubs)
|
||||
self.assertRaises(TypeError, C, name)
|
||||
|
||||
def validate_isinstance(self, abc, name):
|
||||
stub = lambda s, *args: 0
|
||||
|
||||
C = type('C', (object,), {'__hash__': None})
|
||||
setattr(C, name, stub)
|
||||
self.assertIsInstance(C(), abc)
|
||||
self.assertTrue(issubclass(C, abc))
|
||||
|
||||
C = type('C', (object,), {'__hash__': None})
|
||||
self.assertNotIsInstance(C(), abc)
|
||||
self.assertFalse(issubclass(C, abc))
|
||||
|
||||
class TestOneTrickPonyABCs(ABCTestCase):
|
||||
|
||||
|
@ -262,6 +273,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertEqual(hash(H()), 0)
|
||||
self.assertFalse(issubclass(int, H))
|
||||
self.validate_abstract_methods(Hashable, '__hash__')
|
||||
self.validate_isinstance(Hashable, '__hash__')
|
||||
|
||||
def test_Iterable(self):
|
||||
# Check some non-iterables
|
||||
|
@ -286,6 +298,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertEqual(list(I()), [])
|
||||
self.assertFalse(issubclass(str, I))
|
||||
self.validate_abstract_methods(Iterable, '__iter__')
|
||||
self.validate_isinstance(Iterable, '__iter__')
|
||||
|
||||
def test_Iterator(self):
|
||||
non_samples = [None, 42, 3.14, 1j, b"", "", (), [], {}, set()]
|
||||
|
@ -304,6 +317,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertIsInstance(x, Iterator)
|
||||
self.assertTrue(issubclass(type(x), Iterator), repr(type(x)))
|
||||
self.validate_abstract_methods(Iterator, '__next__')
|
||||
self.validate_isinstance(Iterator, '__next__')
|
||||
|
||||
def test_Sized(self):
|
||||
non_samples = [None, 42, 3.14, 1j,
|
||||
|
@ -321,6 +335,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertIsInstance(x, Sized)
|
||||
self.assertTrue(issubclass(type(x), Sized), repr(type(x)))
|
||||
self.validate_abstract_methods(Sized, '__len__')
|
||||
self.validate_isinstance(Sized, '__len__')
|
||||
|
||||
def test_Container(self):
|
||||
non_samples = [None, 42, 3.14, 1j,
|
||||
|
@ -338,6 +353,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertIsInstance(x, Container)
|
||||
self.assertTrue(issubclass(type(x), Container), repr(type(x)))
|
||||
self.validate_abstract_methods(Container, '__contains__')
|
||||
self.validate_isinstance(Container, '__contains__')
|
||||
|
||||
def test_Callable(self):
|
||||
non_samples = [None, 42, 3.14, 1j,
|
||||
|
@ -357,6 +373,7 @@ class TestOneTrickPonyABCs(ABCTestCase):
|
|||
self.assertIsInstance(x, Callable)
|
||||
self.assertTrue(issubclass(type(x), Callable), repr(type(x)))
|
||||
self.validate_abstract_methods(Callable, '__call__')
|
||||
self.validate_isinstance(Callable, '__call__')
|
||||
|
||||
def test_direct_subclassing(self):
|
||||
for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
|
||||
|
|
Loading…
Reference in New Issue