[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_datetime.py:1.3 test_floatfield.py:1.3 test_intfield.py:1.3 test_strfield.py:1.3
Fred L. Drake, Jr.
fred@zope.com
Mon, 14 Apr 2003 12:13:43 -0400
Update of /cvs-repository/Zope3/src/zope/schema/tests
In directory cvs.zope.org:/tmp/cvs-serv11578/tests
Modified Files:
test_datetime.py test_floatfield.py test_intfield.py
test_strfield.py
Log Message:
Start a change of the relationhip of the IValueSet interface to other
field constraints:
- Introduce new field types: IEnumeratedTextLine, IEnumeratedInt,
IEnumeratedFloat, IEnumeratedDatetime; these should be used any time
the allowed_values option for a field is used, instead of requiring
the base field type to support it.
- Updated tests, docstrings, to reflect future removal of the
IValueSet "mixin" interface from ITextLine, IInt, IField, IDatetime,
and several others where it simply doesn't make sense.
- Modify tests to consistent use _Field_Factory to generate field
objects.
=== Zope3/src/zope/schema/tests/test_datetime.py 1.2 => 1.3 ===
--- Zope3/src/zope/schema/tests/test_datetime.py:1.2 Wed Dec 25 09:15:21 2002
+++ Zope3/src/zope/schema/tests/test_datetime.py Mon Apr 14 12:13:43 2003
@@ -14,8 +14,8 @@
"""
$Id$
"""
-from unittest import TestSuite, main, makeSuite
-from zope.schema import Datetime
+from unittest import main, makeSuite
+from zope.schema import Datetime, EnumeratedDatetime
from zope.schema import errornames
from zope.schema.tests.test_field import FieldTestBase
from datetime import datetime
@@ -26,40 +26,24 @@
_Field_Factory = Datetime
def testValidate(self):
- field = Datetime(title=u'Datetime field', description=u'',
- readonly=False, required=False)
+ field = self._Field_Factory(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 = self._Field_Factory(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 = self._Field_Factory(title=u'Datetime field', description=u'',
+ readonly=False, required=False, min=d1)
field.validate(None)
field.validate(d1)
field.validate(d2)
@@ -72,8 +56,8 @@
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 = self._Field_Factory(title=u'Datetime field', description=u'',
+ readonly=False, required=False, max=d2)
field.validate(None)
field.validate(d1)
field.validate(d2)
@@ -87,8 +71,9 @@
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 = self._Field_Factory(title=u'Datetime field', description=u'',
+ readonly=False, required=False,
+ min=d2, max=d4)
field.validate(None)
field.validate(d2)
field.validate(d3)
@@ -98,8 +83,31 @@
self.assertRaisesErrorNames(errornames.TooBig, field.validate, d5)
+class EnumeratedDatetimeTest(DatetimeTest):
+ """Tests of the EnumeratedDatetime field type."""
+
+ _Field_Factory = EnumeratedDatetime
+
+ def testAllowedValues(self):
+ d1 = datetime(2000,10,1)
+ d2 = datetime(2000,10,2)
+
+ field = self._Field_Factory(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 test_suite():
- return makeSuite(DatetimeTest)
+ suite = makeSuite(DatetimeTest)
+ suite.addTest(makeSuite(EnumeratedDatetimeTest))
+ return suite
if __name__ == '__main__':
main(defaultTest='test_suite')
=== Zope3/src/zope/schema/tests/test_floatfield.py 1.2 => 1.3 ===
--- Zope3/src/zope/schema/tests/test_floatfield.py:1.2 Wed Dec 25 09:15:21 2002
+++ Zope3/src/zope/schema/tests/test_floatfield.py Mon Apr 14 12:13:43 2003
@@ -14,8 +14,8 @@
"""
$Id$
"""
-from unittest import TestSuite, main, makeSuite
-from zope.schema import Float
+from unittest import main, makeSuite
+from zope.schema import Float, EnumeratedFloat
from zope.schema import errornames
from zope.schema.tests.test_field import FieldTestBase
@@ -25,35 +25,26 @@
_Field_Factory = Float
def testValidate(self):
- field = Float(title=u'Float field', description=u'',
- readonly=False, required=False)
+ field = self._Field_Factory(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 = self._Field_Factory(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 = self._Field_Factory(title=u'Float field', description=u'',
+ readonly=False, required=False, min=10.5)
field.validate(None)
field.validate(10.6)
field.validate(20.2)
@@ -62,8 +53,8 @@
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 = self._Field_Factory(title=u'Float field', description=u'',
+ readonly=False, required=False, max=10.5)
field.validate(None)
field.validate(5.3)
field.validate(-9.1)
@@ -72,8 +63,9 @@
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 = self._Field_Factory(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)
@@ -85,8 +77,25 @@
self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20.02)
+class EnumeratedFloatTest(FloatTest):
+ """Tests for the EnumeratedFloat field type."""
+
+ _Field_Factory = EnumeratedFloat
+
+ def testAllowedValues(self):
+ field = self._Field_Factory(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 test_suite():
- return makeSuite(FloatTest)
+ suite = makeSuite(FloatTest)
+ suite.addTest(makeSuite(EnumeratedFloatTest))
+ return suite
if __name__ == '__main__':
main(defaultTest='test_suite')
=== Zope3/src/zope/schema/tests/test_intfield.py 1.2 => 1.3 ===
--- Zope3/src/zope/schema/tests/test_intfield.py:1.2 Wed Dec 25 09:15:21 2002
+++ Zope3/src/zope/schema/tests/test_intfield.py Mon Apr 14 12:13:43 2003
@@ -15,7 +15,7 @@
$Id$
"""
from unittest import TestSuite, main, makeSuite
-from zope.schema import Int
+from zope.schema import Int, EnumeratedInt
from zope.schema import errornames
from zope.schema.tests.test_field import FieldTestBase
@@ -25,16 +25,16 @@
_Field_Factory = Int
def testValidate(self):
- field = Int(title=u'Int field', description=u'',
- readonly=False, required=False)
+ field = self._Field_Factory(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 = self._Field_Factory(title=u'Int field', description=u'',
+ readonly=False, required=True)
field.validate(10)
field.validate(0)
field.validate(-1)
@@ -42,18 +42,9 @@
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 = self._Field_Factory(title=u'Int field', description=u'',
+ readonly=False, required=False, min=10)
field.validate(None)
field.validate(10)
field.validate(20)
@@ -62,8 +53,8 @@
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 = self._Field_Factory(title=u'Int field', description=u'',
+ readonly=False, required=False, max=10)
field.validate(None)
field.validate(5)
field.validate(9)
@@ -72,8 +63,9 @@
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 = self._Field_Factory(title=u'Int field', description=u'',
+ readonly=False, required=False,
+ min=0, max=10)
field.validate(None)
field.validate(0)
field.validate(5)
@@ -85,8 +77,25 @@
self.assertRaisesErrorNames(errornames.TooBig, field.validate, 20)
+class EnumeratedIntTest(IntTest):
+ """Test the EnumeratedInt field type."""
+
+ _Field_Factory = EnumeratedInt
+
+ def testAllowedValues(self):
+ field = self._Field_Factory(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 test_suite():
- return makeSuite(IntTest)
+ suite = makeSuite(IntTest)
+ suite.addTest(makeSuite(EnumeratedIntTest))
+ return suite
if __name__ == '__main__':
main(defaultTest='test_suite')
=== Zope3/src/zope/schema/tests/test_strfield.py 1.2 => 1.3 ===
--- Zope3/src/zope/schema/tests/test_strfield.py:1.2 Wed Dec 25 09:15:21 2002
+++ Zope3/src/zope/schema/tests/test_strfield.py Mon Apr 14 12:13:43 2003
@@ -15,7 +15,7 @@
$Id$
"""
from unittest import TestSuite, main, makeSuite
-from zope.schema import Bytes, BytesLine, Text, TextLine
+from zope.schema import Bytes, BytesLine, Text, TextLine, EnumeratedTextLine
from zope.schema import errornames
from zope.schema.interfaces import ValidationError
from zope.schema.tests.test_field import FieldTestBase
@@ -45,18 +45,6 @@
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'',
@@ -146,6 +134,21 @@
class TextLineTest(SingleLine, TextTest):
_Field_Factory = TextLine
+class EnumeratedTextLineTest(TextLineTest):
+ _Field_Factory = EnumeratedTextLine
+
+ 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 test_suite():
return TestSuite((
@@ -153,6 +156,7 @@
makeSuite(TextTest),
makeSuite(LineTest),
makeSuite(TextLineTest),
+ makeSuite(EnumeratedTextLineTest),
))
if __name__ == '__main__':