[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py Full coverage for z.c.config.toargs.

Tres Seaver cvs-admin at zope.org
Wed May 9 20:23:19 UTC 2012


Log message for revision 125775:
  Full coverage for z.c.config.toargs.

Changed:
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py

-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py	2012-05-09 20:23:10 UTC (rev 125774)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py	2012-05-09 20:23:15 UTC (rev 125775)
@@ -1632,9 +1632,71 @@
         from zope.configuration.config import toargs
         return toargs(*args, **kw)
 
-    #TODO coverage
+    def test_w_empty_schema_no_data(self):
+        from zope.interface import Interface
+        class ISchema(Interface):
+            pass
+        context = FauxContext()
+        self.assertEqual(self._callFUT(context, ISchema, {}), {})
 
+    def test_w_empty_schema_w_data_no_kwargs_allowed(self):
+        from zope.configuration.exceptions import ConfigurationError
+        from zope.interface import Interface
+        class ISchema(Interface):
+            pass
+        context = FauxContext()
+        self.assertRaises(ConfigurationError,
+                          self._callFUT, context, ISchema, {'a': 'b'})
 
+    def test_w_empty_schema_w_data_w_kwargs_allowed(self):
+        from zope.interface import Interface
+        class ISchema(Interface):
+            pass
+        ISchema.setTaggedValue('keyword_arguments', True)
+        context = FauxContext()
+        self.assertEqual(self._callFUT(context, ISchema, {'a': 'b'}),
+                         {'a': 'b'})
+
+    def test_w_keyword_sub(self):
+        from zope.interface import Interface
+        from zope.schema import Text
+        class ISchema(Interface):
+            for_ = Text()
+        context = FauxContext()
+        self.assertEqual(self._callFUT(context, ISchema, {'for': 'foo'}),
+                         {'for_': 'foo'})
+
+    def test_w_field_missing_no_default(self):
+        from zope.interface import Interface
+        from zope.schema import Text
+        from zope.configuration.exceptions import ConfigurationError
+        class ISchema(Interface):
+            w_default = Text()
+        context = FauxContext()
+        self.assertRaises(ConfigurationError,
+                          self._callFUT, context, ISchema, {})
+
+    def test_w_field_missing_but_default(self):
+        from zope.interface import Interface
+        from zope.schema import Text
+        from zope.configuration._compat import u
+        class ISchema(Interface):
+            w_default = Text(default=u('default'))
+        context = FauxContext()
+        self.assertEqual(self._callFUT(context, ISchema, {}),
+                         {'w_default': 'default'})
+
+    def test_w_invalid_value(self):
+        from zope.interface import Interface
+        from zope.schema import Int
+        from zope.configuration.exceptions import ConfigurationError
+        class ISchema(Interface):
+            count = Int(min=0)
+        context = FauxContext()
+        self.assertRaises(ConfigurationError,
+                         self._callFUT, context, ISchema, {'count': '-1'})
+
+
 class Test_expand_action(unittest.TestCase):
 
     def _callFUT(self, *args, **kw):



More information about the checkins mailing list