diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-08 15:34:35 +0000 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-08 15:34:35 +0000 |
commit | e99a73b9f8d8975129ddbc6142b4476c7cc4fe3b (patch) | |
tree | d42c7ee7520f7f50c90778740de6614a0fff507d /Lib/test/test_collections.py | |
parent | c1e2394e803d288f9ef374bbd4ea9de43eca6bda (diff) | |
download | cpython-e99a73b9f8d8975129ddbc6142b4476c7cc4fe3b.tar.gz |
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/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 467ddef708..067c537997 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: |