[Zope3-checkins] CVS: Zope3/src/zope/app/tests - test_dependable.py:1.3

Guido van Rossum guido@python.org
Thu, 12 Jun 2003 15:28:09 -0400


Update of /cvs-repository/Zope3/src/zope/app/tests
In directory cvs.zope.org:/tmp/cvs-serv16761/tests

Modified Files:
	test_dependable.py 
Log Message:
Add relative/absolute path equivalence to the Dependable class, a la
UseConfiguration, and add unit tests for this.

Refactoring: share more code between Dependable and UseConfiguration.
The common base is in zope/app/dependable.py, for want of a better place.



=== Zope3/src/zope/app/tests/test_dependable.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/tests/test_dependable.py:1.2	Wed Dec 25 09:13:26 2002
+++ Zope3/src/zope/app/tests/test_dependable.py	Thu Jun 12 15:28:08 2003
@@ -11,38 +11,36 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""XXX short summary goes here.
-
-XXX longer description goes here.
+"""Unit tests for Dependable class.
 
 $Id$
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
-from zope.app.attributeannotations \
-     import AttributeAnnotations
+from zope.app.attributeannotations import AttributeAnnotations
 from zope.app.tests.placelesssetup import PlacelessSetup
+
 class C:pass
 
 class Test(PlacelessSetup, TestCase):
 
-
-    def _Test__new(self):
+    def factory(self):
         from zope.app.dependable import Dependable
         return Dependable(AttributeAnnotations(C()))
 
     def testVerifyInterface(self):
         from zope.interface.verify import verifyObject
         from zope.app.interfaces.dependable import IDependable
-        object = self._Test__new()
+        object = self.factory()
         verifyObject(IDependable, object)
 
-    def test(self):
-        dependable = self._Test__new()
+    def testBasic(self):
+        dependable = self.factory()
         self.failIf(dependable.dependents())
         dependable.addDependent('/a/b')
         dependable.addDependent('/c/d')
         dependable.addDependent('/c/e')
+        dependable.addDependent('/c/d')
         dependents = list(dependable.dependents())
         dependents.sort()
         self.assertEqual(dependents, ['/a/b', '/c/d', '/c/e'])
@@ -50,6 +48,24 @@
         dependents = list(dependable.dependents())
         dependents.sort()
         self.assertEqual(dependents, ['/a/b', '/c/e'])
+        dependable.removeDependent('/c/d')
+        dependents = list(dependable.dependents())
+        dependents.sort()
+        self.assertEqual(dependents, ['/a/b', '/c/e'])
+
+    def testRelativeAbsolute(self):
+        obj = self.factory()
+        # Hack the object to have a parent path
+        obj.pp = "/a/"
+        obj.pplen = len(obj.pp)
+        obj.addDependent("foo")
+        self.assertEqual(obj.dependents(), ("/a/foo",))
+        obj.removeDependent("/a/foo")
+        self.assertEqual(obj.dependents(), ())
+        obj.addDependent("/a/bar")
+        self.assertEqual(obj.dependents(), ("/a/bar",))
+        obj.removeDependent("bar")
+        self.assertEqual(obj.dependents(), ())
 
 def test_suite():
     return TestSuite((