[pypy-svn] r68487 - pypy/branch/gc-hash/pypy/objspace/std/test
arigo at codespeak.net
arigo at codespeak.net
Thu Oct 15 14:34:24 CEST 2009
Author: arigo
Date: Thu Oct 15 14:34:23 2009
New Revision: 68487
Modified:
pypy/branch/gc-hash/pypy/objspace/std/test/test_userobject.py
Log:
A test to ensure that the hash of objects does not change.
Runs 500000 iterations when run as an appdirect test.
Modified: pypy/branch/gc-hash/pypy/objspace/std/test/test_userobject.py
==============================================================================
--- pypy/branch/gc-hash/pypy/objspace/std/test/test_userobject.py (original)
+++ pypy/branch/gc-hash/pypy/objspace/std/test/test_userobject.py Thu Oct 15 14:34:23 2009
@@ -1,3 +1,4 @@
+from pypy.interpreter import gateway
class AppTestUserObject:
@@ -6,6 +7,15 @@
def setup_class(cls):
from pypy import conftest
cls.space = conftest.gettestobjspace(**cls.OPTIONS)
+ #
+ import random
+ def fn_rand():
+ return cls.space.wrap(random.randrange(0, 5))
+ if conftest.option.runappdirect:
+ cls.w_rand = fn_rand
+ else:
+ cls.w_rand = cls.space.wrap(gateway.interp2app(fn_rand))
+ cls.w_runappdirect = cls.space.wrap(bool(conftest.option.runappdirect))
def test_emptyclass(self):
class empty(object): pass
@@ -231,6 +241,38 @@
raises(AttributeError, "del Foo.x")
+ def test_hash(self):
+ if not hasattr(self, 'runappdirect'):
+ skip("disabled")
+ if self.runappdirect:
+ total = 500000
+ else:
+ total = 50
+ #
+ class A(object):
+ hash = None
+ tail = any = A()
+ tail.next = tail
+ i = 0
+ while i < total:
+ a = A()
+ a.next = tail.next
+ tail.next = a
+ for j in range(self.rand()):
+ any = any.next
+ if any.hash is None:
+ any.hash = hash(any)
+ else:
+ assert any.hash == hash(any)
+ i += 1
+ i = 0
+ while i < total:
+ if any.hash is not None:
+ assert any.hash == hash(any)
+ any = any.next
+ i += 1
+
+
class AppTestWithMultiMethodVersion2(AppTestUserObject):
OPTIONS = {} # for test_builtinshortcut.py
More information about the Pypy-commit
mailing list