diff options
| author | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-30 01:36:00 (GMT) |
|---|---|---|
| committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-30 01:36:00 (GMT) |
| commit | d465640eb25c0552613b3a0cb172c9cbbb141b7f (patch) | |
| tree | d8c74ad8ab41d5a747034b6644269924fd1f5271 /Lib/test/test_hash.py | |
| parent | 0edab54cdf3db733c0c352ec0e21f1dbb53b506b (diff) | |
| download | cpython-d465640eb25c0552613b3a0cb172c9cbbb141b7f.zip cpython-d465640eb25c0552613b3a0cb172c9cbbb141b7f.tar.gz cpython-d465640eb25c0552613b3a0cb172c9cbbb141b7f.tar.bz2 | |
Merged revisions 68051 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68051 | nick.coghlan | 2008-12-30 11:18:48 +1000 (Tue, 30 Dec 2008) | 1 line
Issue #4701: implicitly call PyType_Ready from PyObject_Hash
........
Diffstat (limited to 'Lib/test/test_hash.py')
| -rw-r--r-- | Lib/test/test_hash.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py index 47c66d1..7ce40b9 100644 --- a/Lib/test/test_hash.py +++ b/Lib/test/test_hash.py @@ -111,9 +111,32 @@ class HashInheritanceTestCase(unittest.TestCase): self.assertFalse(isinstance(obj, Hashable), repr(obj)) +# Issue #4701: Check that some builtin types are correctly hashable +# (This test only used to fail in Python 3.0, but has been included +# in 2.x along with the lazy call to PyType_Ready in PyObject_Hash) +class DefaultIterSeq(object): + seq = range(10) + def __len__(self): + return len(self.seq) + def __getitem__(self, index): + return self.seq[index] + +class HashBuiltinsTestCase(unittest.TestCase): + hashes_to_check = [xrange(10), + enumerate(xrange(10)), + iter(DefaultIterSeq()), + iter(lambda: 0, 0), + ] + + def test_hashes(self): + _default_hash = object.__hash__ + for obj in self.hashes_to_check: + self.assertEqual(hash(obj), _default_hash(obj)) + def test_main(): test_support.run_unittest(HashEqualityTestCase, - HashInheritanceTestCase) + HashInheritanceTestCase, + HashBuiltinsTestCase) if __name__ == "__main__": |
