[Zope3-checkins] CVS: Zope3/src/zope/schema/tests - test_vocabulary.py:1.10

Fred L. Drake, Jr. fred@zope.com
Fri, 13 Jun 2003 11:33:36 -0400


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

Modified Files:
	test_vocabulary.py 
Log Message:
Added tests for each of the vocabulary field types that describe
containers of values that check
- that empty sets of values don't cause errors if the vocabulary isn't
  available yet
- that getting the default value returns an equivalent copy rather
  than the original mutable value


=== Zope3/src/zope/schema/tests/test_vocabulary.py 1.9 => 1.10 ===
--- Zope3/src/zope/schema/tests/test_vocabulary.py:1.9	Wed Jun  4 14:09:07 2003
+++ Zope3/src/zope/schema/tests/test_vocabulary.py	Fri Jun 13 11:33:35 2003
@@ -127,6 +127,33 @@
         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)
+
 
 class SimpleVocabularyTests(unittest.TestCase):