[Checkins] SVN: zope.security/trunk/ Made non-doctest tests fully independent of ``zope.testing``.

Tres Seaver cvs-admin at zope.org
Fri Dec 21 01:58:19 UTC 2012


Log message for revision 128816:
  Made non-doctest tests fully independent of ``zope.testing``.
  
  Two modules, ``zope.security.checker`` and ``zope.security.management``,
  register cleanups with ``zope.testing`` IFF it is importable, but the
  tests no longer rely on it.
  

Changed:
  _U  zope.security/trunk/
  U   zope.security/trunk/CHANGES.txt
  U   zope.security/trunk/src/zope/security/management.py
  U   zope.security/trunk/src/zope/security/tests/test_checker.py
  U   zope.security/trunk/src/zope/security/tests/test_management.py
  U   zope.security/trunk/src/zope/security/untrustedpython/tests.py

-=-
Modified: zope.security/trunk/CHANGES.txt
===================================================================
--- zope.security/trunk/CHANGES.txt	2012-12-21 01:28:43 UTC (rev 128815)
+++ zope.security/trunk/CHANGES.txt	2012-12-21 01:58:19 UTC (rev 128816)
@@ -5,6 +5,12 @@
 4.0.0 (unreleased)
 ------------------
 
+- Made non-doctest tests fully independent of ``zope.testing``.
+
+  Two modules, ``zope.security.checker`` and ``zope.security.management``,
+  register cleanups with ``zope.testing`` IFF it is importable, but the
+  tests no longer rely on it.
+
 - Enabled building extensions without the 'svn:external' of the ``zope.proxy``
   headers into our 'include' dir.
 

Modified: zope.security/trunk/src/zope/security/management.py
===================================================================
--- zope.security/trunk/src/zope/security/management.py	2012-12-21 01:28:43 UTC (rev 128815)
+++ zope.security/trunk/src/zope/security/management.py	2012-12-21 01:58:19 UTC (rev 128816)
@@ -28,22 +28,6 @@
     interfaces.ISecurityManagement,
     interfaces.IInteractionManagement)
 
-def _clear():
-    global _defaultPolicy
-    _defaultPolicy = ParanoidSecurityPolicy
-
-# XXX This code is used to support automated testing. However, it shouldn't be
-# here and needs to be refactored. The empty addCleanUp-method is a temporary
-# workaround to fix packages that depend on zope.security but don't have a
-# need for zope.testing.
-try:
-    from zope.testing.cleanup import addCleanUp
-except ImportError:
-    def addCleanUp(arg):
-        pass
-
-addCleanUp(_clear)
-
 #
 #   ISecurityManagement implementation
 #
@@ -140,4 +124,19 @@
             raise interfaces.NoInteraction
     return interaction.checkPermission(permission, object)
 
-addCleanUp(endInteraction)
+
+def _clear():
+    global _defaultPolicy
+    _defaultPolicy = ParanoidSecurityPolicy
+
+# XXX This code is used to support automated testing. However, it shouldn't be
+# here and needs to be refactored. The empty addCleanUp-method is a temporary
+# workaround to fix packages that depend on zope.security but don't have a
+# need for zope.testing.
+try:
+    from zope.testing.cleanup import addCleanUp
+except ImportError:
+    pass
+else:
+    addCleanUp(_clear)
+    addCleanUp(endInteraction)

Modified: zope.security/trunk/src/zope/security/tests/test_checker.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_checker.py	2012-12-21 01:28:43 UTC (rev 128815)
+++ zope.security/trunk/src/zope/security/tests/test_checker.py	2012-12-21 01:58:19 UTC (rev 128816)
@@ -16,7 +16,6 @@
 from unittest import TestCase, TestSuite, main, makeSuite
 from zope.interface import implementer
 from zope.interface.verify import verifyObject
-from zope.testing.cleanup import CleanUp
 from zope.proxy import getProxiedObject
 from zope.security.interfaces import ISecurityPolicy, Unauthorized
 from zope.security.interfaces import Forbidden, ForbiddenAttribute
@@ -94,17 +93,19 @@
     e = property(gete, sete)
 
 
-class Test(TestCase, CleanUp):
+class Test(TestCase):
 
     def setUp(self):
-        CleanUp.setUp(self)
+        from zope.security.checker import _clear
+        _clear()
         self.__oldpolicy = setSecurityPolicy(SecurityPolicy)
         newInteraction()
 
     def tearDown(self):
+        from zope.security.checker import _clear
         endInteraction()
         setSecurityPolicy(self.__oldpolicy)
-        CleanUp.tearDown(self)
+        _clear()
 
     def test_typesAcceptedByDefineChecker(self):
         class ClassicClass:

Modified: zope.security/trunk/src/zope/security/tests/test_management.py
===================================================================
--- zope.security/trunk/src/zope/security/tests/test_management.py	2012-12-21 01:28:43 UTC (rev 128815)
+++ zope.security/trunk/src/zope/security/tests/test_management.py	2012-12-21 01:58:19 UTC (rev 128816)
@@ -11,18 +11,27 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-""" Unit tests for SecurityManagement
+""" Unit tests for zope.security.management
 """
-
 import unittest
 
-from zope.interface.verify import verifyObject
-from zope.testing.cleanup import CleanUp
 
+class Test(unittest.TestCase):
 
-class Test(CleanUp, unittest.TestCase):
+    def setUp(self):
+        self._cleanUp()
 
+    def tearDown(self):
+        self._cleanUp()
+
+    def _cleanUp(self):
+        from zope.security.management import _clear
+        from zope.security.management import endInteraction
+        _clear()
+        endInteraction()
+
     def test_import(self):
+        from zope.interface.verify import verifyObject
         from zope.security import management
         from zope.security.interfaces import ISecurityManagement
         from zope.security.interfaces import IInteractionManagement

Modified: zope.security/trunk/src/zope/security/untrustedpython/tests.py
===================================================================
--- zope.security/trunk/src/zope/security/untrustedpython/tests.py	2012-12-21 01:28:43 UTC (rev 128815)
+++ zope.security/trunk/src/zope/security/untrustedpython/tests.py	2012-12-21 01:58:19 UTC (rev 128816)
@@ -13,17 +13,15 @@
 ##############################################################################
 """Untrusted python tests
 """
-
-import doctest
 import unittest
-import re
 
-from zope.testing import renormalizing
 
-
 def test_suite():
+    import doctest
+    import re
     try:
         import RestrictedPython
+        from zope.testing import renormalizing
     except ImportError:
         return unittest.TestSuite()
 



More information about the checkins mailing list