MCPcopy Index your code
hub / github.com/python/cpython / test_hash

Method test_hash

Lib/test/test_builtin.py:1222–1241  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1220 self.assertRaises(ValueError, hasattr, B(), "b")
1221
1222 def test_hash(self):
1223 hash(None)
1224 self.assertEqual(hash(1), hash(1))
1225 self.assertEqual(hash(1), hash(1.0))
1226 hash('spam')
1227 self.assertEqual(hash('spam'), hash(b'spam'))
1228 hash((0,1,2,3))
1229 def f(): pass
1230 hash(f)
1231 self.assertRaises(TypeError, hash, [])
1232 self.assertRaises(TypeError, hash, {})
1233 # Bug 1536021: Allow hash to return long objects
1234 class X:
1235 def __hash__(self):
1236 return 2**100
1237 self.assertEqual(type(hash(X())), int)
1238 class Z(int):
1239 def __hash__(self):
1240 return self
1241 self.assertEqual(hash(Z(42)), hash(42))
1242
1243 def test_invalid_hash_typeerror(self):
1244 # GH-140406: The returned object from __hash__() would leak if it

Callers

nothing calls this directly

Calls 4

XClass · 0.70
ZClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected