[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing/tests - testTraverser.py:1.1.2.8

Jim Fulton jim@cvs.zope.org
Tue, 19 Feb 2002 11:05:39 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing/tests
In directory cvs.zope.org:/tmp/cvs-serv7148/lib/python/Zope/App/Traversing/tests

Modified Files:
      Tag: Zope-3x-branch
	testTraverser.py 
Log Message:
Refactored tests to use a global-data cleanup framework.
This avoids a lot of messy clean-up code needed for tests that
use global registries, such as component services.

It is really important to make sure global registries get registered
with this framework.

See the doc strings in Zope.Testing.CleannUp.


=== Zope3/lib/python/Zope/App/Traversing/tests/testTraverser.py 1.1.2.7 => 1.1.2.8 ===
 from Zope.ContextWrapper import wrapper, Wrapper
 from Zope.Exceptions import NotFoundError, Unauthorized
-from Zope.ComponentArchitecture import provideAdapter, _clear
+from Zope.ComponentArchitecture import provideAdapter
 from Zope.App.Security.SecurityManagement import setSecurityPolicy, \
     noSecurityManager
 from Zope.App.Security.SimpleSecurityPolicies import NameBasedSecurityPolicy
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
 
 from Interface import verify, instancesOfObjectImplements
 
@@ -32,7 +33,7 @@
     def __init__(self, name):
         self.name = name
 
-class TraverserTests(unittest.TestCase):
+class TraverserTests(CleanUp, unittest.TestCase):
     def setUp(self):
         # Build up a wrapper chain
         self.root =   Wrapper(C('root'),   None,        name='')
@@ -60,7 +61,22 @@
         self.assertEquals(tr.getPhysicalPath(), ())
         self.failUnless(tr.getPhysicalRoot() is unwrapped)
 
-class UnrestrictedTraverseTests(unittest.TestCase):
+class UnrestrictedNoTraverseTests(CleanUp, unittest.TestCase):
+    def setUp(self):
+        self.root = root = C('root')
+        self.folder = folder = C('folder')
+        self.item = item = C('item')
+
+        root.folder = folder
+        folder.item = item
+
+        self.tr = Traverser(root)
+
+    def testNoTraversable(self):
+        self.assertRaises(NotFoundError, self.tr.unrestrictedTraverse,
+                          'folder')
+
+class UnrestrictedTraverseTests(CleanUp, unittest.TestCase):
     def setUp(self):
         provideAdapter(None, ITraversable, DefaultTraversable)
 
@@ -73,9 +89,6 @@
 
         self.tr = Traverser(root)
 
-    def tearDown(self):
-        _clear() # Clear out feature registration made
-
     def testSimplePathString(self):
         tr = self.tr
         item = self.item
@@ -110,12 +123,6 @@
             '/../folder/../../folder/item'), item)
         self.assertEquals(tr.unrestrictedTraverse('../../folder/item'), item)
 
-    def testNoTraversable(self):
-        _clear()
-
-        self.assertRaises(NotFoundError, self.tr.unrestrictedTraverse,
-                          'folder')
-
     def testNotFoundDefault(self):
         self.assertEquals(self.tr.unrestrictedTraverse('foo', 'notFound'),
             'notFound')
@@ -123,7 +130,7 @@
     def testNotFoundNoDefault(self):
         self.assertRaises(NotFoundError, self.tr.unrestrictedTraverse, 'foo')
 
-class RestrictedTraverseTests(unittest.TestCase):
+class RestrictedTraverseTests(CleanUp, unittest.TestCase):
     _oldPolicy = None
     _deniedNames = ()
 
@@ -145,8 +152,7 @@
     def tearDown(self):
         noSecurityManager()
         setSecurityPolicy(self._oldPolicy)
-
-        _clear() # Clear out feature registration made
+        CleanUp.tearDown(self)
 
     def denyNames(self, name):
         if name in self._deniedNames:
@@ -188,7 +194,7 @@
             ('folder', '..', 'folder'))
         self.assertEquals(tr.restrictedTraverse(('folder', 'item')), item)
 
-class DefaultTraversableTests(unittest.TestCase):
+class DefaultTraversableTests(CleanUp, unittest.TestCase):
     def testImplementsITraversable(self):
         self.failUnless(ITraversable.isImplementedBy(DefaultTraversable(None)))
 
@@ -227,6 +233,7 @@
     loader = unittest.TestLoader()
     suite = loader.loadTestsFromTestCase(TraverserTests)
     suite.addTest(loader.loadTestsFromTestCase(DefaultTraversableTests))
+    suite.addTest(loader.loadTestsFromTestCase(UnrestrictedNoTraverseTests))
     suite.addTest(loader.loadTestsFromTestCase(UnrestrictedTraverseTests))
     suite.addTest(loader.loadTestsFromTestCase(RestrictedTraverseTests))
     return suite