[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_tuplefield.py:1.3
R. David Murray
bitz@bitdance.com
Fri, 24 Jan 2003 22:53:43 -0500
Update of /cvs-repository/Zope3/src/zope/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv21135
Modified Files:
test_tuplefield.py
Log Message:
Additional unit tests for Sequence and Tuple: make sure Sequence allows
sequence types and disallows non-sequence (non-Iterable), and that
Tuple disallows anything but tuples.
=== Zope3/src/zope/schema/tests/test_tuplefield.py 1.2 => 1.3 ===
--- Zope3/src/zope/schema/tests/test_tuplefield.py:1.2 Wed Dec 25 09:15:21 2002
+++ Zope3/src/zope/schema/tests/test_tuplefield.py Fri Jan 24 22:53:40 2003
@@ -12,13 +12,44 @@
#
##############################################################################
"""
+This set of tests exercises both Tuple and Sequence. The only
+behavior Tuple adds to sequence is the restriction of the type
+to 'tuple'.
+
$Id$
"""
from unittest import TestSuite, main, makeSuite
-from zope.schema import Tuple, Int, Float
+from zope.schema import Sequence, Tuple, Int, Float
from zope.schema import errornames
from zope.schema.tests.test_field import FieldTestBase
+class SequenceTest(FieldTestBase):
+ """Test the Sequence Field."""
+
+ _Field_Factory = Sequence
+
+ def testValidate(self):
+ field = self._Field_Factory(title=u'test field', description=u'',
+ readonly=False, required=False)
+ field.validate(None)
+ field.validate(())
+ field.validate([])
+ field.validate('')
+ field.validate({})
+ field.validate([1, 2])
+
+ self.assertRaisesErrorNames(errornames.NotAContainer,
+ field.validate, 1)
+
+ def testValidateRequired(self):
+ field = self._Field_Factory(title=u'test field', description=u'',
+ readonly=False, required=True)
+ field.validate([1, 2])
+
+ self.assertRaisesErrorNames(errornames.RequiredMissing,
+ field.validate, None)
+
+
class TupleTest(FieldTestBase):
"""Test the Tuple Field."""
@@ -32,6 +63,15 @@
field.validate((1, 2))
field.validate((3,))
+ self.assertRaisesErrorNames(errornames.WrongType,
+ field.validate, [1, 2, 3])
+ self.assertRaisesErrorNames(errornames.WrongType,
+ field.validate, 'abc')
+ self.assertRaisesErrorNames(errornames.WrongType,
+ field.validate, 1)
+ self.assertRaisesErrorNames(errornames.WrongType,
+ field.validate, {})
+
def testValidateRequired(self):
field = Tuple(title=u'Tuple field', description=u'',
readonly=False, required=True)
@@ -93,7 +133,10 @@
field.validate, (2, '') )
def test_suite():
- return makeSuite(TupleTest)
+ suite = TestSuite()
+ suite.addTest(makeSuite(TupleTest))
+ suite.addTest(makeSuite(SequenceTest))
+ return suite
if __name__ == '__main__':
main(defaultTest='test_suite')