summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-03-08 15:34:35 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-03-08 15:34:35 (GMT)
commitce153f6f4d7bcfed0e3c82fc117c716eef9e5ddf (patch)
treec069150dccb8b246ff07852615f507342e7e04f0 /Lib
parentad8c5ca4e7e274163447a33615e02edf1d64d87a (diff)
downloadcpython-ce153f6f4d7bcfed0e3c82fc117c716eef9e5ddf.zip
cpython-ce153f6f4d7bcfed0e3c82fc117c716eef9e5ddf.tar.gz
cpython-ce153f6f4d7bcfed0e3c82fc117c716eef9e5ddf.tar.bz2
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. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_collections.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 467ddef..067c537 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -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: