[Zope3-checkins] CVS: Zope3/lib/python/Zope/Configuration/tests - BaseTestDirectivesXML.py:1.2 testMetameta.py:1.2 testMetametaForDocgen.py:1.2 Directives.py:1.5 testDirectivesXML.py:1.5

R. David Murray bitz@bitdance.com
Wed, 6 Nov 2002 17:30:53 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Configuration/tests
In directory cvs.zope.org:/tmp/cvs-serv10913/lib/python/Zope/Configuration/tests

Modified Files:
	Directives.py testDirectivesXML.py 
Added Files:
	BaseTestDirectivesXML.py testMetameta.py 
	testMetametaForDocgen.py 
Log Message:
Merge of rdmurray-metameta-branch.  See checkin message for 
doc/zcml/meta.stx for a more comprehensive checkin comment.


=== Zope3/lib/python/Zope/Configuration/tests/BaseTestDirectivesXML.py 1.1 => 1.2 ===
--- /dev/null	Wed Nov  6 17:30:53 2002
+++ Zope3/lib/python/Zope/Configuration/tests/BaseTestDirectivesXML.py	Wed Nov  6 17:30:22 2002
@@ -0,0 +1,153 @@
+"""Tests of the XML parsing machinery
+
+This mixin passes a series of sets of configuration directives
+to xmlconfig to make sure the right things happen.  The
+directives first define one or or more new directives, implemented
+by code in the Directives.py module, and then use those
+directives.  The tests check to make sure the expected actions
+were taken, or the expected errors raised.
+
+These tests test only the capabilities of the meta-directives
+implemented by the bootstrap versions.
+"""
+
+from cStringIO import StringIO
+from Zope.Configuration.meta import InvalidDirective
+from Zope.Configuration.xmlconfig import xmlconfig, testxmlconfig
+from Zope.Configuration.tests.Directives import protections, done
+
+ns = 'http://www.zope.org/NS/Zope3/test'
+
+def makeconfig(metadirectives,directives):
+    return StringIO(
+        '''<zopeConfigure
+               xmlns="http://namespaces.zope.org/zope"
+               xmlns:test="%(ns)s">
+            <directives namespace="%(ns)s">
+              %(metadirectives)s
+            </directives>
+            %(directives)s
+            </zopeConfigure>''' % {
+                'metadirectives': metadirectives,
+                'directives': directives,
+                'ns': ns})
+
+
+class directiveTests:
+
+    def testDirective(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="doit"
+                   handler="Zope.Configuration.tests.Directives.doit" />''',
+            '''<test:doit name="splat" />'''
+            ))
+        self.assertEqual(done, ['splat'])
+        
+    def testSimpleComplexDirective(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="protectClass"
+                   handler="Zope.Configuration.tests.Directives.protectClass">
+                 <subdirective name="protect" namespace="%s" />
+               </directive>''',
+            '''<test:protectClass
+                   name=".Contact" permission="splat" names="update" />'''
+            ))
+        self.assertEquals(protections, [(".Contact", "splat", 'update')])
+        
+    def testComplexDirective(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="protectClass"
+                   handler="Zope.Configuration.tests.Directives.protectClass">
+                 <subdirective name="protect" />
+               </directive>''',
+            '''<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 testSubSubdirective(self):
+        xmlconfig(makeconfig(
+            '''<directive name="protectClass"
+                   handler="Zope.Configuration.tests.Directives.protectClass">
+                 <subdirective name="subsub">
+                   <subdirective name="subsub">
+                     <subdirective name="subsub">
+                       <subdirective name="subsub">
+                         <subdirective name="protect"/>
+                       </subdirective>
+                     </subdirective>
+                   </subdirective>
+                 </subdirective>
+               </directive>''',
+            '''<test:protectClass
+                   name=".Contact" permission="splat" names="update"
+               >
+                 <test:subsub>
+                   <test:subsub>
+                     <test:subsub>
+                       <test:subsub> 
+                         <test:protect permission="beep" names="update" />
+                       </test:subsub>
+                     </test:subsub>
+                   </test:subsub>
+                 </test:subsub>
+               </test:protectClass>'''
+            ))
+        self.assertEquals(protections, [(".Contact", "beep", 'update')])
+
+    def testHandlerMethod(self):
+        xmlconfig(makeconfig(
+            '''<directive name="protectClass"
+                   handler="Zope.Configuration.tests.Directives.protectClass">
+                 <subdirective
+                     name="fish"
+                     handler_method="protect" />
+               </directive>''',
+            '''<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,
+            testxmlconfig,
+            makeconfig(
+              '''<directive
+                     name="protectClass"
+                     handler="Zope.Configuration.tests.Directives.protectClass">
+                   <subdirective name="protect" namespace="%s" />
+                 </directive>''',
+              '''<test:protectClass name=".Contact">
+                 <test:protect permission="edit" names='update' />
+                 <protect permission="view" names='name email' />
+                 </test:protectClass>
+              '''))
+        
+    def testBadPrefixComplexDirective(self):
+        try: testxmlconfig(makeconfig(
+            '''<directive
+                   name="protectClass"
+                   handler="Zope.Configuration.tests.Directives.protectClass">
+                 <subdirective name="protect" namespace="%s" />
+               </directive>''',
+            '''<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 InvalidDirective')


=== Zope3/lib/python/Zope/Configuration/tests/testMetameta.py 1.1 => 1.2 ===
--- /dev/null	Wed Nov  6 17:30:53 2002
+++ Zope3/lib/python/Zope/Configuration/tests/testMetameta.py	Wed Nov  6 17:30:22 2002
@@ -0,0 +1,89 @@
+##############################################################################
+#
+# 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 Zope.Testing.CleanUp import CleanUp
+from Zope.Configuration.xmlconfig import xmlconfig, testxmlconfig, XMLConfig
+from Zope.Configuration.tests.Directives import done
+from Zope.Configuration.tests.BaseTestDirectivesXML import directiveTests
+from Zope.Configuration.tests.BaseTestDirectivesXML import makeconfig
+import Zope.Configuration
+
+class Test(CleanUp, unittest.TestCase, directiveTests):
+
+    def setUp(self):
+        XMLConfig('metameta.zcml', Zope.Configuration)()
+
+
+    def testDescription(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="doit"
+                   description="Something to Do"
+                   handler="Zope.Configuration.tests.Directives.doit" />''',
+            '''<test:doit name="splat" />'''
+            ))
+        self.assertEqual(done, ['splat'])
+
+    def testAttribute(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="doit"
+                   handler="Zope.Configuration.tests.Directives.doit"
+                   description="Something to Do"
+               >
+                 <attribute
+                     name="name"
+                     required="yes"
+                     description="Just Do It" />
+               </directive>''',
+            '''<test:doit name="splat" />'''
+            ))
+        self.assertEqual(done, ['splat'])
+
+    def testBadRequired(self):
+        self.assertRaises(
+            ValueError,
+            testxmlconfig,
+            makeconfig(
+                '''<directive
+                       name="doit"
+                       handler="Zope.Configuration.tests.Directives.doit"
+                   >
+                     <attribute
+                         name="name"
+                         required="badvalue"
+                         description="Just Do It" />
+                   </directive>''',
+                '''<test:doit name="splat" />'''
+                ))
+        
+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/testMetametaForDocgen.py 1.1 => 1.2 ===
--- /dev/null	Wed Nov  6 17:30:53 2002
+++ Zope3/lib/python/Zope/Configuration/tests/testMetametaForDocgen.py	Wed Nov  6 17:30:22 2002
@@ -0,0 +1,109 @@
+##############################################################################
+#
+# 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 Zope.Testing.CleanUp import CleanUp
+from Zope.Configuration.xmlconfig import xmlconfig, testxmlconfig, XMLConfig
+from Zope.Configuration.meta import _directives
+from Zope.Configuration.metametaConfigureForDocgen import _metadataKey
+from Zope.Configuration.tests.Directives import done
+from Zope.Configuration.tests.BaseTestDirectivesXML import directiveTests
+from Zope.Configuration.tests.BaseTestDirectivesXML import makeconfig, ns
+import Zope.Configuration
+
+class Test(CleanUp, unittest.TestCase, directiveTests):
+
+    def setUp(self):
+        XMLConfig('metameta.zcml', Zope.Configuration)()
+        XMLConfig('metametaForDocgen.zcml', Zope.Configuration)()
+
+
+    def testDescription(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="doit"
+                   description="Just Do It"
+                   handler="Zope.Configuration.tests.Directives.doit" />''',
+            '''<test:doit name="splat" />'''
+            ))
+        self.assertEqual(done, ['splat'])
+        md = _directives[(ns, 'doit')][1][_metadataKey]
+        self.assertEqual(md['description'], "Just Do It")
+
+    def testAttribute(self):
+        xmlconfig(makeconfig(
+            '''<directive
+                   name="doit"
+                   handler="Zope.Configuration.tests.Directives.doit"
+               >
+                 <attribute
+                     name="name"
+                     required="Yes"
+                     description="Just Do It" />
+                 <attribute
+                     name="opt1"
+                     required="no"
+                     description="ho hum" />
+                 <attribute
+                     name="opt2"
+                     description="ho hummer" />
+               </directive>''',
+            '''<test:doit name="splat" />'''
+            ))
+        self.assertEqual(done, ['splat'])
+        md = _directives[(ns, 'doit')][1][_metadataKey]['attributes']['name']
+        self.assertEqual(md['description'],'Just Do It')
+        self.assertEqual(md['required'],'yes')
+        md = _directives[(ns, 'doit')][1][_metadataKey]['attributes']['opt1']
+        self.assertEqual(md['description'],'ho hum')
+        self.assertEqual(md['required'],'no')
+        md = _directives[(ns, 'doit')][1][_metadataKey]['attributes']['opt2']
+        self.assertEqual(md['description'],'ho hummer')
+        self.assertEqual(md['required'],'')
+
+    def testBadRequired(self):
+        self.assertRaises(
+            ValueError,
+            testxmlconfig,
+            makeconfig(
+                '''<directive
+                       name="doit"
+                       handler="Zope.Configuration.tests.Directives.doit"
+                   >
+                     <attribute
+                         name="name"
+                         required="badvalue"
+                         description="Just Do It" />
+                   </directive>''',
+                '''<test:doit name="splat" />'''
+                ))
+        
+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/Directives.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/Configuration/tests/Directives.py:1.4	Sun Sep 22 12:05:18 2002
+++ Zope3/lib/python/Zope/Configuration/tests/Directives.py	Wed Nov  6 17:30:22 2002
@@ -18,12 +18,14 @@
 """
 
 from Zope.Configuration.INonEmptyDirective import INonEmptyDirective
+from Zope.Configuration.ISubdirectiveHandler import ISubdirectiveHandler
 
 protections=[]
 
 class protectClass:
 
-    __implements__ = INonEmptyDirective
+    __class_implements__ = INonEmptyDirective
+    __implements__ = ISubdirectiveHandler
 
     def __init__(self, _context, name, permission=None, names=None):
         self._name=name
@@ -55,6 +57,7 @@
         #If you put a protect inside a subsub, that'll set children,
         #so when the parser calls us, __call__ will return ().
         return self
+    subsub.__implements__ = INonEmptyDirective
 
 done = []
 


=== Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py:1.4	Sun Sep 22 14:43:40 2002
+++ Zope3/lib/python/Zope/Configuration/tests/testDirectivesXML.py	Wed Nov  6 17:30:22 2002
@@ -12,186 +12,11 @@
 # 
 ##############################################################################
 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
+from Zope.Configuration.tests.BaseTestDirectivesXML import directiveTests
+from Zope.Testing.CleanUp import 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 % (
-            '''<directives  namespace="%s">
-                   <directive name="doit"
-                    handler="Zope.Configuration.tests.Directives.doit" />
-               </directives>''' % ns,
-            '<test:doit name="splat" />'
-            )))
-
-        self.assertEqual(done, ['splat'])
-        
-    def testSimpleComplexDirective(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"
-               >
-                 <test:protect permission="beep" names="update" />
-               </test:protectClass>'''
-            )))
-        
-        self.assertEquals(protections, [(".Contact", "beep", 'update')])
-
-    def testDirectiveDirective(self):
-        xmlconfig(StringIO(
-            template % (
-            '''<directive name="protectClass" namespace="%s"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                       <subdirective name="protect"/>
-               </directive>
-                          ''' % ns,
-            '''<test:protectClass
-                   name=".Contact" permission="splat" names="update"
-               >
-                 <test:protect permission="beep" names="update" />
-               </test:protectClass>'''
-            )))
-
-        self.assertEquals(protections, [(".Contact", "beep", '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 testSubSubdirective(self):
-        xmlconfig(StringIO(
-            template % (
-            '''<directives  namespace="%s">
-                 <directive name="protectClass"
-                    handler="Zope.Configuration.tests.Directives.protectClass">
-                       <subdirective name="subsub">
-                         <subdirective name="subsub">
-                           <subdirective name="protect"/>
-                         </subdirective>
-                       </subdirective>
-                 </directive>
-               </directives>
-                          ''' % ns,
-            '''<test:protectClass
-                   name=".Contact" permission="splat" names="update"
-               >
-                 <test:subsub>
-                   <test:subsub>
-                     <test:protect permission="beep" names="update" />
-                   </test:subsub>
-                 </test:subsub>
-               </test:protectClass>'''
-            )))
+class Test(CleanUp, unittest.TestCase, directiveTests): pass
         
-        self.assertEquals(protections, [(".Contact", "beep", 'update')])
-
-    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)