[Checkins] SVN: zope.etree/trunk/src/zope/etree/test Under certain circumstances the teardown method broke if zope.etree wasn't

Michael Kerrin michael.kerrin at openapp.biz
Tue Apr 10 14:38:31 EDT 2007


Log message for revision 74095:
  Under certain circumstances the teardown method broke if zope.etree wasn't
  used during a test.
  

Changed:
  U   zope.etree/trunk/src/zope/etree/testing.py
  U   zope.etree/trunk/src/zope/etree/tests.py

-=-
Modified: zope.etree/trunk/src/zope/etree/testing.py
===================================================================
--- zope.etree/trunk/src/zope/etree/testing.py	2007-04-10 15:09:49 UTC (rev 74094)
+++ zope.etree/trunk/src/zope/etree/testing.py	2007-04-10 18:38:30 UTC (rev 74095)
@@ -62,15 +62,25 @@
         test.globs["etree"] = engine
         test.globs["assertXMLEqual"] = assertXMLEqual
 
+    # Sometimes during testing the placelesssetup method is used and this
+    # tears down the global site manager during teardown. If the elementtree
+    # engine was never used during the lifetime of the test then we get an
+    # error in trying to teardown the engine. The getEngine method caches
+    # the utility lookup bypassing the need for the global site manger
+    # to know about the utility and thus not causing errors during tear down.
+    engine = zope.etree.getEngine()
     return engine
 
 
 def etreeTearDown(test = None):
+    etreeEngine = None
     if test is not None:
+        etreeEngine = test.globs["etree"]
         del test.globs["etree"]
         del test.globs["assertXMLEqual"]
-    etreeEtree = zope.etree.getEngine()
-    zope.component.getGlobalSiteManager().unregisterUtility(etreeEtree)
+    if etreeEngine is None:
+        etreeEngine = zope.etree.getEngine()
+    zope.component.getGlobalSiteManager().unregisterUtility(etreeEngine)
     zope.etree._utility = None # clear the cache
 
 #

Modified: zope.etree/trunk/src/zope/etree/tests.py
===================================================================
--- zope.etree/trunk/src/zope/etree/tests.py	2007-04-10 15:09:49 UTC (rev 74094)
+++ zope.etree/trunk/src/zope/etree/tests.py	2007-04-10 18:38:30 UTC (rev 74095)
@@ -34,6 +34,7 @@
 from zope.testing import renormalizing
 from zope.testing import testrunner
 from zope.interface.verify import verifyObject
+from zope.app.testing import placelesssetup
 
 import zope.etree.etree
 from interfaces import IEtree
@@ -245,6 +246,24 @@
     del test.globs['old_engine']
 
 
+class UnusedEtree(unittest.TestCase):
+    # Catch problem when the unittest tear down is broken because the
+    # placelesssetup module clears the global site manager.
+
+    def setUp(self):
+        placelesssetup.setUp()
+        etreeSetup()
+
+    def tearDown(self):
+        placelesssetup.tearDown()
+        etreeTearDown()
+
+    def test_simple(self):
+        # Just run a simple test to make sure that the setup / teardown
+        # works without errors.
+        self.assertEqual(1, 1)
+
+
 def test_suite():
     suite = unittest.TestSuite()
 
@@ -360,4 +379,7 @@
         suite.addTest(doctest.DocFileSuite(
             "README.txt", package = "zope.etree"))
 
+        # test teardown
+        suite.addTest(unittest.makeSuite(UnusedEtree))
+
     return suite



More information about the Checkins mailing list