[Zope3-checkins] CVS: Zope3/src/zope/app/component/tests - test_contentdirective.py:1.6.2.1 test_directives.py:1.14.2.1 test_factory.py:1.7.2.1 test_requirepermissions.py:1.8.2.1 test_servicedirective.py:1.10.2.1

Philipp von Weitershausen philikon at philikon.de
Wed Aug 6 11:28:18 EDT 2003


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

Modified Files:
      Tag: zcml-interface-field-branch
	test_contentdirective.py test_directives.py test_factory.py 
	test_requirepermissions.py test_servicedirective.py 
Log Message:
Fix up tests to use the ConfigurationMachine from zope.app.configure which
is service-aware.


=== Zope3/src/zope/app/component/tests/test_contentdirective.py 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/component/tests/test_contentdirective.py:1.6	Sun Aug  3 13:50:15 2003
+++ Zope3/src/zope/app/component/tests/test_contentdirective.py	Wed Aug  6 10:27:40 2003
@@ -17,17 +17,22 @@
 """
 
 import unittest
-from StringIO import StringIO
 
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.management import newSecurityManager, system_user
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationExecutionError
 from zope.security.proxy import Proxy
-import zope.configuration
+from zope.component import getService
+
+# this import needs to be done after the above
+from zope.security.management import newSecurityManager, system_user
+
 import zope.app.security
 import zope.app.component
-from zope.app.security.exceptions import UndefinedPermissionError
-from zope.component import getService
+import zope.app.configuration
+import zope.app.component.service
+import zope.app.publisher.browser
+
+from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.services.servicenames import Factories
 from zope.app.component.globalinterfaceservice import queryInterface
 
@@ -38,32 +43,39 @@
 
 
 def configfile(s):
-    return StringIO("""<configure
+    return """<configure
       xmlns='http://namespaces.zope.org/zope'
       i18n_domain='zope'>
       %s
-      </configure>
-      """ % s)
+      </configure>""" % s
 
 class TestContentDirective(PlacelessSetup, unittest.TestCase):
+
     def setUp(self):
         PlacelessSetup.setUp(self)
         newSecurityManager(system_user)
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
+        self._config()
 
         try:
             del ExampleClass.__implements__
         except AttributeError:
             pass
 
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        xmlconfig.file('meta.zcml', package=zope.app.security,
+                       context=context)
+        self._context = context
+
     def testEmptyDirective(self):
         f = configfile("""
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
-</content>
-                       """)
-        xmlconfig(f)
-
+</content>""")
+        xmlconfig.string(f, context=self._context)
 
     def testImplements(self):
         self.assertEqual(queryInterface(
@@ -72,15 +84,13 @@
         f = configfile("""
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
   <implements interface="zope.app.component.tests.exampleclass.IExample" />
-</content>
-                       """)
-        xmlconfig(f)
+</content>""")
+        xmlconfig.string(f, context=self._context)
         self.failUnless(IExample.isImplementedByInstancesOf(ExampleClass))
 
         self.assertEqual(queryInterface(
             "zope.app.component.tests.exampleclass.IExample"), IExample)
 
-
     def testMulImplements(self):
         self.assertEqual(queryInterface(
             "zope.app.component.tests.exampleclass.IExample"), None)
@@ -93,9 +103,8 @@
            zope.app.component.tests.exampleclass.IExample
            zope.app.component.tests.exampleclass.IExample2
                        " />
-</content>
-                       """)
-        xmlconfig(f)
+</content>""")
+        xmlconfig.string(f, context=self._context)
         self.failUnless(IExample.isImplementedByInstancesOf(ExampleClass))
         self.failUnless(IExample2.isImplementedByInstancesOf(ExampleClass))
 
@@ -111,33 +120,38 @@
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
     <require permission="zope.View"
                       attributes="anAttribute anotherAttribute" />
-</content>
-                       """)
-        xmlconfig(f)
+</content>""")
+        xmlconfig.string(f, context=self._context)
 
     def testAllow(self):
         f = configfile("""
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
     <allow attributes="anAttribute anotherAttribute" />
