summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2008-12-30 07:29:12 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2008-12-30 07:29:12 (GMT)
commitf1f2f686fe06c651e082029d7e76a7eefdb8a2de (patch)
treeaaa7fc633fc18c3b7f17b6dc6ac5d04bbdc165b9 /Lib/test
parent4450dcf041523fa6752be97994a4111a803dd1fc (diff)
downloadcpython-f1f2f686fe06c651e082029d7e76a7eefdb8a2de.zip
cpython-f1f2f686fe06c651e082029d7e76a7eefdb8a2de.tar.gz
cpython-f1f2f686fe06c651e082029d7e76a7eefdb8a2de.tar.bz2
Recorded merge of 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')
-rw-r--r--Lib/test/test_hash.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
index 59e43dc..807c2c4 100644
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -103,9 +103,30 @@ class HashInheritanceTestCase(unittest.TestCase):
self.assertFalse(isinstance(obj, Hashable), repr(obj))
+# Issue #4701: Check that some builtin types are correctly hashable
+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 = [range(10),
+ enumerate(range(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():
support.run_unittest(HashEqualityTestCase,
- HashInheritanceTestCase)
+ HashInheritanceTestCase,
+ HashBuiltinsTestCase)
if __name__ == "__main__":