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

Fred L. Drake, Jr. fred@zope.com
Wed, 11 Dec 2002 22:13:25 -0500


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

Modified Files:
      Tag: zconfig-schema-devel-branch
	test_schema.py 
Log Message:
Add a test of application-defined section types.


=== Packages/ZConfig/tests/test_schema.py 1.1.2.5 => 1.1.2.6 ===
--- Packages/ZConfig/tests/test_schema.py:1.1.2.5	Wed Dec 11 17:38:49 2002
+++ Packages/ZConfig/tests/test_schema.py	Wed Dec 11 22:13:25 2002
@@ -27,6 +27,15 @@
     def convert(self, value):
         return str(value).upper()
 
+class appsection:
+    def convert(self, value):
+        return MySection(value)
+
+class MySection:
+    def __init__(self, value):
+        self.conf = value
+        self.length = len(value)
+
 
 class SchemaTestCase(unittest.TestCase):
 
@@ -86,6 +95,28 @@
         eq(conf.b, 'ABC')
         eq(conf.c, ['UPP', 'ER', 'CASE'])
         eq(conf.d, ['NOT', 'LOWER', 'CASE'])
+
+    def test_app_sectiontype(self):
+        schema = self.load_schema_text(
+            "<schema>"
+            "  <section names='sect' type='%s.appsection'"
+            "           sectiontype='foo'>"
+            "    <key name='sample' type='integer'>"
+            "      <default>345</default>"
+            "      </key>"
+            "    </section>"
+            "</schema>"
+            % __name__)
+        conf = self.load_config_text(schema,
+                                     "<foo sect>\n"
+                                     "  sample 42\n"
+                                     "</foo>")
+        self.assertEqual(len(conf), 1)
+        o1 = conf[0]
+        self.assert_(isinstance(o1, MySection))
+        self.assertEqual(o1.length, 1)
+        self.assertEqual(o1.conf.sample, 42)
+        self.assert_(isinstance(conf.sect, MySection))
 
     def test_multivalued_keys(self):
         schema = self.load_schema_text(