-</content>
-                       """)
-        xmlconfig(f)
+</content>""")
+        xmlconfig.string(f, context=self._context)
 
     def testMimic(self):
         f = configfile("""
 <content class="zope.app.component.tests.exampleclass.ExampleClass">
     <require like_class="zope.app.component.tests.exampleclass.ExampleClass" />
-</content>
-                       """)
-        xmlconfig(f)
-
+</content>""")
+        xmlconfig.string(f, context=self._context)
 
 class TestFactorySubdirective(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         PlacelessSetup.setUp(self)
         newSecurityManager(system_user)
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
+        self._config()
+
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        xmlconfig.file('meta.zcml', package=zope.app.security,
+                       context=context)
+        self._context = context
 
     def testFactory(self):
         f = configfile("""
@@ -150,13 +164,10 @@
       title="Example content"
       description="Example description"
     />
-</content>
-                       """)
-        xmlconfig(f)
-
+</content>""")
+        xmlconfig.string(f, context=self._context)
 
     def testFactoryUndefinedPermission(self):
-
         f = configfile("""
 <permission id="zope.Foo" title="Zope Foo Permission" />
 
@@ -167,11 +178,9 @@
       title="Example content"
       description="Example description"
     />
-</content>
-            """)
-        self.assertRaises(UndefinedPermissionError, xmlconfig, f,
-                          testing=1)
-
+</content>""")
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string, f,
+                          context=self._context)
 
     def testFactoryPublicPermission(self):
 
@@ -185,20 +194,17 @@
       title="Example content"
       description="Example description"
     />
-</content>
-            """)
-        xmlconfig(f)
+</content>""")
+        xmlconfig.string(f, context=self._context)
         factory = getService(None, Factories).getFactory('Example')
         self.failUnless(type(factory) is Proxy)
 
-
 def test_suite():
     suite = unittest.TestSuite()
     loader = unittest.TestLoader()
     suite.addTest(loader.loadTestsFromTestCase(TestContentDirective))
     suite.addTest(loader.loadTestsFromTestCase(TestFactorySubdirective))
     return suite
-
 
 if __name__=='__main__':
     unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/app/component/tests/test_directives.py 1.14 => 1.14.2.1 ===
--- Zope3/src/zope/app/component/tests/test_directives.py:1.14	Sun Aug  3 13:50:15 2003
+++ Zope3/src/zope/app/component/tests/test_directives.py	Wed Aug  6 10:27:40 2003
@@ -11,31 +11,30 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""
+$Id$
+"""
 
 import unittest
-from cStringIO import StringIO
-
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-from zope.configuration.exceptions import ConfigurationError
-from zope.app.security.exceptions import UndefinedPermissionError
 
+from zope.interface import implements
 from zope.proxy import getProxiedObject
 from zope.security.proxy import getTestProxyItems
-
-import zope.app.component
 from zope.component.exceptions import ComponentLookupError
-from zope.component import getView, queryView, queryResource
-from zope.component import createObject
-from zope.component import getDefaultViewName
-from zope.component import getAdapter, queryAdapter
-from zope.component import getNamedAdapter, queryNamedAdapter
-from zope.component import getUtility, queryUtility
 
-from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationExecutionError
+from zope.configuration.exceptions import ConfigurationError
+
 from zope.component.tests.views import IV, IC, V1, VZMI, R1, RZMI
 from zope.component.tests.request import Request
-from zope.interface import implements
 
+import zope.app.component
+import zope.app.component.service
+import zope.app.configuration
+
+from zope.app import zapi
+from zope.app.tests.placelesssetup import PlacelessSetup
 
 template = """<configure
    xmlns='http://namespaces.zope.org/zope'
@@ -47,26 +46,29 @@
 class Ob:
     implements(IC)
 
-def definePermissions():
-    XMLConfig('meta.zcml', zope.app.component)()
-
 class Test(PlacelessSetup, unittest.TestCase):
 
     # XXX: tests for other directives needed
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
+        self._config()
 
-    def testAdapter(self):
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        xmlconfig.file('meta.zcml', package=zope.app.security,
+                       context=context)
+        self._context = context
 
+    def testAdapter(self):
         # Full import is critical!
         from zope.component.tests.components import Content, IApp, Comp
-
-        self.assertEqual(queryAdapter(Content(), IV, None), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryAdapter(Content(), IV, None), None)
+        xmlconfig.string(template % (
             """
             <adapter
               factory="zope.component.tests.components.Comp"
