[Zope3-checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.6

Fred L. Drake, Jr. fred@zope.com
Mon, 6 Jan 2003 17:30:26 -0500


Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv25601/tests

Modified Files:
	test_schema.py 
Log Message:
Implement sectiontype extension (for ZODB).

=== Packages/ZConfig/tests/test_schema.py 1.5 => 1.6 ===
--- Packages/ZConfig/tests/test_schema.py:1.5	Mon Jan  6 16:07:40 2003
+++ Packages/ZConfig/tests/test_schema.py	Mon Jan  6 17:30:21 2003
@@ -568,6 +568,55 @@
                                      "<sect 1 />")
         self.assertEqual(len(conf.things), 1)
 
+    def test_sectiontype_extension(self):
+        schema = self.load_schema_text("<schema>"
+                                       "  <sectiontype type='t1'>"
+                                       "    <key name='k1'/>"
+                                       "  </sectiontype>"
+                                       "  <sectiontype type='t2' extends='t1'>"
+                                       "    <key name='k2'/>"
+                                       "  </sectiontype>"
+                                       "  <section name='s' type='t2'/>"
+                                       "</schema>")
+        conf = self.load_config_text(schema,
+                                     "<t2 s>\n"
+                                     "  k1 k1-value\n"
+                                     "  k2 k2-value\n"
+                                     "</t2>")
+        self.assertEqual(conf.s.k1, "k1-value")
+        self.assertEqual(conf.s.k2, "k2-value")
+
+    def test_sectiontype_extension_errors(self):
+        # cannot override key from base
+        self.assertRaises(ZConfig.SchemaError, self.load_schema_text,
+                          "<schema>"
+                          "  <sectiontype type='t1'>"
+                          "    <key name='k1'/>"
+                          "  </sectiontype>"
+                          "  <sectiontype type='t2' extends='t1'>"
+                          "    <key name='k1'/>"
+                          "  </sectiontype>"
+                          "</schema>")
+        # cannot extend non-existing section
+        self.assertRaises(ZConfig.SchemaError, self.load_schema_text,
+                          "<schema>"
+                          "  <sectiontype type='t2' extends='t1'/>"
+                          "</schema>")
+        # cannot extend abstract type
+        self.assertRaises(ZConfig.SchemaError, self.load_schema_text,
+                          "<schema>"
+                          "  <sectiongroup type='t1'>"
+                          "    <sectiontype type='t2' extends='t1'/>"
+                          "  </sectiongroup>"
+                          "</schema>")
+        # cannot specify keytype
+        self.assertRaises(ZConfig.SchemaError, self.load_schema_text,
+                          "<schema>"
+                          "  <sectiontype type='t1' keytype='string'/>"
+                          "  <sectiontype type='t2' extends='t1'"
+                          "               keytype='integer'/>"
+                          "</schema>")
+
 
 def test_suite():
     return unittest.makeSuite(SchemaTestCase)