[Zope3-checkins] CVS: Zope3/src/zope/app/schema/tests - keywords_vocab.zcml:1.1 simple_vocab.zcml:1.1 test_directives.py:1.1 test_vocabulary.py:1.4

Stephan Richter srichter@cosmos.phy.tufts.edu
Fri, 1 Aug 2003 17:48:46 -0400


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

Modified Files:
	test_vocabulary.py 
Added Files:
	keywords_vocab.zcml simple_vocab.zcml test_directives.py 
Log Message:
Converted vocabulary directive to new Configuration mechanism.


=== Added File Zope3/src/zope/app/schema/tests/keywords_vocab.zcml ===
<configure xmlns="http://namespaces.zope.org/zope">

  <include package="zope.app.schema" file="meta.zcml"/>

  <vocabulary
      name="my-vocab"
      factory="zope.app.schema.tests.test_vocabulary.MyFactory"
      filter="my-filter"
      another="keyword"/>

</configure>


=== Added File Zope3/src/zope/app/schema/tests/simple_vocab.zcml ===
<configure xmlns="http://namespaces.zope.org/zope">

  <include package="zope.app.schema" file="meta.zcml"/>

  <vocabulary
      name="my-vocab"
      factory="zope.app.schema.tests.test_vocabulary.MyFactory" />

</configure>


=== Added File Zope3/src/zope/app/schema/tests/test_directives.py ===
##############################################################################
#
# 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.
#
##############################################################################
"""Testing vocabulary directive.

$Id: test_directives.py,v 1.1 2003/08/01 21:48:38 srichter Exp $
"""
import unittest

from zope.interface import Interface, implements
from zope.component.tests.placelesssetup import PlacelessSetup
from zope.configuration import xmlconfig
from zope.app.schema import vocabulary

import zope.app.schema


class DirectivesTest(PlacelessSetup, unittest.TestCase):

    extra_keywords = {"filter": "my-filter",
                      "another": "keyword"}

    def check_vocabulary_get(self, kw={}):
        context = object()
        vocab = vocabulary.vocabularyService.get(context, "my-vocab")
        self.assert_(vocab.ob is context)
        self.assertEqual(vocab.kw, kw)

    def test_simple_zcml(self):
        self.context = xmlconfig.file("tests/simple_vocab.zcml",
                                      zope.app.schema)
        self.check_vocabulary_get()

    def test_passing_keywords_from_zcml(self):
        self.context = xmlconfig.file("tests/keywords_vocab.zcml",
                                      zope.app.schema)
        self.check_vocabulary_get(self.extra_keywords)


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(DirectivesTest),
        ))

if __name__ == '__main__':
    unittest.main()


=== Zope3/src/zope/app/schema/tests/test_vocabulary.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/schema/tests/test_vocabulary.py:1.3	Mon Jul 28 18:20:34 2003
+++ Zope3/src/zope/app/schema/tests/test_vocabulary.py	Fri Aug  1 17:48:38 2003
@@ -11,20 +11,28 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Unit tests for the global vocabulary service and ZCML integration.
 