@@ -74,22 +76,20 @@
               for="zope.component.tests.components.IContent"
               />
             """
-            )))
-
-        self.assertEqual(getAdapter(Content(), IApp).__class__, Comp)
+            ),
+                         context=self._context)
+        self.assertEqual(zapi.getAdapter(Content(), IApp).__class__, Comp)
 
     def testNamedAdapter(self):
-
-
         # Full import is critical!
         from zope.component.tests.components import Content, IApp, Comp
 
         self.testAdapter()
-        self.assertEqual(getAdapter(Content(), IApp).__class__, Comp)
-        self.assertEqual(queryNamedAdapter(Content(), IV, 'test'),
+        self.assertEqual(zapi.getAdapter(Content(), IApp).__class__, Comp)
+        self.assertEqual(zapi.queryNamedAdapter(Content(), IV, 'test'),
                          None)
 
-        xmlconfig(StringIO(template % (
+        xmlconfig.string(template % (
             """
             <adapter
               factory="zope.component.tests.components.Comp"
@@ -98,19 +98,17 @@
               name="test"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(getNamedAdapter(Content(), IApp, "test").__class__,
+        self.assertEqual(zapi.getNamedAdapter(Content(), IApp, "test").__class__,
                          Comp)
 
     def testProtectedAdapter(self):
-
         # Full import is critical!
         from zope.component.tests.components import Content, IApp, Comp
-
-        self.assertEqual(queryAdapter(Content(), IV, None), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryAdapter(Content(), IV, None), None)
+        xmlconfig.string(template % (
             """
             <adapter
               factory="zope.component.tests.components.Comp"
@@ -119,55 +117,47 @@
               permission="zope.Public"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        adapter = getAdapter(Content(), IApp)
+        adapter = zapi.getAdapter(Content(), IApp)
         items = [item[0] for item in getTestProxyItems(adapter)]
         self.assertEqual(items, ['a', 'f'])
         self.assertEqual(getProxiedObject(adapter).__class__, Comp)
 
     def testAdapterUndefinedPermission(self):
-        config = StringIO(template % (
-             """
+        config = template % """
              <adapter
               factory="zope.component.tests.components.Comp"
               provides="zope.component.tests.components.IApp"
               for="zope.component.tests.components.IContent"
               permission="zope.UndefinedPermission"
-              />
-            """
-            ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
+              />"""
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string,
+                          config, context=self._context)
 
     def testUtility(self):
-
         # Full import is critical!
         from zope.component.tests.components import IApp, comp
-
-        self.assertEqual(queryUtility(None, IV, None), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
+        xmlconfig.string(template % (
             """
             <utility
               component="zope.component.tests.components.comp"
               provides="zope.component.tests.components.IApp"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(getUtility(None, IApp), comp)
+        self.assertEqual(zapi.getUtility(None, IApp), comp)
 
     def testNamedUtility(self):
-
         # Full import is critical!
         from zope.component.tests.components import IApp, comp
-
         self.testUtility()
-
-        self.assertEqual(queryUtility(None, IV, None, name='test'), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryUtility(None, IV, None, name='test'), None)
+        xmlconfig.string(template % (
             """
             <utility
               component="zope.component.tests.components.comp"
@@ -175,36 +165,32 @@
               name="test"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(getUtility(None, IApp, "test"), comp)
+        self.assertEqual(zapi.getUtility(None, IApp, "test"), comp)
 
     def testUtilityFactory(self):
-
         # Full import is critical!
         from zope.component.tests.components import IApp, Comp
-
-        self.assertEqual(queryUtility(None, IV, None), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
+        xmlconfig.string(template % (
             """
             <utility
               factory="zope.component.tests.components.Comp"
               provides="zope.component.tests.components.IApp"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(getUtility(None, IApp).__class__, Comp)
+        self.assertEqual(zapi.getUtility(None, IApp).__class__, Comp)
 
     def testProtectedUtility(self):
-
         # Full import is critical!
         from zope.component.tests.components import IApp, comp
-
-        self.assertEqual(queryUtility(None, IV, None), None)
-
-        xmlconfig(StringIO(template % (
+        self.assertEqual(zapi.queryUtility(None, IV, None), None)
+        xmlconfig.string(template % (
             """
             <utility
               component="zope.component.tests.components.comp"
@@ -212,81 +198,70 @@
               permission="zope.Public"
               />
             """
-            )))
+            ),
+                         context=self._context)
 
-        utility = getUtility(None, IApp)
+        utility = zapi.getUtility(None, IApp)
         items = [item[0] for item in getTestProxyItems(utility)]
         self.assertEqual(items, ['a', 'f'])
         self.assertEqual(getProxiedObject(utility), comp)
 
     def testUtilityUndefinedPermission(self):
-        config = StringIO(template % (
-             """
+        config = template % """
              <utility
               component="zope.component.tests.components.comp"
               provides="zope.component.tests.components.IApp"
               permission="zope.UndefinedPermission"
-              />
-            """
-            ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
-
+              />"""
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string,
+                          config, context=self._context)
 
     def testView(self):
-
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
-        xmlconfig(StringIO(template %
-            """
+        xmlconfig.string(template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
-                  type="zope.component.tests.views.IV"/>
-            """
-            ))
+                  type="zope.component.tests.views.IV"/>""",
+                         context=self._context)
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None).__class__,
                          V1)
 
     def testInterfaceProtectedView(self):
-        xmlconfig(StringIO(template %
-            """
+        xmlconfig.string(template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"
                   permission="zope.Public"
-              allowed_interface="zope.component.tests.views.IV"
-                  />
-            """
-            ))
+                  allowed_interface="zope.component.tests.views.IV"
+                  />""",
+                         context=self._context)
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.index(), 'V1 here')
         self.assertRaises(Exception, getattr, v, 'action')
 
     def testAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            """
+        xmlconfig.string(template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"
                   permission="zope.Public"
                   allowed_attributes="action"
-                  />
-            """
-            ))
+                  />""",
+                         context=self._context)
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.action(), 'done')
         self.assertRaises(Exception, getattr, v, 'index')
 
     def testInterfaceAndAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            """
+        xmlconfig.string(template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
@@ -295,104 +270,92 @@
                   allowed_attributes="action"
               allowed_interface="zope.component.tests.views.IV"
                   />
-            """
-            ))
+            """,
+                         context=self._context)
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.index(), 'V1 here')
         self.assertEqual(v.action(), 'done')
 
     def testDuplicatedInterfaceAndAttributeProtectedView(self):
-        xmlconfig(StringIO(template %
-            """
+        xmlconfig.string(template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"
                   permission="zope.Public"
                   allowed_attributes="action index"
-              allowed_interface="zope.component.tests.views.IV"
-                  />
-            """
-            ))
+                  allowed_interface="zope.component.tests.views.IV"
+                  />""",
+                         context=self._context)
 
-        v = getView(Ob(), 'test', Request(IV))
+        v = zapi.getView(Ob(), 'test', Request(IV))
         self.assertEqual(v.index(), 'V1 here')
         self.assertEqual(v.action(), 'done')
 
     def testIncompleteProtectedViewNoPermission(self):
-        self.assertRaises(
-            ConfigurationError,
-            xmlconfig,
-            StringIO(template %
-            """
+        self.assertRaises(ConfigurationError, xmlconfig.string,
+                          template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"
                   allowed_attributes="action index"
-                  />
-            """
-            ))
+                  />""",
+                          context=self._context)
 
     def testViewUndefinedPermission(self):
-        config = StringIO(template % (
-            """
+        config = template % """
             <view name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"
                   permission="zope.UndefinedPermission"
                   allowed_attributes="action index"
-              allowed_interface="zope.component.tests.views.IV"
-                  />
-            """
-            ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
-
-
+                  allowed_interface="zope.component.tests.views.IV"
+                  />"""
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string,
+                          config, context=self._context)
 
     def testDefaultView(self):
-
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
-        xmlconfig(StringIO(template % (
+        xmlconfig.string(template % (
             """
             <defaultView name="test"
                   factory="zope.component.tests.views.V1"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"/>
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None).__class__,
                          V1)
-        self.assertEqual(getDefaultViewName(ob, Request(IV)), 'test')
+        self.assertEqual(zapi.getDefaultViewName(ob, Request(IV)), 'test')
 
     def testDefaultViewOnly(self):
-
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
-        xmlconfig(StringIO(template % (
+        xmlconfig.string(template % (
             """
             <defaultView name="test"
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"/>
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
-        self.assertEqual(getDefaultViewName(ob, Request(IV)), 'test')
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.getDefaultViewName(ob, Request(IV)), 'test')
 
     def testSkinView(self):
-
         ob = Ob()
-        self.assertEqual(queryView(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None), None)
 
-        xmlconfig(StringIO(template % (
+        xmlconfig.string(template % (
             """
             <skin name="zmi" layers="zmi default"
                   type="zope.component.tests.views.IV" />
@@ -406,50 +369,43 @@
                   for="zope.component.tests.views.IC"
                   type="zope.component.tests.views.IV"/>
             """
-            )))
+            ),
+                         context=self._context)
 
-        self.assertEqual(queryView(ob, 'test', Request(IV), None).__class__,
+        self.assertEqual(zapi.queryView(ob, 'test', Request(IV), None).__class__,
                          V1)
         self.assertEqual(
-            queryView(ob, 'test', Request(IV, 'zmi'), None).__class__,
+            zapi.queryView(ob, 'test', Request(IV, 'zmi'), None).__class__,
             VZMI)
 
     def testResource(self):
-
         ob = Ob()
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None), None)
-        xmlconfig(StringIO(template % (
-            """
+        self.assertEqual(zapi.queryResource(ob, 'test', Request(IV), None), None)
+        xmlconfig.string(template % """
             <resource name="test"
                   factory="zope.component.tests.views.R1"
                   type="zope.component.tests.views.IV"/>
-            """
-            )))
+            """,
+                         context=self._context)
 
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None
+        self.assertEqual(zapi.queryResource(ob, 'test', Request(IV), None
                                        ).__class__,
                          R1)
 
     def testResourceUndefinedPermission(self):
-
-        config = StringIO(template % (
-            """
+        config = template % """
             <resource name="test"
                   factory="zope.component.tests.views.R1"
                   type="zope.component.tests.views.IV"
-                  permission="zope.UndefinedPermission"/>
-            """
-            ))
-        self.assertRaises(UndefinedPermissionError, xmlconfig, config,
-                          testing=1)
-
+                  permission="zope.UndefinedPermission"/>"""
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string,
+                          config, context=self._context)
 
     def testSkinResource(self):
-
         ob = Ob()
-        self.assertEqual(queryResource(ob, 'test', Request(IV), None), None)
+        self.assertEqual(zapi.queryResource(ob, 'test', Request(IV), None), None)
 
-        xmlconfig(StringIO(template % (
+        xmlconfig.string(template % (
             """
             <skin name="zmi" layers="zmi default"
                   type="zope.component.tests.views.IV" />
@@ -461,30 +417,30 @@
                   factory="zope.component.tests.views.R1"
                   type="zope.component.tests.views.IV"/>
             """
-            )))
+            ),
+                         context=self._context)
 
         self.assertEqual(
-            queryResource(ob, 'test', Request(IV), None).__class__,
+            zapi.queryResource(ob, 'test', Request(IV), None).__class__,
             R1)
         self.assertEqual(
-            queryResource(ob, 'test', Request(IV, 'zmi'), None).__class__,
+            zapi.queryResource(ob, 'test', Request(IV, 'zmi'), None).__class__,
             RZMI)
 
     def testFactory(self):
-
-        self.assertRaises(ComponentLookupError, createObject, None, 'foo')
-
-        xmlconfig(StringIO(template % (
+        self.assertRaises(ComponentLookupError, zapi.createObject, None, 'foo')
+        xmlconfig.string(template % (
             """
             <factory
                id="foo"
                component="zope.component.tests.factory.f"
                />
             """
-            )))
+            ),
+                         context=self._context)
 
         from zope.component.tests.factory import X
-        self.assertEqual(createObject(None, 'foo').__class__, X)
+        self.assertEqual(zapi.createObject(None, 'foo').__class__, X)
 
 def test_suite():
     return unittest.makeSuite(Test)


=== Zope3/src/zope/app/component/tests/test_factory.py 1.7 => 1.7.2.1 ===
--- Zope3/src/zope/app/component/tests/test_factory.py:1.7	Sun Aug  3 13:50:15 2003
+++ Zope3/src/zope/app/component/tests/test_factory.py	Wed Aug  6 10:27:40 2003
@@ -14,34 +14,41 @@
 """ Test handler for 'factory' subdirective of 'content' directive """
 
 import unittest
-from cStringIO import StringIO
 
-from zope.configuration.xmlconfig import xmlconfig
-from zope.configuration.xmlconfig import XMLConfig
-from zope.app.services.servicenames import Factories
-from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.configuration import xmlconfig
 from zope.security.management import newSecurityManager, system_user
 
-import zope.configuration
 import zope.app.security
 import zope.app.component
+import zope.app.component.service
+import zope.app.configuration
 
+from zope.app.services.servicenames import Factories
+from zope.app.tests.placelesssetup import PlacelessSetup
 from zope.app.component.tests.exampleclass import ExampleClass
 
 def configfile(s):
-    return StringIO("""<configure
+    return """<configure
       xmlns='http://namespaces.zope.org/zope'
       i18n_domain='zope'>
       %s
-      </configure>
-      """ % s)
+      </configure>""" % s
 
 class Test(PlacelessSetup, unittest.TestCase):
     def setUp(self):
         PlacelessSetup.setUp(self)
         newSecurityManager(system_user)
-        XMLConfig('meta.zcml', zope.app.component)()
-        XMLConfig('meta.zcml', zope.app.security)()
+        self._config()
+
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        xmlconfig.file('meta.zcml', package=zope.app.security,
+                       context=context)
+        self._context = context
 
     def testFactory(self):
         from zope.component import getService
@@ -57,7 +64,7 @@
        />
 </content>
                        """)
-        xmlconfig(f)
+        xmlconfig.string(f, context=self._context)
         obj = getService(None, Factories).createObject('Example')
         obj = removeAllProxies(obj)
         self.failUnless(isinstance(obj, ExampleClass))


=== Zope3/src/zope/app/component/tests/test_requirepermissions.py 1.8 => 1.8.2.1 ===
--- Zope3/src/zope/app/component/tests/test_requirepermissions.py:1.8	Sun Aug  3 15:08:19 2003
+++ Zope3/src/zope/app/component/tests/test_requirepermissions.py	Wed Aug  6 10:27:40 2003
@@ -13,32 +13,23 @@
 ##############################################################################
 """ Test handler for 'require' subdirective of 'content' directive """
 
-from cStringIO import StringIO
-from zope.app.component.globalinterfaceservice import queryInterface
-from zope.app.component.tests import module
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.security.checker import selectChecker
 import unittest
-import zope.app.component
-import zope.app.security
-import zope.configuration
+
 from zope.interface import implements
+from zope.configuration import xmlconfig
+from zope.configuration.xmlconfig import ZopeXMLConfigurationError
+from zope.security.checker import selectChecker
 
-# So we can use config parser to exercise protectClass stuff.
-from zope.configuration.xmlconfig import XMLConfig
-from zope.configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
+import zope.app.security
+import zope.app.component
+import zope.app.component.service
+import zope.app.configuration
 
-PREFIX = module.__name__ + '.'
+from zope.app.component.globalinterfaceservice import queryInterface
+from zope.app.component.tests import module
+from zope.app.tests.placelesssetup import PlacelessSetup
 
-def defineDirectives():
-    XMLConfig('meta.zcml', zope.app.component)()
-    XMLConfig('meta.zcml', zope.app.security)()
-    xmlconfig(StringIO("""<configure
-        xmlns='http://namespaces.zope.org/zope'
-        i18n_domain='zope'>
-       <permission id="zope.Extravagant" title="extravagant" />
-       <permission id="zope.Paltry" title="paltry" />
-    </configure>"""))
+PREFIX = module.__name__ + '.'
 
 NOTSET = []
 
@@ -49,7 +40,7 @@
 
     def setUp(self):
         PlacelessSetup.setUp(self)
-        defineDirectives()
+        self._config()
 
         class B:
             def m1(self):
@@ -67,6 +58,23 @@
         module.test_instance = C()
         self.assertState()
 
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        xmlconfig.file('meta.zcml', package=zope.app.security,
+                       context=context)
+        xmlconfig.string("""<configure
+        xmlns='http://namespaces.zope.org/zope'
+        i18n_domain='zope'>
+       <permission id="zope.Extravagant" title="extravagant" />
+       <permission id="zope.Paltry" title="paltry" />
+    </configure>""",
+                         context=context)
+        self._context = context
+
     def tearDown(self):
         PlacelessSetup.tearDown(self)
         module.test_class = None
@@ -82,7 +90,8 @@
         self.assertEqual(checker.permission_id('m3'), (m3P or None))
 
     def assertDeclaration(self, declaration, **state):
-        apply_declaration(module.template_bracket % declaration)
+        apply_declaration(module.template_bracket % declaration,
+                          self._context)
         self.assertState(**state)
 
     # "testSimple*" exercises tags that do NOT have children.  This mode
@@ -117,7 +126,7 @@
                                 set_attributes="m1 m3"/>
                           </content>"""
                        % (PREFIX+"test_class", P1))
-        apply_declaration(module.template_bracket % declaration)
+        apply_declaration(module.template_bracket % declaration, self._context)
         checker = selectChecker(module.test_instance)
         self.assertEqual(checker.setattr_permission_id('m1'), P1)
         self.assertEqual(checker.setattr_permission_id('m2'), None)
@@ -133,7 +142,7 @@
                                 set_schema="%s"/>
                           </content>"""
                        % (PREFIX+"test_class", P1, PREFIX+"S"))
-        apply_declaration(module.template_bracket % declaration)
+        apply_declaration(module.template_bracket % declaration, self._context)
 
         self.assertEqual(queryInterface(PREFIX+"S"), module.S)
 
@@ -157,7 +166,7 @@
                                 set_schema="%s %s"/>
                           </content>"""
                        % (PREFIX+"test_class", P1, PREFIX+"S", PREFIX+"S2"))
-        apply_declaration(module.template_bracket % declaration)
+        apply_declaration(module.template_bracket % declaration, self._context)
 
         self.assertEqual(queryInterface(PREFIX+"S"), module.S)
         self.assertEqual(queryInterface(PREFIX+"S2"), module.S2)
@@ -293,9 +302,9 @@
                                m1P=P1, m2P=P2, m3P=P2)
 
 
-def apply_declaration(declaration):
+def apply_declaration(declaration, context):
     """Apply the xmlconfig machinery."""
-    return xmlconfig(StringIO(declaration))
+    return xmlconfig.string(declaration, context=context)
 
 def test_suite():
     loader=unittest.TestLoader()


=== Zope3/src/zope/app/component/tests/test_servicedirective.py 1.10 => 1.10.2.1 ===
--- Zope3/src/zope/app/component/tests/test_servicedirective.py:1.10	Sun Aug  3 13:50:15 2003
+++ Zope3/src/zope/app/component/tests/test_servicedirective.py	Wed Aug  6 10:27:40 2003
@@ -13,17 +13,19 @@
 ##############################################################################
 
 import unittest
-from cStringIO import StringIO
 
 from zope.exceptions import Forbidden, Unauthorized
-
-from zope.configuration.xmlconfig import testxmlconfig as xmlconfig, XMLConfig
-from zope.configuration.config import ConfigurationConflictError
-from zope.security.proxy import ProxyFactory
+from zope.component import getService
 from zope.component.exceptions import ComponentLookupError
+from zope.security.proxy import ProxyFactory
+from zope.configuration import xmlconfig
+from zope.configuration.config import ConfigurationExecutionError, \
+     ConfigurationConflictError
 
 import zope.app.component
-from zope.component import getService
+import zope.app.component.service
+import zope.app.configuration
+
 from zope.app.tests.placelesssetup import PlacelessSetup
 
 template = """<configure
@@ -35,34 +37,30 @@
 
 class Test(PlacelessSetup, unittest.TestCase):
 
-    # XXX: tests for other directives needed
-
     def setUp(self):
         PlacelessSetup.setUp(self)
-        XMLConfig('meta.zcml', zope.app.component)()
+        self._config()
+
+    def _config(self):
+        sm = zope.app.component.service.globalServiceManager()
+        context = zope.app.configuration.ConfigurationMachine(sm)
+        xmlconfig.registerCommonDirectives(context)
+        xmlconfig.file('meta.zcml', package=zope.app.component,
+                       context=context)
+        self._context = context
 
     def testServiceConfigNoType(self):
-        from zope.component.service \
-             import UndefinedService
-        self.assertRaises(
-            UndefinedService,
-            xmlconfig,
-            StringIO(template % (
-            """
+        self.assertRaises(ConfigurationExecutionError, xmlconfig.string,
+                          template % """
             <service
               serviceType="Foo"
               component="
               zope.app.component.tests.service.fooService"
-              />
-            """
-            )))
+              />""", context=self._context)
 
     def testDuplicateServiceConfig(self):
-        self.assertRaises(
-            ConfigurationConflictError,
-            xmlconfig,
-            StringIO(template % (
-            """
+        self.assertRaises(ConfigurationConflictError,
+            xmlconfig.string, template % """
             <serviceType id="Foo"
                          interface="
                zope.app.component.tests.service.IFooService"
@@ -76,15 +74,12 @@
               serviceType="Foo"
               component="
               zope.app.component.tests.service.foo2"
-              />
-            """
-            )))
+              />""", context=self._context)
 
     def testServiceConfig(self):
         self.assertRaises(ComponentLookupError, getService, None, "Foo")
 
-        xmlconfig(StringIO(template % (
-            """
+        xmlconfig.string(template % """
             <serviceType id="Foo"
                          interface="
                zope.app.component.tests.service.IFooService"
@@ -93,9 +88,7 @@
               serviceType="Foo"
               component="
               zope.app.component.tests.service.fooService"
-              />
-            """
-            )))
+              />""", context=self._context)
 
         service = getService(None, "Foo")
         self.assertEqual(service.foo(), "foo here")
@@ -105,8 +98,7 @@
     def testServiceFactoryConfig(self):
         self.assertRaises(ComponentLookupError, getService, None, "Foo")
 
-        xmlconfig(StringIO(template % (
-            """
+        xmlconfig.string(template % """
             <serviceType id="Foo"
                          interface="
                zope.app.component.tests.service.IFooService"
@@ -115,9 +107,7 @@
               serviceType="Foo"
               factory="
               zope.app.component.tests.service.FooService"
-              />
-            """
-            )))
+              />""", context=self._context)
 
         service = getService(None, "Foo")
         self.assertEqual(service.foo(), "foo here")
@@ -127,8 +117,7 @@
     def testPublicProtectedServiceConfig(self):
         self.assertRaises(ComponentLookupError, getService, None, "Foo")
 
-        xmlconfig(StringIO(template % (
-            """
+        xmlconfig.string(template % """
             <serviceType id="Foo"
                          interface="
                zope.app.component.tests.service.IFooService"
@@ -138,9 +127,7 @@
               component="
               zope.app.component.tests.service.fooService"
               permission="zope.Public"
-              />
-            """
-            )))
+              />""", context=self._context)
 
         service = getService(None, "Foo")
         service = ProxyFactory(service) # simulate untrusted code!
@@ -151,8 +138,7 @@
     def testProtectedServiceConfig(self):
         self.assertRaises(ComponentLookupError, getService, None, "Foo")
 
-        xmlconfig(StringIO(template % (
-            """
+        xmlconfig.string(template % """
             <directives namespace="http://namespaces.zope.org/zope">
               <directive name="permission"
                  attributes="id title description"
@@ -171,10 +157,7 @@
               component="
               zope.app.component.tests.service.fooService"
               permission="zope.TestPermission"
-              />
-            """
-            )))
-
+              />""", context=self._context)
 
         # Need to "log someone in" to turn on checks
         from zope.security.management import newSecurityManager
@@ -186,8 +169,6 @@
         self.assertRaises(Unauthorized, getattr, service, 'foo')
         self.assertRaises(Unauthorized, getattr, service, 'foobar')
         self.assertRaises(Forbidden, getattr, service, 'bar')
-
-
 
 def test_suite():
     loader=unittest.TestLoader()




More information about the Zope3-Checkins mailing list