[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_date.py:1.2 test_tuplefield.py:1.6

Philipp von Weitershausen philikon at philikon.de
Fri Jan 16 08:38:21 EST 2004


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

Modified Files:
	test_date.py test_tuplefield.py 
Log Message:
Changes to the schema package and the widget machinery (see
http://mail.zope.org/pipermail/zope3-dev/2004-January/009265.html):

- Widgets requiring key_type and/or value_type arguments will now check
  whether they implement IField. Before, anything was accepted although
  a field instance was implied. A key_type/value_type of None implies no
  validation of the key/value.

- Basic fields like TextLine, Int, Float, Date, and Datetime are not
  enumerated fields anymore. There are separate Enumerated* fields for
  that purpose now. Extra widgets for that functionality were added
  and configured.


=== Zope3/src/zope/schema/tests/test_date.py 1.1 => 1.2 ===
--- Zope3/src/zope/schema/tests/test_date.py:1.1	Tue Aug 12 14:16:43 2003
+++ Zope3/src/zope/schema/tests/test_date.py	Fri Jan 16 08:38:20 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import main, makeSuite
-from zope.schema import Date
+from zope.schema import Date, EnumeratedDate
 from zope.schema import errornames
 from zope.schema.tests.test_field import FieldTestBase
 from datetime import datetime, date
@@ -82,6 +82,11 @@
         self.assertRaisesErrorNames(errornames.TooSmall, field.validate, d1)
         self.assertRaisesErrorNames(errornames.TooBig, field.validate, d5)
 
+class EnumeratedDateTest(DateTest):
+    """Test the EnumeratedDate Field."""
+
+    _Field_Factory = EnumeratedDate
+
     def testAllowedValues(self):
         d1 = date(2000,10,1)
         d2 = date(2000,10,2)
@@ -100,6 +105,7 @@
 
 def test_suite():
     suite = makeSuite(DateTest)
+    suite.addTest(makeSuite(EnumeratedDateTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_tuplefield.py 1.5 => 1.6 ===
--- Zope3/src/zope/schema/tests/test_tuplefield.py:1.5	Sun Aug 17 02:09:20 2003
+++ Zope3/src/zope/schema/tests/test_tuplefield.py	Fri Jan 16 08:38:20 2004
@@ -19,7 +19,10 @@
 $Id$
 """
 from unittest import TestSuite, main, makeSuite
-from zope.schema import Sequence, Tuple, Int
+
+from zope.interface import implements
+from zope.schema import Field, Sequence, Tuple, Int
+from zope.schema.interfaces import IField
 from zope.schema import errornames
 from zope.schema.tests.test_field import FieldTestBase
 
@@ -131,6 +134,20 @@
                                     field.validate, ('',) )
         self.assertRaisesErrorNames(errornames.WrongContainedType,
                                     field.validate, (3.14159,) )
+
+    def testCorrectValueType(self):
+        # allow value_type of None (XXX)
+        Tuple(value_type=None)
+
+        # do not allow arbitrary value types
+        self.assertRaises(ValueError, Tuple, value_type=object())
+        self.assertRaises(ValueError, Tuple, value_type=Field)
+
+        # however, allow anything that implements IField
+        Tuple(value_type=Field())
+        class FakeField:
+            implements(IField)
+        Tuple(value_type=FakeField())
 
 def test_suite():
     suite = TestSuite()




More information about the Zope3-Checkins mailing list