[Checkins] SVN: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/ Moar coverage for z.s._f.Choice.

Tres Seaver cvs-admin at zope.org
Mon Apr 23 21:59:59 UTC 2012


Log message for revision 125262:
  Moar coverage for z.s._f.Choice.

Changed:
  U   zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_field.py
  U   zope.schema/branches/tseaver-test_cleanup/src/zope/schema/tests/test__field.py

-=-
Modified: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_field.py
===================================================================
--- zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_field.py	2012-04-23 21:59:51 UTC (rev 125261)
+++ zope.schema/branches/tseaver-test_cleanup/src/zope/schema/_field.py	2012-04-23 21:59:56 UTC (rev 125262)
@@ -300,8 +300,8 @@
     def __init__(self, values=None, vocabulary=None, source=None, **kw):
         """Initialize object."""
         if vocabulary is not None:
-            if (not isinstance(vocabulary, string_types)
-                    and not IBaseVocabulary.providedBy(vocabulary)):
+            if (not isinstance(vocabulary, string_types) and
+                not IBaseVocabulary.providedBy(vocabulary)):
                 raise ValueError('vocabulary must be a string or implement '
                                  'IBaseVocabulary')
             if source is not None:

Modified: zope.schema/branches/tseaver-test_cleanup/src/zope/schema/tests/test__field.py
===================================================================
--- zope.schema/branches/tseaver-test_cleanup/src/zope/schema/tests/test__field.py	2012-04-23 21:59:51 UTC (rev 125261)
+++ zope.schema/branches/tseaver-test_cleanup/src/zope/schema/tests/test__field.py	2012-04-23 21:59:56 UTC (rev 125262)
@@ -162,6 +162,33 @@
     def _makeOne(self, *args, **kw):
         return self._getTargetClass()(*args, **kw)
 
+    def test_ctor_wo_values_vocabulary_or_source(self):
+        self.assertRaises(ValueError, self._makeOne)
+
+    def test_ctor_invalid_vocabulary(self):
+        self.assertRaises(ValueError, self._makeOne, vocabulary=object())
+
+    def test_ctor_invalid_source(self):
+        self.assertRaises(ValueError, self._makeOne, source=object())
+
+    def test_ctor_both_vocabulary_and_source(self):
+        self.assertRaises(ValueError,
+                          self._makeOne, vocabulary='voc.name', source=object())
+
+    def test_ctor_both_vocabulary_and_values(self):
+        self.assertRaises(ValueError,
+                          self._makeOne, vocabulary='voc.name', values=[1, 2])
+
+    def test_ctor_w_values(self):
+        from zope.schema.vocabulary import SimpleVocabulary
+        choose = self._makeOne(values=[1, 2])
+        self.assertTrue(isinstance(choose.vocabulary, SimpleVocabulary))
+        self.assertEqual(sorted(choose.vocabulary.by_value.keys()), [1, 2])
+
+    def test_ctor_w_named_vocabulary(self):
+        choose = self._makeOne(vocabulary='voc.name')
+        self.assertEqual(choose.vocabularyName, 'voc.name')
+
     def test_fromUnicode_miss(self):
         from zope.schema.interfaces import ConstraintNotSatisfied
         from zope.schema._compat import u



More information about the checkins mailing list