~menesis/ubuntu/natty/zope.app.schema/natty

« back to all changes in this revision

Viewing changes to src/zope/app/schema/tests/test_directives.py

  • Committer: Gediminas Paulauskas
  • Author(s): Brian Sutherland
  • Date: 2007-11-08 17:27:48 UTC
  • Revision ID: menesis@pov.lt-20071108172748-2yg2z58jbj9u8tmf
Tags: upstream-3.4.0
ImportĀ upstreamĀ versionĀ 3.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 
4
# All Rights Reserved.
 
5
#
 
6
# This software is subject to the provisions of the Zope Public License,
 
7
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
 
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 
11
# FOR A PARTICULAR PURPOSE.
 
12
#
 
13
##############################################################################
 
14
"""Testing vocabulary directive.
 
15
 
 
16
$Id: test_directives.py 66637 2006-04-07 12:08:52Z jim $
 
17
"""
 
18
# BBB 2006/02/24, to be removed after 12 months
 
19
 
 
20
import unittest
 
21
import warnings
 
22
 
 
23
from zope.app.testing.placelesssetup import PlacelessSetup
 
24
from zope.configuration import xmlconfig
 
25
from zope.app.schema.vocabulary import ZopeVocabularyRegistry
 
26
 
 
27
import zope.app.schema
 
28
 
 
29
 
 
30
class MyFactory(object):
 
31
    def __init__(self, context, **kw):
 
32
        self.ob = context
 
33
        self.kw = kw
 
34
 
 
35
 
 
36
class DirectivesTest(PlacelessSetup, unittest.TestCase):
 
37
 
 
38
    extra_keywords = {"filter": "my-filter",
 
39
                      "another": "keyword"}
 
40
 
 
41
    def setUp(self):
 
42
        super(DirectivesTest, self).setUp()
 
43
        self.__showwarning = warnings.showwarning
 
44
        warnings.showwarning = lambda *a, **k: None
 
45
 
 
46
    def tearDown(self):
 
47
        warnings.showwarning = self.__showwarning
 
48
        super(DirectivesTest, self).tearDown()
 
49
 
 
50
    def check_vocabulary_get(self, kw={}):
 
51
        context = object()
 
52
        registry = ZopeVocabularyRegistry()
 
53
        vocab = registry.get(context, "my-vocab")
 
54
        self.assert_(vocab.ob is context)
 
55
        self.assertEqual(vocab.kw, kw)
 
56
 
 
57
    def test_simple_zcml(self):
 
58
        self.context = xmlconfig.file("tests/simple_vocab.zcml",
 
59
                                      zope.app.schema)
 
60
        self.check_vocabulary_get()
 
61
 
 
62
    def test_passing_keywords_from_zcml(self):
 
63
        self.context = xmlconfig.file("tests/keywords_vocab.zcml",
 
64
                                      zope.app.schema)
 
65
        self.check_vocabulary_get(self.extra_keywords)
 
66
 
 
67
 
 
68
def test_suite():
 
69
    return unittest.TestSuite((
 
70
        unittest.makeSuite(DirectivesTest),
 
71
        ))
 
72
 
 
73
if __name__ == '__main__':
 
74
    unittest.main()