diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-11-02 16:49:22 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-11-02 16:49:22 (GMT) |
commit | 4af77a027680f2aa956a4d1c50947d6e2dbd0185 (patch) | |
tree | 5da6482a5d2dd2472b83f1a9438b227166322b96 /Lib/test/test_buffer.py | |
parent | e6996ed5d9c3ce149a8384a625521ab5a0820ae3 (diff) | |
download | cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.zip cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.tar.gz cpython-4af77a027680f2aa956a4d1c50947d6e2dbd0185.tar.bz2 |
Issue #15814: Use hash function that is compatible with the equality
definition from #15573.
Diffstat (limited to 'Lib/test/test_buffer.py')
-rw-r--r-- | Lib/test/test_buffer.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 26cd9be..977b282 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -3999,14 +3999,42 @@ class TestBufferProtocol(unittest.TestCase): m = memoryview(x) self.assertEqual(hash(m), hash(x)) + # equality-hash invariant + x = ndarray(list(range(12)), shape=[12], format='B') + a = memoryview(nd) + + y = ndarray(list(range(12)), shape=[12], format='b') + b = memoryview(nd) + + z = ndarray(list(bytes(chr(x), 'latin-1') for x in range(12)), + shape=[12], format='c') + c = memoryview(nd) + + if (a == b): + self.assertEqual(hash(a), hash(b)) + + if (a == c): + self.assertEqual(hash(a), hash(c)) + + if (b == c): + self.assertEqual(hash(b), hash(c)) + # non-byte formats nd = ndarray(list(range(12)), shape=[2,2,3], format='L') m = memoryview(nd) - self.assertEqual(hash(m), hash(nd.tobytes())) + self.assertRaises(ValueError, m.__hash__) nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='h') m = memoryview(nd) - self.assertEqual(hash(m), hash(nd.tobytes())) + self.assertRaises(ValueError, m.__hash__) + + nd = ndarray(list(range(12)), shape=[2,2,3], format='= L') + m = memoryview(nd) + self.assertRaises(ValueError, m.__hash__) + + nd = ndarray(list(range(-6, 6)), shape=[2,2,3], format='< h') + m = memoryview(nd) + self.assertRaises(ValueError, m.__hash__) def test_memoryview_release(self): |