[Zodb-checkins] CVS: Packages/SFTPGateway/src/ZConfig/tests - test_schema.py:1.24 runtests.py:1.4

Fred L. Drake, Jr. fred at zope.com
Fri Jan 2 00:35:34 EST 2004


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

Modified Files:
	test_schema.py runtests.py 
Log Message:
allow "keytype" to be overridden in derived section types


=== Packages/SFTPGateway/src/ZConfig/tests/test_schema.py 1.23 => 1.24 ===
--- Packages/SFTPGateway/src/ZConfig/tests/test_schema.py:1.23	Fri Jan  2 00:27:17 2004
+++ Packages/SFTPGateway/src/ZConfig/tests/test_schema.py	Fri Jan  2 00:35:02 2004
@@ -659,14 +659,6 @@
                             <sectiontype name='t2' extends='t1'/>
                           </schema>
                           """)
-        # cannot specify keytype
-        self.assertRaises(ZConfig.SchemaError, self.load_schema_text, """\
-                          <schema>
-                            <sectiontype name='t1' keytype='string'/>
-                            <sectiontype name='t2' extends='t1'
-                                         keytype='integer'/>
-                          </schema>
-                          """)
 
     def test_sectiontype_derived_keytype(self):
         # make sure that a derived section type inherits the keytype
@@ -689,6 +681,34 @@
             """)
         self.assertEqual(conf.foo.foo, "bar")
         self.assertEqual(conf.foo.Foo, "BAR")
+
+    def test_sectiontype_override_keytype(self):
+        schema = self.load_schema_text("""\
+            <schema>
+              <sectiontype name='base' keytype='identifier' >
+                <key name='+' attribute='map' />
+              </sectiontype>
+              <sectiontype name='derived' keytype='ipaddr-or-hostname'
+                           extends='base' />
+              <section name='*' type='base' attribute='base' />
+              <section name='*' type='derived' attribute='derived' />
+            </schema>
+            """)
+        conf = self.load_config_text(schema, """\
+            <base>
+              ident1 foo
+              Ident2 bar
+            </base>
+            <derived>
+              EXAMPLE.COM foo
+            </derived>
+            """)
+        L = conf.base.map.items()
+        L.sort()
+        self.assertEqual(L, [("Ident2", "bar"), ("ident1", "foo")])
+        L = conf.derived.map.items()
+        L.sort()
+        self.assertEqual(L, [("example.com", "foo")])
 
     def test_sectiontype_inherited_datatype(self):
         schema = self.load_schema_text("""\


=== Packages/SFTPGateway/src/ZConfig/tests/runtests.py 1.3 => 1.4 ===
--- Packages/SFTPGateway/src/ZConfig/tests/runtests.py:1.3	Mon Jan 20 17:53:50 2003
+++ Packages/SFTPGateway/src/ZConfig/tests/runtests.py	Fri Jan  2 00:35:02 2004
@@ -23,23 +23,40 @@
 
 TESTDIR = os.path.dirname(os.path.abspath(__file__))
 
-TOPDIR = os.path.dirname(os.path.dirname(TESTDIR))
+PKGDIR = os.path.dirname(TESTDIR) # the ZConfig package directory
+TOPDIR = os.path.dirname(PKGDIR)
 
-if TOPDIR not in sys.path:
-    sys.path.insert(0, TOPDIR)
+COMPONENTS = os.path.join(PKGDIR, "components")
 
-def load_tests(name):
-    name = "ZConfig.tests." + name
+TESTDIRS = {
+    "ZConfig.tests": TESTDIR,
+    "ZConfig.components.basic.tests": os.path.join(COMPONENTS,
+                                                   "basic", "tests"),
+    }
+
+try:
+    import logging
+except ImportError:
+    print >>sys.stderr, \
+          "'logging' not available; skipping logger component tests"
+else:
+    TESTDIRS["ZConfig.components.logger.tests"] = os.path.join(
+        COMPONENTS, "logger", "tests")
+
+
+def load_tests(pkgname, name):
+    name = "%s.%s" % (pkgname, name)
     __import__(name)
     mod = sys.modules[name]
     return mod.test_suite()
 
 def test_suite():
     L = []
-    for fn in os.listdir(TESTDIR):
-        name, ext = os.path.splitext(fn)
-        if name[:4] == "test" and ext == ".py":
-            L.append(load_tests(name))
+    for pkgname, path in TESTDIRS.items():
+        for fn in os.listdir(path):
+            name, ext = os.path.splitext(fn)
+            if name[:4] == "test" and ext == ".py":
+                L.append(load_tests(pkgname, name))
     if len(L) == 1:
         return L[0]
     else:
@@ -49,4 +66,6 @@
         return suite
 
 if __name__ == "__main__":
+    if TOPDIR not in sys.path:
+        sys.path.insert(0, TOPDIR)
     unittest.main(defaultTest="test_suite")




More information about the Zodb-checkins mailing list