[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_containerfield.py:1.1 test_iterablefield.py:1.1
R. David Murray
bitz@bitdance.com
Fri, 24 Jan 2003 21:49:30 -0500
Update of /cvs-repository/Zope3/src/zope/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv12999
Added Files:
test_containerfield.py test_iterablefield.py
Log Message:
Add unit tests for Container and Iterable fields.
=== Added File Zope3/src/zope/schema/tests/test_containerfield.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.
#
##############################################################################
"""
$Id: test_containerfield.py,v 1.1 2003/01/25 02:49:27 rdmurray Exp $
"""
from UserDict import UserDict
from unittest import TestSuite, main, makeSuite
from zope.schema import Container
from zope.schema.errornames import RequiredMissing, NotAContainer
from zope.schema.tests.test_field import FieldTestBase
class ContainerTest(FieldTestBase):
"""Test the Container Field."""
_Field_Factory = Container
def testValidate(self):
field = self._Field_Factory(title=u'test field', description=u'',
readonly=False, required=False)
field.validate(None)
field.validate('')
field.validate('abc')
field.validate([1, 2, 3])
field.validate({'a': 1, 'b': 2})
field.validate(UserDict())
self.assertRaisesErrorNames(NotAContainer, field.validate, 1)
self.assertRaisesErrorNames(NotAContainer, field.validate, True)
def testValidateRequired(self):
field = self._Field_Factory(title=u'test field', description=u'',
readonly=False, required=True)
field.validate('')
self.assertRaisesErrorNames(RequiredMissing, field.validate, None)
def test_suite():
return makeSuite(ContainerTest)
if __name__ == '__main__':
main(defaultTest='test_suite')
=== Added File Zope3/src/zope/schema/tests/test_iterablefield.py ===
##############################################################################
#
# Copyright (c) 2003 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: test_iterablefield.py,v 1.1 2003/01/25 02:49:27 rdmurray Exp $
"""
from UserDict import UserDict, IterableUserDict
from unittest import TestSuite, main, makeSuite
from zope.schema import Iterable
from zope.schema.errornames import RequiredMissing
from zope.schema.errornames import NotAContainer, NotAnIterator
from zope.schema.tests.test_field import FieldTestBase
class IterableTest(FieldTestBase):
"""Test the Iterable Field."""
_Field_Factory = Iterable
def testValidate(self):
field = self._Field_Factory(title=u'test field', description=u'',
readonly=False, required=False)
field.validate(None)
field.validate('')
field.validate('abc')
field.validate([1, 2, 3])
field.validate({'a': 1, 'b': 2})
field.validate(IterableUserDict())
self.assertRaisesErrorNames(NotAContainer, field.validate, 1)
self.assertRaisesErrorNames(NotAContainer, field.validate, True)
self.assertRaisesErrorNames(NotAnIterator, field.validate, UserDict)
def testValidateRequired(self):
field = self._Field_Factory(title=u'test field', description=u'',
readonly=False, required=True)
field.validate('')
self.assertRaisesErrorNames(RequiredMissing, field.validate, None)
def test_suite():
return makeSuite(IterableTest)
if __name__ == '__main__':
main(defaultTest='test_suite')