/usr/share/pyshared/zope/schema/tests/test_states.py is in python-zope.schema 3.7.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ##############################################################################
#
# Copyright (c) 2003 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Tests of the states example.
"""
import unittest
from zope.interface import Interface
from zope.interface.verify import verifyObject
from zope.schema import vocabulary
from zope.schema import Choice
from zope.schema.interfaces import IVocabulary
from zope.schema.tests import states
class IBirthInfo(Interface):
state1 = Choice(
title=u'State of Birth',
description=u'The state in which you were born.',
vocabulary="states",
default="AL",
)
state2 = Choice(
title=u'State of Birth',
description=u'The state in which you were born.',
vocabulary="states",
default="AL",
)
state3 = Choice(
title=u'Favorite State',
description=u'The state you like the most.',
vocabulary=states.StateVocabulary(),
)
state4 = Choice(
title=u"Name",
description=u"The name of your new state",
vocabulary="states",
)
class StateSelectionTest(unittest.TestCase):
def setUp(self):
vocabulary._clear()
vr = vocabulary.getVocabularyRegistry()
vr.register("states", states.StateVocabulary)
def tearDown(self):
vocabulary._clear()
def test_default_presentation(self):
field = IBirthInfo.getDescriptionFor("state1")
bound = field.bind(object())
self.assert_(verifyObject(IVocabulary, bound.vocabulary))
self.assertEqual(bound.vocabulary.getTerm("VA").title, "Virginia")
def test_contains(self):
vocab = states.StateVocabulary()
self.assert_(verifyObject(IVocabulary, vocab))
count = 0
L = list(vocab)
for term in L:
count += 1
self.assert_(term.value in vocab)
self.assertEqual(count, len(vocab))
# make sure we get the same values the second time around:
L = [term.value for term in L]
L.sort()
L2 = [term.value for term in vocab]
L2.sort()
self.assertEqual(L, L2)
def test_prebound_vocabulary(self):
field = IBirthInfo.getDescriptionFor("state3")
bound = field.bind(None)
self.assert_(bound.vocabularyName is None)
self.assert_(verifyObject(IVocabulary, bound.vocabulary))
self.assert_("AL" in bound.vocabulary)
def test_suite():
return unittest.makeSuite(StateSelectionTest)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
|