[pypy-svn] r36436 - in pypy/dist/pypy: interpreter objspace/std/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Jan 10 21:56:03 CET 2007
Author: cfbolz
Date: Wed Jan 10 21:56:02 2007
New Revision: 36436
Added:
pypy/dist/pypy/objspace/std/test/test_shadowtracking.py
Modified:
pypy/dist/pypy/interpreter/typedef.py
Log:
(pedronis, cfbolz): add tests for the last checkin. also give up on shadow
tracking if an instance gets its __class__ changed.
Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py (original)
+++ pypy/dist/pypy/interpreter/typedef.py Wed Jan 10 21:56:02 2007
@@ -196,6 +196,14 @@
else:
self.w__dict__ = space.newdict()
self.user_setup_slots(w_subtype.nslots)
+
+ def setclass(self, space, w_subtype):
+ # only used by descr_set___class__
+ self.w__class__ = w_subtype
+ if space.config.objspace.std.withshadowtracking:
+ self.w__dict__.implementation.shadows_anything = True
+
+
else:
supercls = cls
Added: pypy/dist/pypy/objspace/std/test/test_shadowtracking.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/objspace/std/test/test_shadowtracking.py Wed Jan 10 21:56:02 2007
@@ -0,0 +1,77 @@
+from pypy.conftest import gettestobjspace
+
+class TestShadowTracking(object):
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.withshadowtracking": True})
+
+ def test_simple_shadowing(self):
+ space = self.space
+ w_inst = space.appexec([], """():
+ class A(object):
+ def f(self):
+ return 42
+ a = A()
+ return a
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ a.g = "foo"
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ a.f = "foo"
+ """)
+ assert w_inst.w__dict__.implementation.shadows_anything
+
+ def test_shadowing_via__dict__(self):
+ space = self.space
+ w_inst = space.appexec([], """():
+ class A(object):
+ def f(self):
+ return 42
+ a = A()
+ return a
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ a.__dict__["g"] = "foo"
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ a.__dict__["f"] = "foo"
+ """)
+ assert w_inst.w__dict__.implementation.shadows_anything
+
+ def test_changing__dict__(self):
+ space = self.space
+ w_inst = space.appexec([], """():
+ class A(object):
+ def f(self):
+ return 42
+ a = A()
+ return a
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ a.__dict__ = {}
+ """)
+ assert w_inst.w__dict__.implementation.shadows_anything
+
+ def test_changing__class__(self):
+ space = self.space
+ w_inst = space.appexec([], """():
+ class A(object):
+ def f(self):
+ return 42
+ a = A()
+ return a
+ """)
+ assert not w_inst.w__dict__.implementation.shadows_anything
+ space.appexec([w_inst], """(a):
+ class B(object):
+ def g(self):
+ return 42
+ a.__class__ = B
+ """)
+ assert w_inst.w__dict__.implementation.shadows_anything
+
More information about the Pypy-commit
mailing list