[Zope-Checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - Directives.py:1.2 __init__.py:1.2 hookTestDummyModule.py:1.2 testDirectivesXML.py:1.2 testHookRegistry.py:1.2 testMeta.py:1.2 testMultipleXML.py:1.2 testNames.py:1.2 testXML.py:1.2
Jim Fulton
jim@zope.com
Mon, 10 Jun 2002 19:29:55 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv20468/lib/python/Zope/Configuration/tests
Added Files:
Directives.py __init__.py hookTestDummyModule.py
testDirectivesXML.py testHookRegistry.py testMeta.py
testMultipleXML.py testNames.py testXML.py
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.
=== Zope3/lib/python/Zope/Configuration/tests/Directives.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+Test class for use by test modules
+
+$Id$
+"""
+
+from Zope.Configuration.ConfigurationDirectiveInterfaces \
+ import INonEmptyDirective
+
+protections=[]
+
+class protectClass:
+
+ __implements__ = INonEmptyDirective
+
+ def __init__(self, _context, name, permission=None, names=None):
+ self._name=name
+ self._permission=permission
+ self._names=names
+ self._children=[]
+ self.__context = _context
+
+ def __call__(self):
+ if not self._children:
+ p = self._name, self._permission, self._names
+ d = self._name, self._names
+ return [(d, protections.append, (p,))]
+ else:
+ return ()
+
+ def protect(self, _context, permission=None, names=None):
+ if permission is None: permission=self._permission
+ if permission is None: raise 'no perm'
+ p=self._name, permission, names
+ d=self._name, names
+ self._children.append(p)
+ return [(d, protections.append, (p,))]
+
+done = []
+
+def doit(_context, name):
+ return [('d', done.append, (name,))]
+
+def clearDirectives():
+ del protections[:]
+ del done[:]
+
+# Register our cleanup with Testing.CleanUp to make writing unit tests simpler.
+from Zope.Testing.CleanUp import addCleanUp
+addCleanUp(clearDirectives)
+del addCleanUp
=== Zope3/lib/python/Zope/Configuration/tests/__init__.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+""" Configuration unit tests."""
+
+from hookTestDummyModule import dummyHookable as testImport
=== Zope3/lib/python/Zope/Configuration/tests/hookTestDummyModule.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Hook test dummy module
+
+$Id$
+"""
+
+def dummyHookable():
+ return dummyHookable_hook()
+
+def dummyHookable_hook():
+ return "original implementation"
+
+def associatedDummy():
+ return dummyHookable()
=== Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import sys, unittest
+from cStringIO import StringIO
+from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
+from Zope.Configuration.xmlconfig import testxmlconfig
+from Zope.Configuration.meta import InvalidDirective
+from Zope.Configuration.tests.Directives import protections, done
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:test='http://www.zope.org/NS/Zope3/test'>
+ %s
+ %s
+ </zopeConfigure>"""
+
+
+ns='http://www.zope.org/NS/Zope3/test'
+
+class Test(CleanUp, unittest.TestCase):
+
+ def xtestDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="doit"
+ handler="Zope.Configuration.tests.Directives.doit" />
+ </directives>''' % ns,
+ '<test:doit name="splat" />'
+ )))
+
+ self.assertEqual(done, ['splat'])
+
+ def xtestSimpleComplexDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="protectClass"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect"/>
+ </directive>
+ </directives>
+ ''' % ns,
+ '''<test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />'''
+ )))
+
+ self.assertEquals(protections, [(".Contact", "splat", 'update')])
+
+ def testComplexDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="protectClass"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" />
+ </directive>
+ </directives>''' % ns,
+ '''<test:protectClass name=".Contact">
+ <test:protect permission="edit" names='update' />
+ <test:protect permission="view" names='name email' />
+ </test:protectClass>'''
+ )))
+
+ self.assertEquals(protections, [
+ (".Contact", "edit", 'update'),
+ (".Contact", "view", 'name email'),
+ ])
+
+ def testHandlerMethod(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="protectClass"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="fish"
+ handler_method="protect" />
+ </directive>
+ </directives>''' % ns,
+ '''<test:protectClass name=".Contact">
+ <test:fish permission="edit" names='update' />
+ <test:fish permission="view" names='name email' />
+ </test:protectClass>'''
+ )))
+
+ self.assertEquals(protections, [
+ (".Contact", "edit", 'update'),
+ (".Contact", "view", 'name email'),
+ ])
+
+
+ def testBadNoPrefixComplexDirective(self):
+
+ self.assertRaises(
+ InvalidDirective,
+ xmlconfig,
+ StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="protectClass"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" />
+ </directive>
+ </directives>''' % ns,
+
+ '''<test:protectClass name=".Contact">
+ <test:protect permission="edit" names='update' />
+ <protect permission="view" names='name email' />
+ </test:protectClass>'''
+ )),
+ testing=1)
+
+ def testBadPrefixComplexDirective(self):
+
+ try:
+ testxmlconfig(
+ StringIO(
+ template % (
+ '''<directives namespace="%s">
+ <directive name="protectClass"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" />
+ </directive>
+ </directives>''' % ns,
+
+ '''<test:protectClass name=".Contact">
+ <test2:protect permission="edit" names='update' />
+ </test:protectClass>'''
+ )))
+ except InvalidDirective, v:
+ self.assertEqual(str(v), "(None, u'test2:protect')")
+ else:
+ self.fail('Should have raised ZopeXMLConfigurationError')
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+def run():
+ unittest.TextTestRunner().run(test_suite())
+
+def debug():
+ test_suite().debug()
+
+def pdb():
+ import pdb
+ pdb.run('debug()')
+
+if __name__=='__main__':
+ if len(sys.argv) < 2:
+ run()
+ else:
+ globals()[sys.argv[1]]()
=== Zope3/lib/python/Zope/Configuration/tests/testHookRegistry.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, sys
+
+def dummyHook():
+ return "hooked implementation"
+
+class HookRegistryTest(unittest.TestCase):
+
+# def setUp(self):
+#
+# from Zope.Configuration.tests import Products_
+# self.old=sys.modules.get('ZopeProducts', None)
+# sys.modules['ZopeProducts']=Products_
+#
+# def tearDown(self):
+# old=self.old
+# if old is None: del sys.modules['ZopeProducts']
+# else: sys.modules['ZopeProducts']=self.old
+
+ def testAddHookable(self):
+ from Zope.Configuration.HookRegistry import HookRegistry
+
+ hookableAddr='Zope.Configuration.tests.hookTestDummyModule.dummyHookable'
+
+ hookRegistry=HookRegistry()
+ hookRegistry.addHookable(hookableAddr)
+ hookables=hookRegistry.getHookables()
+ self.assertEquals(len(hookables), 1)
+ self.assertEquals(hookables[0][0], hookableAddr)
+ self.assertEquals(hookables[0][1],0)
+
+ def testAddDuplicateHookable(self):
+ from Zope.Configuration.HookRegistry import HookRegistry
+ from Zope.Exceptions import DuplicationError
+
+ hookableAddr='Zope.Configuration.tests.hookTestDummyModule.dummyHookable'
+ hookRegistry=HookRegistry()
+ hookRegistry.addHookable(hookableAddr)
+ self.assertRaises(DuplicationError, hookRegistry.addHookable,
+ hookableAddr)
+
+ def testAddInvalidHookable(self):
+ from Zope.Configuration.HookRegistry import HookRegistry, \
+ BadHookableError
+ hookRegistry=HookRegistry()
+ self.assertRaises(BadHookableError, hookRegistry.addHookable,
+ 'foo.bar.this.should.not.resolve.anywhere')
+ self.assertRaises(BadHookableError, hookRegistry.addHookable,
+ 'Zope')
+ self.assertRaises(BadHookableError, hookRegistry.addHookable,
+ 'Zope.Configuration.HookRegistry.HookRegistry.addHookable')
+
+ def testAddHook(self):
+ from Zope.Configuration.HookRegistry import \
+ HookRegistry, BadHookError, DuplicateHookError, \
+ MissingHookableError
+ from Zope.Configuration.tests.hookTestDummyModule import associatedDummy
+ hookableParent='Zope.Configuration.tests.hookTestDummyModule'
+ hookableLast='dummyHookable'
+ hookableAddr='%s.%s' % (hookableParent, hookableLast)
+ old=__import__(hookableParent,{},{}, ('__dict__',)) # for cleanup
+ old=getattr(old, hookableLast)
+ self.assertEquals(old(),"original implementation")
+
+ hookRegistry=HookRegistry()
+ hookRegistry.addHookable(hookableAddr)
+ self.assertRaises(BadHookError, hookRegistry.addHook,
+ hookableAddr, 'foo.bar.this.should.not.resolve.anywhere')
+ hookRegistry.addHook(hookableAddr,
+ 'Zope.Configuration.tests.testHookRegistry.dummyHook')
+ new=__import__(hookableParent,{},{}, ('__dict__',))
+ new=getattr(new, hookableLast)
+ self.assertEquals(new(), "hooked implementation")
+ self.assertEquals(associatedDummy(), "hooked implementation")
+ from Zope.Configuration.tests.hookTestDummyModule import associatedDummy as associatedDummyAgain
+ self.assertEquals(associatedDummyAgain(), "hooked implementation")
+ self.assertRaises(DuplicateHookError, hookRegistry.addHook,
+ hookableAddr, 'Zope.Configuration.tests.testHookRegistry.test_suite')
+ self.assertRaises(MissingHookableError, hookRegistry.addHook,
+ 'Zope.Configuration.tests.testHookRegistry.test_suite',
+ 'Zope.Configuration.tests.testHookRegistry.dummyHook')
+
+ setattr(__import__(hookableParent,{},{}, ('__dict__',)), hookableLast, old) # cleanup
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(HookRegistryTest)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Configuration/tests/testMeta.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest
+from Zope.Configuration.tests.Directives \
+ import protectClass, protections, doit, done
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+from Zope.Configuration import name
+
+ns='http://www.zope.org/NS/Zope3/test'
+
+class MetaTest(CleanUp, unittest.TestCase):
+
+ def testImport(self):
+ import Zope.Configuration.meta
+
+ def testDirective(self):
+ from Zope.Configuration.meta \
+ import register, registersub, begin, end, InvalidDirective
+
+ self.assertRaises(InvalidDirective, begin, None, name, (ns, 'doit'))
+
+ register((ns, 'doit'), doit)
+
+ subs = begin(None, (ns, 'doit'), name, name='splat')
+ (des, callable, args, kw), = end(subs)
+ self.assertEqual(des, 'd')
+ callable(*args)
+
+ self.failUnless(done==['splat'])
+
+ def testSimpleComplexDirective(self):
+ from Zope.Configuration.meta \
+ import register, registersub, begin, end, InvalidDirective
+
+ subs = register((ns, 'protectClass'), protectClass)
+ registersub(subs, (ns, 'protect'))
+
+ subs=begin(None, (ns, 'protectClass'), name,
+ name=".Contact", permission="splat", names='update')
+
+ (des, callable, args, kw), = end(subs)
+ self.assertEqual(des, ('.Contact', 'update'))
+ callable(*args)
+
+ self.assertEquals(protections, [(".Contact", "splat", 'update')])
+
+ def testComplexDirective(self):
+ from Zope.Configuration.meta \
+ import register, registersub, begin, sub, end, InvalidDirective
+
+ subs = register((ns, 'protectClass'), protectClass)
+ registersub(subs, (ns, 'protect'))
+
+ subs = begin(None, (ns, 'protectClass'), name, name=".Contact")
+
+ actions = end(sub(subs, (ns, 'protect'), name,
+ permission='edit', names='update'))
+ (des, callable, args, kw), = actions
+ self.assertEqual(des, ('.Contact', 'update'))
+ callable(*args)
+
+ actions = end(sub(subs, (ns, 'protect'), name,
+ permission='view', names='name email'))
+ (des, callable, args, kw), = actions
+ self.assertEqual(des, ('.Contact', 'name email'))
+ callable(*args)
+
+ self.assertEqual(tuple(end(subs)), ())
+
+ self.assertEquals(protections, [
+ (".Contact", "edit", 'update'),
+ (".Contact", "view", 'name email'),
+ ])
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(MetaTest)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Configuration/tests/testMultipleXML.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest, sys, os
+from tempfile import mktemp
+from Zope.Configuration.tests.Directives import protections, done
+from Zope.Configuration.xmlconfig import XMLConfig
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:test='http://www.zope.org/NS/Zope3/test'>
+ %s
+ %s
+ </zopeConfigure>"""
+
+ns='http://www.zope.org/NS/Zope3/test'
+
+
+class Test(CleanUp, unittest.TestCase):
+
+ def testNormal(self):
+ f2=tfile(template % ('',
+ '''
+ <test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />
+ <test:protectClass
+ name=".Contact" permission="splat" names="update2"
+ />
+ '''), 'f2')
+
+ f1=tfile(template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>''' % (ns, ns),
+ '''
+ <test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />
+ <include file="%s"/>
+ ''' % f2), 'f1')
+
+ XMLConfig(str(f1))()
+
+ self.assertEquals(protections, [
+ (".Contact", "splat", 'update'),
+ (".Contact", "splat", 'update2'),
+ ])
+
+ def testConflicting(self):
+ f2=tfile(template % ('',
+ '''
+ <test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />
+ <test:protectClass
+ name=".Contact" permission="splat" names="update2"
+ />
+ '''), 'f2')
+ f3=tfile(template % ('',
+ '''
+ <test:protectClass
+ name=".Contact" permission="splat" names="update2"
+ />
+ '''), 'f3')
+
+ f1=tfile(template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>''' % (ns, ns),
+ '''
+ <test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />
+ <include file="%s"/>
+ <include file="%s"/>
+ ''' % (f2, f3)), 'f1')
+
+ x=XMLConfig(str(f1))
+
+ from Zope.Configuration.xmlconfig import ZopeConfigurationConflictError
+
+ self.assertRaises(ZopeConfigurationConflictError, x)
+
+ self.assertEquals(protections, [])
+
+
+
+class tfile:
+
+ def __init__(self, string, suffix):
+ self.name = mktemp(suffix)
+ file = open(self.name, 'w')
+ file.write(string)
+ file.close()
+
+ def __str__(self): return self.name
+
+ def __del__(self): os.remove(self.name)
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Configuration/tests/testNames.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+
+import unittest, sys
+
+class NameTest(unittest.TestCase):
+
+ def setUp(self):
+
+ from Zope.Configuration.tests import Products_
+ self.old=sys.modules.get('ZopeProducts', None)
+ sys.modules['ZopeProducts']=Products_
+
+ def tearDown(self):
+ old=self.old
+ if old is None: del sys.modules['ZopeProducts']
+ else: sys.modules['ZopeProducts']=self.old
+
+ def testProductPath(self):
+ from Zope.Configuration.name import resolve
+
+ c=resolve('.Contact.')
+ self.assertEquals(c.n, 2)
+ c=resolve('ZopeProducts.Contact.Contact.Contact')
+ self.assertEquals(c.n, 2)
+
+ def testPackagePath(self):
+ from Zope.Configuration.name import resolve
+
+ c=resolve('Zope.Configuration.tests.Contact')
+ import Zope.Configuration.tests.Contact
+ self.assertEquals(c, Zope.Configuration.tests.Contact)
+
+ c=resolve('Zope.Configuration.tests.Contact.')
+ self.assertEquals(c.n, 1)
+ c=resolve('Zope.Configuration.tests.Contact.Contact.Contact')
+ self.assertEquals(c.n, 1)
+
+ def testNoDots(self):
+ from Zope.Configuration.name import resolve
+ import Zope
+ c=resolve('Zope')
+
+ self.assertEquals(id(c), id(Zope))
+
+ def testPackage(self):
+ from Zope.Configuration.name import resolve
+ c=resolve('Zope.App.ZMI')
+ import Zope.App.ZMI
+
+ self.assertEquals(id(c), id(Zope.App.ZMI))
+
+ nameSet={
+ ('Zope.Configuration.tests','Noplace'):'Zope.Configuration.tests',
+ ('Zope.Configuration.tests.tests','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests.','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests+','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.tests.tests+','Noplace'):'Zope.Configuration.tests+',
+ ('Zope.Configuration.tests.','Noplace'):'Zope.Configuration.tests+',
+ ('.tests','Zope.Configuration'):'Zope.Configuration.tests',
+ ('.tests.tests','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests.','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests+','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.tests.tests+','Zope.Configuration'):'Zope.Configuration.tests+',
+ ('.tests.','Zope.Configuration'):'Zope.Configuration.tests+'
+ }
+
+ def testNormalizedName(self):
+ from Zope.Configuration.name import getNormalizedName
+ for args in self.nameSet:
+ self.assertEquals(self.nameSet[args], getNormalizedName(*args))
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(NameTest)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
=== Zope3/lib/python/Zope/Configuration/tests/testXML.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import sys, unittest
+from cStringIO import StringIO
+from Zope.Configuration.xmlconfig import xmlconfig, ZopeXMLConfigurationError
+from Zope.Configuration.xmlconfig import testxmlconfig
+from Zope.Configuration.meta import InvalidDirective, BrokenDirective
+from Zope.Configuration.tests.Directives import protections, done
+from Zope.Testing.CleanUp import CleanUp # Base class w registry cleanup
+
+template = """<zopeConfigure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:test='http://www.zope.org/NS/Zope3/test'>
+ %s
+ %s
+ </zopeConfigure>"""
+
+
+ns='http://www.zope.org/NS/Zope3/test'
+
+class Test(CleanUp, unittest.TestCase):
+
+ def testDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directive name="doit" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.doit" />
+ ''' % ns,
+ '<test:doit name="splat" />'
+ )))
+
+ self.assertEqual(done, ['splat'])
+
+ def testSimpleComplexDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>
+ ''' % (ns, ns),
+ '''<test:protectClass
+ name=".Contact" permission="splat" names="update"
+ />'''
+ )))
+
+ self.assertEquals(protections, [(".Contact", "splat", 'update')])
+
+ def testComplexDirective(self):
+ xmlconfig(StringIO(
+ template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>
+ ''' % (ns, ns),
+ '''<test:protectClass name=".Contact">
+ <test:protect permission="edit" names='update' />
+ <test:protect permission="view" names='name email' />
+ </test:protectClass>'''
+ )))
+
+ self.assertEquals(protections, [
+ (".Contact", "edit", 'update'),
+ (".Contact", "view", 'name email'),
+ ])
+
+ def testBadNoPrefixComplexDirective(self):
+
+ self.assertRaises(
+ InvalidDirective,
+ testxmlconfig,
+ StringIO(
+ template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>
+ ''' % (ns, ns),
+
+ '''<test:protectClass name=".Contact">
+ <test:protect permission="edit" names='update' />
+ <protect permission="view" names='name email' />
+ </test:protectClass>'''
+ )))
+
+ def testBadPrefixComplexDirective(self):
+
+ try:
+ testxmlconfig(
+ StringIO(
+ template % (
+ '''<directive name="protectClass" namespace="%s"
+ handler="Zope.Configuration.tests.Directives.protectClass">
+ <subdirective name="protect" namespace="%s" />
+ </directive>
+ ''' % (ns, ns),
+
+ '''<test:protectClass name=".Contact">
+ <test2:protect permission="edit" names='update' />
+ </test:protectClass>'''
+ )))
+ except InvalidDirective, v:
+ self.assertEqual(str(v), "(None, u'test2:protect')")
+ else:
+ self.fail('Should have raised ZopeXMLConfigurationError')
+
+
+ def testInclude(self):
+ from tempfile import mktemp
+ name = mktemp()
+ open(name, 'w').write(
+ """<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
+ <include package="Zope.Configuration.tests.Contact"
+ file="contact.zcml" />
+ </zopeConfigure>""")
+
+ from Zope.Configuration.xmlconfig import XMLConfig
+ x=XMLConfig(name)
+ x()
+
+
+def test_suite():
+ loader=unittest.TestLoader()
+ return loader.loadTestsFromTestCase(Test)
+
+def run():
+ unittest.TextTestRunner().run(test_suite())
+
+def debug():
+ test_suite().debug()
+
+def pdb():
+ import pdb
+ pdb.run('debug()')
+
+if __name__=='__main__':
+ if len(sys.argv) < 2:
+ run()
+ else:
+ globals()[sys.argv[1]]()