[pypy-svn] r29534 - pypy/dist/pypy/rpython/ootypesystem/test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jun 30 16:08:21 CEST 2006


Author: antocuni
Date: Fri Jun 30 16:08:16 2006
New Revision: 29534

Modified:
   pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py
Log:
Added a failing test.

Basically, if we modify the Record after its hash has already been
computed, we might obtain two objects that compare equal but hash
differently.

Disabling the caching in LowLevelType.__hash__ fix the test, but I
think it's not what we want.

Adding the following __hash__ to ootype.Record also fix the test, but
I'm not sure if it's correct, especially with recursive structures:

  def __hash__(self):
    return hash(self._fields)




Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_oorecord.py	Fri Jun 30 16:08:16 2006
@@ -38,3 +38,14 @@
     t.a = 1
     t.b = 2
     assert ooidentityhash(t) != ooidentityhash(t2)
+
+import py
+def test_hash():
+    #py.test.skip("LowLevelType.__hash__ bug waiting to be fixed")
+    T1 = Record({"item0": Signed, "item1": Signed})
+    T2 = Record({"item0": Signed})
+
+    hash(T2) # compute the hash, it will stored in __cached_hash
+    T2._add_fields({"item1": Signed}) # modify the object
+    assert T1 == T2
+    assert hash(T1) == hash(T2)



More information about the Pypy-commit mailing list