[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - __init__.py:1.2 test_boolfield.py:1.2 test_datetime.py:1.2 test_dictfield.py:1.2 test_equality.py:1.2 test_field.py:1.2 test_fieldproperty.py:1.2 test_floatfield.py:1.2 test_intfield.py:1.2 test_listfield.py:1.2 test_schema.py:1.2 test_strfield.py:1.2 test_tuplefield.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:15:52 -0500


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

Added Files:
	__init__.py test_boolfield.py test_datetime.py 
	test_dictfield.py test_equality.py test_field.py 
	test_fieldproperty.py test_floatfield.py test_intfield.py 
	test_listfield.py test_schema.py test_strfield.py 
	test_tuplefield.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/schema/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/__init__.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/schema/tests/test_boolfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/test_boolfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,47 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Bool
+from zope.schema.errornames import RequiredMissing
+from zope.schema.tests.test_field import FieldTestBase
+
+class BoolTest(FieldTestBase):
+    """Test the Bool Field."""
+
+    _Field_Factory = Bool
+
+    def testValidate(self):
+        field = Bool(title=u'Bool field', description=u'',
+                     readonly=False, required=False)
+        field.validate(None)
+        field.validate(True)
+        field.validate(False)
+
+    def testValidateRequired(self):
+        field = Bool(title=u'Bool field', description=u'',
+                     readonly=False, required=True)
+        field.validate(True)
+        field.validate(False)
+
+        self.assertRaisesErrorNames(RequiredMissing, field.validate, None)
+
+
+def test_suite():
+    return makeSuite(BoolTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_datetime.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/test_datetime.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,105 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Datetime
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+from datetime import datetime
+
+class DatetimeTest(FieldTestBase):
+    """Test the Datetime Field."""
+
+    _Field_Factory = Datetime
+
+    def testValidate(self):
+        field = Datetime(title=u'Datetime field', description=u'',
+                        readonly=False, required=False)
+        field.validate(None)
+        field.validate(datetime.now())
+
+    def testValidateRequired(self):
+        field = Datetime(title=u'Datetime field', description=u'',
+                    readonly=False, required=True)
+        field.validate(datetime.now())
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testAllowedValues(self):
+        d1 = datetime(2000,10,1)
+        d2 = datetime(2000,10,2)
+
+
+        field = Datetime(title=u'Datetime field', description=u'',
+                        readonly=False, required=False,
+                         allowed_values=(d1, d2))
+        field.validate(None)
+        field.validate(d2)
+        field.validate(datetime(2000,10,2))
+
+        self.assertRaisesErrorNames(errornames.InvalidValue,
+                                    field.validate,
+                                    datetime(2000,10,4))
+
+    def testValidateMin(self):
+        d1 = datetime(2000,10,1)
+        d2 = datetime(2000,10,2)
+        field = Datetime(title=u'Datetime field', description=u'',
+                        readonly=False, required=False, min=d1)
+        field.validate(None)
+        field.validate(d1)
+        field.validate(d2)
+        field.validate(datetime.now())
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate,
+                                    datetime(2000,9,30))
+
+    def testValidateMax(self):
+        d1 = datetime(2000,10,1)
+        d2 = datetime(2000,10,2)
+        d3 = datetime(2000,10,3)
+        field = Datetime(title=u'Datetime field', description=u'',
+                        readonly=False, required=False, max=d2)
+        field.validate(None)
+        field.validate(d1)
+        field.validate(d2)
+
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, d3)
+
+    def testValidateMinAndMax(self):
+        d1 = datetime(2000,10,1)
+        d2 = datetime(2000,10,2)
+        d3 = datetime(2000,10,3)
+        d4 = datetime(2000,10,4)
+        d5 = datetime(2000,10,5)
+
+        field = Datetime(title=u'Datetime field', description=u'',
+                        readonly=False, required=False, min=d2, max=d4)
+        field.validate(None)
+        field.validate(d2)
+        field.validate(d3)
+        field.validate(d4)
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, d1)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, d5)
+
+
+def test_suite():
+    return makeSuite(DatetimeTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_dictfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/test_dictfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,113 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Dict, Int, Float
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+
+class DictTest(FieldTestBase):
+    """Test the Dict Field."""
+
+    _Field_Factory = Dict
+
+    def testValidate(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False)
+        field.validate(None)
+        field.validate({})
+        field.validate({1: 'foo'})
+        field.validate({'a': 1})
+
+    def testValidateRequired(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=True)
+        field.validate({})
+        field.validate({1: 'foo'})
+        field.validate({'a': 1})
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testValidateMinValues(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False,
+                     min_length=1)
+        field.validate(None)
+        field.validate({1: 'a'})
+        field.validate({1: 'a', 2: 'b'})
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, {})
+
+    def testValidateMaxValues(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False,
+                     max_length=1)
+        field.validate(None)
+        field.validate({})
+        field.validate({1: 'a'})
+
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, {1: 'a', 2: 'b'})
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, {1: 'a', 2: 'b', 3: 'c'})
+
+    def testValidateMinValuesAndMaxValues(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False,
+                     min_length=1, max_length=2)
+        field.validate(None)
+        field.validate({1: 'a'})
+        field.validate({1: 'a', 2: 'b'})
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, {})
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, {1: 'a', 2: 'b', 3: 'c'})
+
+    def testValidateValueTypes(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False,
+                     value_types=(Int(), Float()))
+        field.validate(None)
+        field.validate({'a': 5.3})
+        field.validate({'a': 2, 'b': 2.3})
+
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, {1: ''} )
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, {'a': ()} )
+
+    def testValidateKeyTypes(self):
+        field = Dict(title=u'Dict field',
+                     description=u'', readonly=False, required=False,
+                     key_types=(Int(), Float()))
+        field.validate(None)
+        field.validate({5.3: 'a'})
+        field.validate({2: 'a', 2.3: 'b'})
+
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, {'': 1} )
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, {(): 'a'} )
+
+
+def test_suite():
+    return makeSuite(DictTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_equality.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/test_equality.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,33 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestCase, TestSuite, makeSuite
+from zope.schema import Field, Text, Int
+
+class FieldEqualityTests(TestCase):
+
+    equality = [
+        'Text(title=u"Foo", description=u"Bar")',
+        'Int(title=u"Foo", description=u"Bar")',
+        ]
+
+    def test_equality(self):
+        for text in self.equality:
+            self.assertEquals(eval(text), eval(text))
+
+def test_suite():
+    return TestSuite(
+        [makeSuite(FieldEqualityTests)])


=== Zope3/src/zope/schema/tests/test_field.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:51 2002
+++ Zope3/src/zope/schema/tests/test_field.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,139 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.schema import Field, Text, Int
+from zope.schema.interfaces import IField
+from zope.schema import errornames
+from zope.schema.interfaces import StopValidation, ValidationError
+
+class FieldTestBase(TestCase):
+
+    def assertRaisesErrorNames(self, error_name, f, *args, **kw):
+        try:
+            f(*args, **kw)
+        except ValidationError, e:
+            self.assertEquals(error_name, e[0])
+            return
+        self.fail('Expected ValidationError')
+
+    def test_bind(self):
+        field = self._Field_Factory(
+            __name__ = 'x',
+            title=u'Not required field', description=u'',
+            readonly=False, required=False)
+
+        class C(object):
+            x=None
+
+        c = C()
+        field2 = field.bind(c)
+
+        self.assertEqual(field2.context, c)
+        for n in ('__class__', '__name__', 'title', 'description',
+                  'readonly', 'required'):
+            self.assertEquals(getattr(field2, n), getattr(field, n), n)
+
+    def testValidate(self):
+        field = self._Field_Factory(
+            title=u'Not required field', description=u'',
+            readonly=False, required=False)
+        field.validate(None)
+        field.validate('foo')
+        field.validate(1)
+        field.validate(0)
+        field.validate('')
+
+    def testValidateRequired(self):
+        field = self._Field_Factory(
+            title=u'Required field', description=u'',
+            readonly=False, required=True)
+        field.validate('foo')
+        field.validate(1)
+        field.validate(0)
+        field.validate('')
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+class FieldTest(FieldTestBase):
+    """Test generic Field."""
+
+
+    _Field_Factory = Field
+
+
+    def testSillyDefault(self):
+
+        self.assertRaises(ValidationError, Text, default="")
+
+    def test__doc__(self):
+        field = Text(title=u"test fiield",
+                     description=(
+                         u"To make sure that\n"
+                         u"doc strings are working correctly\n"
+                         )
+                     )
+        self.assertEqual(
+            field.__doc__,
+            u"test fiield\n\n"
+            u"To make sure that\n"
+            u"doc strings are working correctly\n"
+            )
+
+    def testOrdering(self):
+
+        from zope.interface import Interface
+
+        class S1(Interface):
+            a = Text()
+            b = Text()
+
+        self.failUnless(S1['a'].order < S1['b'].order)
+
+        class S2(Interface):
+            b = Text()
+            a = Text()
+
+        self.failUnless(S2['a'].order > S2['b'].order)
+
+    def testConstraint(self):
+        def isodd(x):
+            return x % 2 == 1
+
+        i = Int(title=u'my constrained integer',
+                constraint=isodd)
+
+        i.validate(11)
+        self.assertRaisesErrorNames(errornames.ConstraintNotSatisfied,
+                                    i.validate, 10)
+
+
+class FieldDefaultBehaviour(TestCase):
+    def test_required_defaults_to_true(self):
+        class MyField(Field):
+            pass
+        field = MyField(title=u'my')
+        self.assert_(field.required)
+
+def test_suite():
+    return TestSuite(   (
+            makeSuite(FieldTest),
+            makeSuite(FieldDefaultBehaviour)
+    ))
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_fieldproperty.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_fieldproperty.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,68 @@
+##############################################################################
+#
+# 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$
+"""
+
+from unittest import TestCase, TestSuite, main, makeSuite
+
+from zope.interface import Interface
+from zope.schema import Float, Text, Bytes
+from zope.schema.fieldproperty import FieldProperty
+from zope.schema.interfaces import ValidationError
+
+class I(Interface):
+
+    title = Text(description=u"Short summary", default=u'say something')
+    weight = Float(min=0.0)
+    code = Bytes(min_length=6, max_length=6, default='xxxxxx')
+
+class C(object):
+
+    title = FieldProperty(I['title'])
+    weight = FieldProperty(I['weight'])
+    code = FieldProperty(I['code'])
+
+class Test(TestCase):
+
+    def test(self):
+        c = C()
+        self.assertEqual(c.title, u'say something')
+        self.assertEqual(c.weight, None)
+        self.assertEqual(c.code, 'xxxxxx')
+        self.assertRaises(ValidationError, setattr, c, 'title', 'foo')
+        self.assertRaises(ValidationError, setattr, c, 'weight', 'foo')
+        self.assertRaises(ValidationError, setattr, c, 'weight', -1.0)
+        self.assertRaises(ValidationError, setattr, c, 'weight', 2)
+        self.assertRaises(ValidationError, setattr, c, 'code', -1)
+        self.assertRaises(ValidationError, setattr, c, 'code', 'xxxx')
+        self.assertRaises(ValidationError, setattr, c, 'code', u'xxxxxx')
+
+        c.title = u'c is good'
+        c.weight = 10.0
+        c.code = 'abcdef'
+
+        self.assertEqual(c.title, u'c is good')
+        self.assertEqual(c.weight, 10)
+        self.assertEqual(c.code, 'abcdef')
+
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(Test),
+        ))
+
+if __name__=='__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_floatfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_floatfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Float
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+
+class FloatTest(FieldTestBase):
+    """Test the Float Field."""
+
+    _Field_Factory = Float
+
+    def testValidate(self):
+        field = Float(title=u'Float field', description=u'',
+                        readonly=False, required=False)
+        field.validate(None)
+        field.validate(10.0)
+        field.validate(0.93)
+        field.validate(1000.0003)
+
+    def testValidateRequired(self):
+        field = Float(title=u'Float field', description=u'',
+                        readonly=False, required=True)
+        field.validate(10.0)
+        field.validate(0.93)
+        field.validate(1000.0003)
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+    def testAllowedValues(self):
+        field = Float(title=u'Integer field', description=u'',
+                      readonly=False, required=False,
+                      allowed_values=(0.1, 2.6))
+        field.validate(None)
+        field.validate(2.6)
+
+        self.assertRaisesErrorNames(errornames.InvalidValue,
+                                    field.validate, -5.4)
+
+    def testValidateMin(self):
+        field = Float(title=u'Float field', description=u'',
+                        readonly=False, required=False, min=10.5)
+        field.validate(None)
+        field.validate(10.6)
+        field.validate(20.2)
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -9.0)
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, 10.4)
+
+    def testValidateMax(self):
+        field = Float(title=u'Float field', description=u'',
+                        readonly=False, required=False, max=10.5)
+        field.validate(None)
+        field.validate(5.3)
+        field.validate(-9.1)
+
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 10.51)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20.7)
+
+    def testValidateMinAndMax(self):
+        field = Float(title=u'Float field', description=u'',
+                        readonly=False, required=False, min=-0.6, max=10.1)
+        field.validate(None)
+        field.validate(0.0)
+        field.validate(-0.03)
+        field.validate(10.0001)
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -10.0)
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -1.6)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 11.45)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20.02)
+
+
+def test_suite():
+    return makeSuite(FloatTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_intfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_intfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,92 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Int
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+
+class IntTest(FieldTestBase):
+    """Test the Int Field."""
+
+    _Field_Factory = Int
+
+    def testValidate(self):
+        field = Int(title=u'Int field', description=u'',
+                        readonly=False, required=False)
+        field.validate(None)
+        field.validate(10)
+        field.validate(0)
+        field.validate(-1)
+
+    def testValidateRequired(self):
+        field = Int(title=u'Int field', description=u'',
+                    readonly=False, required=True)
+        field.validate(10)
+        field.validate(0)
+        field.validate(-1)
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testAllowedValues(self):
+        field = Int(title=u'Int field', description=u'',
+                        readonly=False, required=False, allowed_values=(-1, 2))
+        field.validate(None)
+        field.validate(2)
+
+        self.assertRaisesErrorNames(errornames.InvalidValue,
+                                    field.validate, 4)
+
+    def testValidateMin(self):
+        field = Int(title=u'Int field', description=u'',
+                        readonly=False, required=False, min=10)
+        field.validate(None)
+        field.validate(10)
+        field.validate(20)
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, 9)
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -10)
+
+    def testValidateMax(self):
+        field = Int(title=u'Int field', description=u'',
+                        readonly=False, required=False, max=10)
+        field.validate(None)
+        field.validate(5)
+        field.validate(9)
+
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 11)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20)
+
+    def testValidateMinAndMax(self):
+        field = Int(title=u'Int field', description=u'',
+                        readonly=False, required=False, min=0, max=10)
+        field.validate(None)
+        field.validate(0)
+        field.validate(5)
+        field.validate(10)
+
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -10)
+        self.assertRaisesErrorNames(errornames.TooSmall, field.validate, -1)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 11)
+        self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20)
+
+
+def test_suite():
+    return makeSuite(IntTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_listfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_listfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,99 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import List, Int, Float
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+
+class ListTest(FieldTestBase):
+    """Test the List Field."""
+
+    _Field_Factory = List
+
+    def testValidate(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=False)
+        field.validate(None)
+        field.validate([])
+        field.validate([1, 2])
+        field.validate([3,])
+
+    def testValidateRequired(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=True)
+        field.validate([])
+        field.validate([1, 2])
+        field.validate([3,])
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testValidateMinValues(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=False, min_length=2)
+        field.validate(None)
+        field.validate([1, 2])
+        field.validate([1, 2, 3])
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, [])
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, [1,])
+
+    def testValidateMaxValues(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=False, max_length=2)
+        field.validate(None)
+        field.validate([])
+        field.validate([1, 2])
+
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, [1, 2, 3, 4])
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, [1, 2, 3])
+
+    def testValidateMinValuesAndMaxValues(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=False,
+                     min_length=1, max_length=2)
+        field.validate(None)
+        field.validate([1, ])
+        field.validate([1, 2])
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, [])
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, [1, 2, 3])
+
+    def testValidateValueTypes(self):
+        field = List(title=u'List field', description=u'',
+                     readonly=False, required=False,
+                     value_types=(Int(), Float()))
+        field.validate(None)
+        field.validate([5.3,])
+        field.validate([2, 2.3])
+
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, ['',] )
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, [2, ''] )
+
+def test_suite():
+    return makeSuite(ListTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_schema.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_schema.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,105 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestCase, TestSuite, main, makeSuite
+from zope.schema.interfaces import StopValidation, ValidationError, \
+     ValidationErrorsAll
+from zope.interface import Interface
+from zope.schema import Bytes
+from zope.schema.errornames import RequiredMissing
+from zope.schema import validateMapping, validateMappingAll,\
+     getFields, getFieldsInOrder
+
+class ISchemaTest(Interface):
+    title = Bytes(
+        title=u"Title",
+        description=u"Title",
+        default="",
+        required=True)
+
+    description = Bytes(
+        title=u"Description",
+        description=u"Description",
+        default="",
+        required=True)
+
+    spam = Bytes(
+        title=u"Spam",
+        description=u"Spam",
+        default="",
+        required=True)
+
+class SchemaTest(TestCase):
+
+    def testValidateMapping(self):
+        dict = {'title': 'A title',
+                'description': 'A particular description.',
+                'spam': 'Spam'}
+        try:
+            validateMapping(ISchemaTest, dict)
+        except ValidationError, e:
+            self.fail("Unexpected ValidationError: %s" % e.error_name)
+
+    def testValidateBadMapping(self):
+        dict = {'title': 'A title'}
+        self.assertRaises(ValidationError, validateMapping, ISchemaTest, dict)
+
+    def testValidateMappingAll(self):
+        dict = {'title': 'A title',
+                'description': 'A particular description.',
+                'spam': 'Spam',
+                }
+        try:
+            validateMappingAll(ISchemaTest, dict)
+        except ValidationErrorsAll:
+            self.fail("Unexpected ValidationErrors")
+
+    def test_validateBadMappingAll(self):
+        dict = {'title': 'A title'}
+        try:
+            validateMappingAll(ISchemaTest, dict)
+        except ValidationErrorsAll, e:
+            error=ValidationError(RequiredMissing)
+            self.assertEqual(e.errors ,
+                             [('description',error), ('spam',error)])
+            self.assertRaises(ValidationError, validateMapping, ISchemaTest,
+                              dict)
+            return
+        self.fail('Expected ValidationErrors, but none detected')
+
+    def test_getFields(self):
+        fields = getFields(ISchemaTest)
+
+        self.assert_(fields.has_key('title'))
+        self.assert_(fields.has_key('description'))
+        self.assert_(fields.has_key('spam'))
+
+        # test whether getName() has the right value
+        for key, value in fields.iteritems():
+            self.assertEquals(key, value.getName())
+
+    def test_getFieldsInOrder(self):
+        fields = getFieldsInOrder(ISchemaTest)
+        field_names = [name for name, field in fields]
+        self.assertEquals(field_names, ['title', 'description', 'spam'])
+        for key, value in fields:
+            self.assertEquals(key, value.getName())
+
+def test_suite():
+    return makeSuite(SchemaTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_strfield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_strfield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,159 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Bytes, BytesLine, Text, TextLine
+from zope.schema import errornames
+from zope.schema.interfaces import ValidationError
+from zope.schema.tests.test_field import FieldTestBase
+
+class StrTest(FieldTestBase):
+    """Test the Str Field."""
+
+    def testValidate(self):
+        field = self._Field_Factory(title=u'Str field', description=u'',
+                                    readonly=False, required=False)
+        field.validate(None)
+        field.validate(self._convert('foo'))
+        field.validate(self._convert(''))
+
+    def testValidateRequired(self):
+
+        # Note that if we want to require non-empty strings,
+        # we need to set the min-length to 1.
+
+        field = self._Field_Factory(
+            title=u'Str field', description=u'',
+            readonly=False, required=True, min_length=1)
+        field.validate(self._convert('foo'))
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert(''))
+
+    def testAllowedValues(self):
+        field = self._Field_Factory(
+            title=u'Str field', description=u'',
+            readonly=False, required=False,
+            allowed_values=(self._convert('foo'),
+                            self._convert('bar')))
+        field.validate(None)
+        field.validate(self._convert('foo'))
+
+        self.assertRaisesErrorNames(errornames.InvalidValue,
+                                    field.validate, self._convert('blah'))
+
+    def testValidateMinLength(self):
+        field = self._Field_Factory(
+            title=u'Str field', description=u'',
+            readonly=False, required=False, min_length=3)
+        field.validate(None)
+        field.validate(self._convert('333'))
+        field.validate(self._convert('55555'))
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert(''))
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert('22'))
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert('1'))
+
+    def testValidateMaxLength(self):
+        field = self._Field_Factory(
+            title=u'Str field', description=u'',
+            readonly=False, required=False, max_length=5)
+        field.validate(None)
+        field.validate(self._convert(''))
+        field.validate(self._convert('333'))
+        field.validate(self._convert('55555'))
+
+        self.assertRaisesErrorNames(errornames.TooLong, field.validate,
+                                    self._convert('666666'))
+        self.assertRaisesErrorNames(errornames.TooLong, field.validate,
+                                    self._convert('999999999'))
+
+    def testValidateMinLengthAndMaxLength(self):
+        field = self._Field_Factory(
+            title=u'Str field', description=u'',
+            readonly=False, required=False,
+            min_length=3, max_length=5)
+
+        field.validate(None)
+        field.validate(self._convert('333'))
+        field.validate(self._convert('4444'))
+        field.validate(self._convert('55555'))
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert('22'))
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, self._convert('22'))
+        self.assertRaisesErrorNames(errornames.TooLong, field.validate,
+                                    self._convert('666666'))
+        self.assertRaisesErrorNames(errornames.TooLong, field.validate,
+                                    self._convert('999999999'))
+
+
+class MultiLine:
+
+    def test_newlines(self):
+        field = self._Field_Factory(title=u'Str field')
+        field.validate(self._convert('hello\nworld'))
+
+
+class BytesTest(StrTest, MultiLine):
+    _Field_Factory = Bytes
+    _convert = str
+
+    def testBadStringType(self):
+        field = self._Field_Factory()
+        self.assertRaises(ValidationError, field.validate, u'hello')
+
+
+class TextTest(StrTest, MultiLine):
+    _Field_Factory = Text
+    def _convert(self, v):
+        return unicode(v, 'ascii')
+
+    def testBadStringType(self):
+        field = self._Field_Factory()
+        self.assertRaises(ValidationError, field.validate, 'hello')
+
+class SingleLine:
+
+    def test_newlines(self):
+        field = self._Field_Factory(title=u'Str field')
+        self.assertRaisesErrorNames(errornames.ConstraintNotSatisfied,
+                                    field.validate,
+                                    self._convert('hello\nworld'))
+
+class LineTest(SingleLine, BytesTest):
+    _Field_Factory = BytesLine
+
+class TextLineTest(SingleLine, TextTest):
+    _Field_Factory = TextLine
+
+
+def test_suite():
+    return TestSuite((
+        makeSuite(BytesTest),
+        makeSuite(TextTest),
+        makeSuite(LineTest),
+        makeSuite(TextLineTest),
+        ))
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')


=== Zope3/src/zope/schema/tests/test_tuplefield.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:52 2002
+++ Zope3/src/zope/schema/tests/test_tuplefield.py	Wed Dec 25 09:15:21 2002
@@ -0,0 +1,99 @@
+##############################################################################
+#
+# 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$
+"""
+from unittest import TestSuite, main, makeSuite
+from zope.schema import Tuple, Int, Float
+from zope.schema import errornames
+from zope.schema.tests.test_field import FieldTestBase
+
+class TupleTest(FieldTestBase):
+    """Test the Tuple Field."""
+
+    _Field_Factory = Tuple
+
+    def testValidate(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=False)
+        field.validate(None)
+        field.validate(())
+        field.validate((1, 2))
+        field.validate((3,))
+
+    def testValidateRequired(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=True)
+        field.validate(())
+        field.validate((1, 2))
+        field.validate((3,))
+
+        self.assertRaisesErrorNames(errornames.RequiredMissing,
+                                    field.validate, None)
+
+    def testValidateMinValues(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=False, min_length=2)
+        field.validate(None)
+        field.validate((1, 2))
+        field.validate((1, 2, 3))
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, ())
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, (1,))
+
+    def testValidateMaxValues(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=False, max_length=2)
+        field.validate(None)
+        field.validate(())
+        field.validate((1, 2))
+
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, (1, 2, 3, 4))
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, (1, 2, 3))
+
+    def testValidateMinValuesAndMaxValues(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=False,
+                      min_length=1, max_length=2)
+        field.validate(None)
+        field.validate((1, ))
+        field.validate((1, 2))
+
+        self.assertRaisesErrorNames(errornames.TooShort,
+                                    field.validate, ())
+        self.assertRaisesErrorNames(errornames.TooLong,
+                                    field.validate, (1, 2, 3))
+
+    def testValidateValueTypes(self):
+        field = Tuple(title=u'Tuple field', description=u'',
+                      readonly=False, required=False,
+                      value_types=(Int(), Float()))
+        field.validate(None)
+        field.validate((5.3,))
+        field.validate((2, 2.3))
+
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, ('',) )
+        self.assertRaisesErrorNames(errornames.WrongContainedType,
+                                    field.validate, (2, '') )
+
+def test_suite():
+    return makeSuite(TupleTest)
+
+if __name__ == '__main__':
+    main(defaultTest='test_suite')