[Zope-Checkins] CVS: Zope/lib/Components/ExtensionClass/test - test_acquisition.py:1.4

Shane Hathaway shane@digicool.com
Fri, 14 Sep 2001 16:00:13 -0400


Update of /cvs-repository/Zope/lib/Components/ExtensionClass/test
In directory cvs.zope.org:/tmp/cvs-serv32296/test

Modified Files:
	test_acquisition.py 
Log Message:
Corrected aq_inContextOf().   The former code returned the incorrect result
if the context object was the root of the hierarchy, a condition which
normally does not occur in Zope, but can occur in scripts.


=== Zope/lib/Components/ExtensionClass/test/test_acquisition.py 1.3 => 1.4 ===
 assert( b.c.d == b.c )
 assert( b.c == c )
+
+
+def checkContext(self, o):
+    # Python equivalent to aq_inContextOf
+    from Acquisition import aq_base, aq_parent, aq_inner
+    subob = self
+    o = aq_base(o)
+    while 1:
+      if aq_base(subob) is o: return 1
+      self = aq_inner(subob)
+      if self is None: break
+      subob = aq_parent(self)
+      if subob is None: break
+
+
+assert checkContext(b.c, b)
+assert not checkContext(b.c, b.a)
+
+assert b.a.aq_inContextOf(b)
+assert b.c.aq_inContextOf(b)
+assert b.c.d.aq_inContextOf(b)
+assert b.c.d.aq_inContextOf(c)
+assert b.c.d.aq_inContextOf(b.c)
+assert not b.c.aq_inContextOf(foo)
+assert not b.c.aq_inContextOf(b.a)
+assert not b.a.aq_inContextOf('somestring')