-"""Unit tests for the global vocabulary service and ZCML integration."""
-
+$Id$
+"""
 import unittest
-
+from zope.app.schema.metaconfigure import \
+     vocabulary as register, FactoryKeywordPasser
 from zope.app.schema import vocabulary
 from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.configuration import xmlconfig
 
 
 class MyContext:
     def resolve(self, name):
         return MyFactory
 
+    def action(self, discriminator=None, callable=None, args=None, kw=None):
+        self.discriminator = discriminator
+        self.callable = callable
+        self.args = args or ()
+        self.kw = kw or {}
+        
+
 class MyFactory:
     def __init__(self, context, **kw):
         self.ob = context
@@ -38,80 +46,49 @@
                           vocabulary.vocabularyService.get,
                           None, "missing-vocabulary")
 
+
     def check_vocabulary_get(self, kw={}):
         context = object()
         vocab = vocabulary.vocabularyService.get(context, "my-vocab")
         self.assert_(vocab.ob is context)
         self.assertEqual(vocab.kw, kw)
 
-    def load_zcml(self, fragment):
-        xmlconfig.string("""\
-        <zopeConfigure xmlns='http://namespaces.zope.org/zope'>
-          <include package='zope.configuration' file='meta.zcml' />
-          <include package='zope.app.component' file='meta.zcml' />
-          <include package='zope.app.schema' file='meta.zcml' />
-
-          <include package='zope.app.schema' />
-
-          %s
-        </zopeConfigure>
-        """ % fragment)
-
     extra_keywords = {"filter": "my-filter",
                       "another": "keyword"}
 
-    def test_simple_zcml(self):
-        self.load_zcml("""\
-          <vocabulary
-              name='my-vocab'
-              factory='zope.app.schema.tests.test_vocabulary.MyFactory'
-              />""")
-        self.check_vocabulary_get()
-
-    def test_passing_keywords_from_zcml(self):
-        self.load_zcml("""\
-          <vocabulary
-              name='my-vocab'
-              factory='zope.app.schema.tests.test_vocabulary.MyFactory'
-              filter='my-filter'
-              another='keyword'
-              />""")
-        self.check_vocabulary_get(self.extra_keywords)
-
     def test_action_without_keywords(self):
         # make sure the action machinery works, aside from ZCML concerns
-        actions = vocabulary.register(MyContext(), "my-vocab", ".maker")
-        self.assertEqual(len(actions), 1)
-        descriminator, callable, args, kw = actions[0]
+        context = MyContext()
+        register(context, "my-vocab", MyFactory)
         # check our expectations of the action:
-        self.assertEqual(len(args), 2)
-        self.assertEqual(args[0], "my-vocab")
-        self.assertEqual(kw, {})
-        self.failIf(isinstance(args[1], vocabulary.FactoryKeywordPasser))
-        # enact the registration:
-        callable(*args, **kw)
+        self.assertEqual(len(context.args), 2)
+        self.assertEqual(context.args[0], "my-vocab")
+        self.failIf(isinstance(context.args[1], FactoryKeywordPasser))
+        self.assertEqual(context.kw, {})
+        context.callable(*context.args, **context.kw)
         # make sure the factory behaves as expected:
         self.check_vocabulary_get()
 
     def test_action_with_keywords(self):
         # make sure the action machinery works, aside from ZCML concerns
-        actions = vocabulary.register(MyContext(), "my-vocab", ".maker",
-                                      **self.extra_keywords)
-        self.assertEqual(len(actions), 1)
-        descriminator, callable, args, kw = actions[0]
+        context = MyContext()
+        actions = register(context, "my-vocab", MyFactory,
+                           **self.extra_keywords)
         # check our expectations of the action:
-        self.assertEqual(len(args), 2)
-        self.assertEqual(args[0], "my-vocab")
-        self.assertEqual(kw, {})
-        self.assert_(isinstance(args[1], vocabulary.FactoryKeywordPasser))
+        self.assertEqual(len(context.args), 2)
+        self.assertEqual(context.args[0], "my-vocab")
+        self.assertEqual(context.kw, {})
+        self.assert_(isinstance(context.args[1], FactoryKeywordPasser))
         # enact the registration:
-        callable(*args, **kw)
+        context.callable(*context.args, **context.kw)
         # make sure the factory behaves as expected:
         self.check_vocabulary_get(self.extra_keywords)
 
 
 def test_suite():
-    return unittest.makeSuite(VocabularyServiceTests)
+    return unittest.TestSuite((
+        unittest.makeSuite(VocabularyServiceTests),
+        ))
 
-if __name__ == "__main__":
-    unittest.main(defaultTest="test_suite")
+if __name__ == '__main__':
+    unittest.main()