[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_date.py:1.4 test_datetime.py:1.5 test_floatfield.py:1.5 test_intfield.py:1.6 test_states.py:1.6 test_strfield.py:1.5 test_tuplefield.py:1.8 test_vocabulary.py:1.14

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Apr 24 19:21:08 EDT 2004


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

Modified Files:
	test_date.py test_datetime.py test_floatfield.py 
	test_intfield.py test_states.py test_strfield.py 
	test_tuplefield.py test_vocabulary.py 
Log Message:


Remove Enumerated* and *VocabualryField* and replace it by Choice and Sequence.


=== Zope3/src/zope/schema/tests/test_date.py 1.3 => 1.4 ===
--- Zope3/src/zope/schema/tests/test_date.py:1.3	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_date.py	Sat Apr 24 19:21:06 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import main, makeSuite
-from zope.schema import Date, EnumeratedDate
+from zope.schema import Date
 from zope.schema.interfaces import RequiredMissing, InvalidValue
 from zope.schema.interfaces import TooSmall, TooBig
 from zope.schema.tests.test_field import FieldTestBase
@@ -81,28 +81,9 @@
         self.assertRaises(TooSmall, field.validate, d1)
         self.assertRaises(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)
-
-        field = self._Field_Factory(title=u'Date field', description=u'',
-                                    readonly=False, required=False,
-                                    allowed_values=(d1, d2))
-        field.validate(None)
-        field.validate(d2)
-        field.validate(date(2000,10,2))
-
-        self.assertRaises(InvalidValue, field.validate, date(2000,10,4))
-
 
 def test_suite():
     suite = makeSuite(DateTest)
-    suite.addTest(makeSuite(EnumeratedDateTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_datetime.py 1.4 => 1.5 ===
--- Zope3/src/zope/schema/tests/test_datetime.py:1.4	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_datetime.py	Sat Apr 24 19:21:06 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import main, makeSuite
-from zope.schema import Datetime, EnumeratedDatetime
+from zope.schema import Datetime
 from zope.schema.interfaces import RequiredMissing, InvalidValue
 from zope.schema.interfaces import TooSmall, TooBig
 from zope.schema.tests.test_field import FieldTestBase
@@ -82,28 +82,8 @@
         self.assertRaises(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.assertRaises(InvalidValue, field.validate, datetime(2000,10,4))
-
-
 def test_suite():
     suite = makeSuite(DatetimeTest)
-    suite.addTest(makeSuite(EnumeratedDatetimeTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_floatfield.py 1.4 => 1.5 ===
--- Zope3/src/zope/schema/tests/test_floatfield.py:1.4	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_floatfield.py	Sat Apr 24 19:21:06 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import main, makeSuite
-from zope.schema import Float, EnumeratedFloat
+from zope.schema import Float
 from zope.schema.interfaces import RequiredMissing, InvalidValue
 from zope.schema.interfaces import TooSmall, TooBig
 from zope.schema.tests.test_field import FieldTestBase
@@ -77,23 +77,8 @@
         self.assertRaises(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.assertRaises(InvalidValue, field.validate, -5.4)
-
-
 def test_suite():
     suite = makeSuite(FloatTest)
-    suite.addTest(makeSuite(EnumeratedFloatTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_intfield.py 1.5 => 1.6 ===
--- Zope3/src/zope/schema/tests/test_intfield.py:1.5	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_intfield.py	Sat Apr 24 19:21:06 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import main, makeSuite
-from zope.schema import Int, EnumeratedInt
+from zope.schema import Int
 from zope.schema.interfaces import RequiredMissing, InvalidValue
 from zope.schema.interfaces import TooSmall, TooBig
 from zope.schema.tests.test_field import FieldTestBase
@@ -77,23 +77,8 @@
         self.assertRaises(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.assertRaises(InvalidValue, field.validate, 4)
-
-
 def test_suite():
     suite = makeSuite(IntTest)
-    suite.addTest(makeSuite(EnumeratedIntTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_states.py 1.5 => 1.6 ===
--- Zope3/src/zope/schema/tests/test_states.py:1.5	Sun Aug 17 02:09:20 2003
+++ Zope3/src/zope/schema/tests/test_states.py	Sat Apr 24 19:21:06 2004
@@ -11,38 +11,40 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Tests of the states example.
 
-"""Tests of the states example."""
-
+$Id$
+"""
 import unittest
 
 from zope.interface import Interface
 from zope.interface.verify import verifyObject
 
 from zope.schema import vocabulary
+from zope.schema import Choice
 from zope.schema.interfaces import IVocabulary
 from zope.schema.tests import states
 
 
 class IBirthInfo(Interface):
-    state1 = vocabulary.VocabularyField(
+    state1 = Choice(
         title=u'State of Birth',
         description=u'The state in which you were born.',
         vocabulary="states",
         default="AL",
         )
-    state2 = vocabulary.VocabularyField(
+    state2 = Choice(
         title=u'State of Birth',
         description=u'The state in which you were born.',
         vocabulary="states",
         default="AL",
         )
-    state3 = vocabulary.VocabularyField(
+    state3 = Choice(
         title=u'Favorite State',
         description=u'The state you like the most.',
         vocabulary=states.StateVocabulary(),
         )
-    state4 = vocabulary.VocabularyField(
+    state4 = Choice(
         title=u"Name",
         description=u"The name of your new state",
         vocabulary="states",


=== Zope3/src/zope/schema/tests/test_strfield.py 1.4 => 1.5 ===
--- Zope3/src/zope/schema/tests/test_strfield.py:1.4	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_strfield.py	Sat Apr 24 19:21:06 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 from unittest import TestSuite, main, makeSuite
-from zope.schema import Bytes, BytesLine, Text, TextLine, EnumeratedTextLine
+from zope.schema import Bytes, BytesLine, Text, TextLine
 from zope.schema.interfaces import ValidationError
 from zope.schema.interfaces import RequiredMissing, InvalidValue
 from zope.schema.interfaces import TooShort, TooLong, ConstraintNotSatisfied
@@ -85,7 +85,7 @@
         self.assertRaises(TooLong, field.validate, self._convert('999999999'))
 
 
-class MultiLine:
+class MultiLine(object):
 
     def test_newlines(self):
         field = self._Field_Factory(title=u'Str field')
@@ -110,7 +110,7 @@
         field = self._Field_Factory()
         self.assertRaises(ValidationError, field.validate, 'hello')
 
-class SingleLine:
+class SingleLine(object):
 
     def test_newlines(self):
         field = self._Field_Factory(title=u'Str field')
@@ -124,20 +124,6 @@
 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.assertRaises(InvalidValue, field.validate, self._convert('blah'))
-
 
 def test_suite():
     return TestSuite((
@@ -145,7 +131,6 @@
         makeSuite(TextTest),
         makeSuite(LineTest),
         makeSuite(TextLineTest),
-        makeSuite(EnumeratedTextLineTest),
         ))
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_tuplefield.py 1.7 => 1.8 ===
--- Zope3/src/zope/schema/tests/test_tuplefield.py:1.7	Sun Apr 11 06:35:17 2004
+++ Zope3/src/zope/schema/tests/test_tuplefield.py	Sat Apr 24 19:21:06 2004
@@ -11,7 +11,8 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""
+"""Sequence and Tuple field tests.
+
 This set of tests exercises both Tuple and Sequence.  The only
 behavior Tuple adds to sequence is the restriction of the type
 to 'tuple'.
@@ -24,35 +25,10 @@
 from zope.schema import Field, Sequence, Tuple, Int
 from zope.schema.interfaces import IField
 from zope.schema.interfaces import NotAContainer, RequiredMissing
-from zope.schema.interfaces import WrongContainedType, WrongType
+from zope.schema.interfaces import WrongContainedType, WrongType, NotUnique
 from zope.schema.interfaces import TooShort, TooLong
 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.assertRaises(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.assertRaises(RequiredMissing, field.validate, None)
-
-
 class TupleTest(FieldTestBase):
     """Test the Tuple Field."""
 
@@ -136,10 +112,15 @@
             implements(IField)
         Tuple(value_type=FakeField())
 
+    def testUnique(self):
+        field = self._Field_Factory(title=u'test field', description=u'',
+                                    readonly=False, required=True, unique=True)
+        field.validate((1, 2))
+        self.assertRaises(NotUnique, field.validate, (1, 2, 1))
+
 def test_suite():
     suite = TestSuite()
     suite.addTest(makeSuite(TupleTest))
-    suite.addTest(makeSuite(SequenceTest))
     return suite
 
 if __name__ == '__main__':


=== Zope3/src/zope/schema/tests/test_vocabulary.py 1.13 => 1.14 ===
--- Zope3/src/zope/schema/tests/test_vocabulary.py:1.13	Fri Mar  5 17:09:32 2004
+++ Zope3/src/zope/schema/tests/test_vocabulary.py	Sat Apr 24 19:21:06 2004
@@ -11,9 +11,10 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
+"""Test of the Vocabulary and related support APIs.
 
-"""Test of the VocabularyField and related support APIs."""
-
+$Id$
+"""
 import unittest
 
 from zope.interface.verify import verifyObject
@@ -21,7 +22,6 @@
 
 from zope.schema import interfaces
 from zope.schema import vocabulary
-from zope.testing.doctestunit import DocTestSuite
 
 
 class DummyRegistry(vocabulary.VocabularyRegistry):
@@ -63,6 +63,9 @@
 class SampleVocabulary:
     implements(interfaces.IVocabulary)
 
+    def __iter__(self):
+        return iter([self.getTerm(x) for x in range(0, 10)])
+
     def __contains__(self, value):
         return 0 <= value < 10
 
@@ -81,131 +84,6 @@
         raise LookupError("no such value: %r" % value)
 
 
-class VocabularyFieldTests(BaseTest):
-    """Tests of the VocabularyField implementation."""
-
-    def check_preconstructed(self, cls, okval, badval):
-        v = SampleVocabulary()
-        field = cls(vocabulary=v)
-        self.assert_(field.vocabulary is v)
-        self.assert_(field.vocabularyName is None)
-        bound = field.bind(None)
-        self.assert_(bound.vocabulary is v)
-        self.assert_(bound.vocabularyName is None)
-        bound.default = okval
-        self.assertEqual(bound.default, okval)
-        self.assertRaises(interfaces.ValidationError,
-                          setattr, bound, "default", badval)
-
-    def test_preconstructed_vocabulary(self):
-        self.check_preconstructed(vocabulary.VocabularyField, 1, 42)
-
-    def test_preconstructed_vocabulary_multi(self):
-        self.check_preconstructed(vocabulary.VocabularyListField,
-                                  [1], [1, 42])
-
-    def check_constructed(self, cls, okval, badval):
-        vocabulary.setVocabularyRegistry(DummyRegistry())
-        field = cls(vocabulary="vocab")
-        self.assert_(field.vocabulary is None)
-        self.assertEqual(field.vocabularyName, "vocab")
-        o = object()
-        bound = field.bind(o)
-        self.assert_(isinstance(bound.vocabulary, SampleVocabulary))
-        bound.default = okval
-        self.assertEqual(bound.default, okval)
-        self.assertRaises(interfaces.ValidationError,
-                          setattr, bound, "default", badval)
-
-    def test_constructed_vocabulary(self):
-        self.check_constructed(vocabulary.VocabularyField, 1, 42)
-
-    def test_constructed_vocabulary_multi(self):
-        self.check_constructed(vocabulary.VocabularyListField,
-                               [1], [1, 42])
-
-    def test_abstract_base_class_is_abstract(self):
-        self.assertRaises(NotImplementedError,
-                          vocabulary.VocabularyMultiField, vocabulary="foo")
-
-    def check_constructed_vocabulary_multi_default(self, cls):
-        # make sure these don't die during construction:
-        cls(vocabulary="testvocab", default=None)
-        L = []
-        unbound = cls(vocabulary="testvocab", default=L)
-        self.assertEqual(L, unbound.default)
-        self.assert_(unbound.default is not L)
-        # XXX this does, but not clear that it should:
-        self.assertRaises(ValueError,
-                          cls, vocabulary="testvocab", default=['xy'])
-
-    def test_constructed_vocabulary_bag_default(self):
-        self.check_constructed_vocabulary_multi_default(
-            vocabulary.VocabularyBagField)
-
-    def test_constructed_vocabulary_list_default(self):
-        self.check_constructed_vocabulary_multi_default(
-            vocabulary.VocabularyListField)
-
-    def test_constructed_vocabulary_set_default(self):
-        self.check_constructed_vocabulary_multi_default(
-            vocabulary.VocabularySetField)
-
-    def test_constructed_vocabulary_unique_list_default(self):
-        self.check_constructed_vocabulary_multi_default(
-            vocabulary.VocabularyUniqueListField)
-
-    def check_min_length_ok(self, v, cls):
-        field = cls(vocabulary=v, min_length=1)
-        self.assertEqual(field.min_length, 1)
-        field.validate([0])
-
-    def test_min_length_ok(self):
-        v = SampleVocabulary()
-        self.check_min_length_ok(v, vocabulary.VocabularyBagField)
-        self.check_min_length_ok(v, vocabulary.VocabularyListField)
-        self.check_min_length_ok(v, vocabulary.VocabularySetField)
-        self.check_min_length_ok(v, vocabulary.VocabularyUniqueListField)
-
-    def check_min_length_short(self, v, cls):
-        field = cls(vocabulary=v, min_length=1)
-        self.assertEqual(field.min_length, 1)
-        self.assertRaises(interfaces.ValidationError,
-                          field.validate, [])
-
-    def test_min_length_short(self):
-        v = SampleVocabulary()
-        self.check_min_length_short(v, vocabulary.VocabularyBagField)
-        self.check_min_length_short(v, vocabulary.VocabularyListField)
-        self.check_min_length_short(v, vocabulary.VocabularySetField)
-        self.check_min_length_short(v, vocabulary.VocabularyUniqueListField)
-
-    def check_max_length_ok(self, v, cls):
-        field = cls(vocabulary=v, min_length=2)
-        self.assertEqual(field.min_length, 2)
-        field.validate([0, 1])
-
-    def test_max_length_ok(self):
-        v = SampleVocabulary()
-        self.check_max_length_ok(v, vocabulary.VocabularyBagField)
-        self.check_max_length_ok(v, vocabulary.VocabularyListField)
-        self.check_max_length_ok(v, vocabulary.VocabularySetField)
-        self.check_max_length_ok(v, vocabulary.VocabularyUniqueListField)
-
-    def check_max_length_long(self, v, cls):
-        field = cls(vocabulary=v, max_length=2)
-        self.assertEqual(field.max_length, 2)
-        self.assertRaises(interfaces.ValidationError,
-                          field.validate, [0, 1, 2])
-
-    def test_max_length_long(self):
-        v = SampleVocabulary()
-        self.check_max_length_long(v, vocabulary.VocabularyBagField)
-        self.check_max_length_long(v, vocabulary.VocabularyListField)
-        self.check_max_length_long(v, vocabulary.VocabularySetField)
-        self.check_max_length_long(v, vocabulary.VocabularyUniqueListField)
-
-
 class SimpleVocabularyTests(unittest.TestCase):
 
     list_vocab = vocabulary.SimpleVocabulary.fromValues([1, 2, 3])
@@ -292,9 +170,7 @@
 
 def test_suite():
     suite = unittest.makeSuite(RegistryTests)
-    suite.addTest(unittest.makeSuite(VocabularyFieldTests))
     suite.addTest(unittest.makeSuite(SimpleVocabularyTests))
-    suite.addTest(DocTestSuite("zope.schema.vocabulary"))
     return suite
 
 if __name__ == "__main__":




More information about the Zope3-Checkins mailing list