[Zope-Checkins] CVS: StandaloneZConfig/ZConfig/tests - test_schema.py:1.25

Fred L. Drake, Jr. fred at zope.com
Tue Mar 16 15:47:25 EST 2004


Update of /cvs-repository/StandaloneZConfig/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv31115/tests

Modified Files:
	test_schema.py 
Log Message:
- make it possible to provide defaults for <multikey name="+"> and
  <key name="+">; keys need to be provided for each default value
- fix bug in converting an empty section that contained a
  <multikey name="+">
- document <default> element in reference manual and DTD
- more tests


=== StandaloneZConfig/ZConfig/tests/test_schema.py 1.24 => 1.25 ===
--- StandaloneZConfig/ZConfig/tests/test_schema.py:1.24	Fri Jan  2 00:35:02 2004
+++ StandaloneZConfig/ZConfig/tests/test_schema.py	Tue Mar 16 15:47:25 2004
@@ -406,7 +406,7 @@
         conf = self.load_config_text(schema, "some-key 42")
         self.assertEqual(conf.keymap, {'some-key': 42})
 
-    def test_arbitrary_multikey(self):
+    def test_arbitrary_multikey_required(self):
         schema = self.load_schema_text("""\
             <schema>
               <multikey name='+' required='yes' attribute='keymap'
@@ -418,6 +418,81 @@
                                      some-key 43
                                      """)
         self.assertEqual(conf.keymap, {'some-key': [42, 43]})
+
+    def test_arbitrary_multikey_optional(self):
+        schema = self.load_schema_text("""\
+            <schema>
+              <sectiontype name='sect'>
+                <multikey name='+' attribute='keymap'/>
+              </sectiontype>
+              <section name='+' type='sect' attribute='stuff'/>
+            </schema>
+            """)
+        conf = self.load_config_text(schema, """\
+                                     <sect foo>
+                                       some-key 42
+                                       some-key 43
+                                     </sect>
+                                     """)
+        self.assertEqual(conf.stuff.keymap, {'some-key': ['42', '43']})
+
+    def test_arbitrary_multikey_optional_empty(self):
+        schema = self.load_schema_text("""\
+            <schema>
+              <sectiontype name='sect'>
+                <multikey name='+' attribute='keymap'/>
+              </sectiontype>
+              <section name='+' type='sect' attribute='stuff'/>
+            </schema>
+            """)
+        conf = self.load_config_text(schema, "<sect foo/>")
+        self.assertEqual(conf.stuff.keymap, {})
+
+    def test_arbitrary_multikey_with_defaults(self):
+        schema = self.load_schema_text("""\
+            <schema>
+              <multikey name='+' attribute='keymap'>
+                <default key='a'>value-a1</default>
+                <default key='a'>value-a2</default>
+                <default key='b'>value-b</default>
+              </multikey>
+            </schema>
+            """)
+        conf = self.load_config_text(schema, "")
+        self.assertEqual(conf.keymap, {'a': ['value-a1', 'value-a2'],
+                                       'b': ['value-b']})
+
+    def test_arbitrary_multikey_with_unkeyed_default(self):
+        self.assertRaises(ZConfig.SchemaError,
+                          self.load_schema_text, """\
+                          <schema>
+                            <multikey name='+' attribute='keymap'>
+                              <default>value-a1</default>
+                            </multikey>
+                          </schema>
+                          """)
+
+    def test_arbitrary_key_with_defaults(self):
+        schema = self.load_schema_text("""\
+            <schema>
+              <key name='+' attribute='keymap'>
+                <default key='a'>value-a</default>
+                <default key='b'>value-b</default>
+              </key>
+            </schema>
+            """)
+        conf = self.load_config_text(schema, "")
+        self.assertEqual(conf.keymap, {'a': 'value-a', 'b': 'value-b'})
+
+    def test_arbitrary_key_with_unkeyed_default(self):
+        self.assertRaises(ZConfig.SchemaError,
+                          self.load_schema_text, """\
+                          <schema>
+                            <key name='+' attribute='keymap'>
+                              <default>value-a1</default>
+                            </key>
+                          </schema>
+                          """)
 
     def test_arbitrary_keys_with_others(self):
         schema = self.load_schema_text("""\




More information about the Zope-Checkins mailing list