[Zope3-checkins] CVS: Zope/lib/python/ZConfig/tests - runtests.py:1.2.2.1 test_datatypes.py:1.4.2.1 test_loader.py:1.9.2.2 test_schema.py:1.7.2.2

Fred L. Drake, Jr. fred@zope.com
Thu, 23 Jan 2003 17:02:31 -0500


Update of /cvs-repository/Zope/lib/python/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv32578/tests

Modified Files:
      Tag: chrism-install-branch
	runtests.py test_datatypes.py test_loader.py test_schema.py 
Log Message:
Merge from the ZConfig trunk.

=== Zope/lib/python/ZConfig/tests/runtests.py 1.2 => 1.2.2.1 ===
--- Zope/lib/python/ZConfig/tests/runtests.py:1.2	Fri Jan  3 16:05:56 2003
+++ Zope/lib/python/ZConfig/tests/runtests.py	Thu Jan 23 17:01:57 2003
@@ -26,7 +26,7 @@
 TOPDIR = os.path.dirname(os.path.dirname(TESTDIR))
 
 if TOPDIR not in sys.path:
-    sys.path.append(TOPDIR)
+    sys.path.insert(0, TOPDIR)
 
 def load_tests(name):
     name = "ZConfig.tests." + name


=== Zope/lib/python/ZConfig/tests/test_datatypes.py 1.4 => 1.4.2.1 ===
--- Zope/lib/python/ZConfig/tests/test_datatypes.py:1.4	Tue Jan  7 18:09:19 2003
+++ Zope/lib/python/ZConfig/tests/test_datatypes.py	Thu Jan 23 17:01:57 2003
@@ -202,6 +202,9 @@
         eq(convert('hostname'),          'hostname')
         eq(convert('hostname.com'),      'hostname.com')
         eq(convert('www.hostname.com'),  'www.hostname.com')
+        eq(convert('HOSTNAME'),          'hostname')
+        eq(convert('HOSTNAME.COM'),      'hostname.com')
+        eq(convert('WWW.HOSTNAME.COM'),  'www.hostname.com')
         eq(convert('127.0.0.1'),         '127.0.0.1')
         raises(ValueError, convert,  '1hostnamewithleadingnumeric')
         raises(ValueError, convert,  '255.255')


=== Zope/lib/python/ZConfig/tests/test_loader.py 1.9.2.1 => 1.9.2.2 ===
--- Zope/lib/python/ZConfig/tests/test_loader.py:1.9.2.1	Mon Jan 13 20:17:31 2003
+++ Zope/lib/python/ZConfig/tests/test_loader.py	Thu Jan 23 17:01:57 2003
@@ -15,6 +15,7 @@
 
 import os.path
 import sys
+import tempfile
 import unittest
 
 from StringIO import StringIO
@@ -128,6 +129,23 @@
         self.assertEqual(
             ZConfig.url.urldefrag("file:/abc/def#frag"),
             ("file:///abc/def", "frag"))
+
+    def test_nonexistant_file(self):
+        fn = tempfile.mktemp()
+        schema = ZConfig.loadSchemaFile(StringIO("<schema/>"))
+        self.assertRaises(ZConfig.ConfigurationError,
+                          ZConfig.loadSchema, fn)
+        self.assertRaises(ZConfig.ConfigurationError,
+                          ZConfig.loadConfig, schema, fn)
+        self.assertRaises(ZConfig.ConfigurationError,
+                          ZConfig.loadConfigFile, schema,
+                          StringIO("%include " + fn))
+        self.assertRaises(ZConfig.ConfigurationError,
+                          ZConfig.loadSchema,
+                          "http://www.zope.org/no-such-document/")
+        self.assertRaises(ZConfig.ConfigurationError,
+                          ZConfig.loadConfig, schema,
+                          "http://www.zope.org/no-such-document/")
 
 
 def test_suite():


=== Zope/lib/python/ZConfig/tests/test_schema.py 1.7.2.1 => 1.7.2.2 ===
--- Zope/lib/python/ZConfig/tests/test_schema.py:1.7.2.1	Mon Jan 13 20:17:31 2003
+++ Zope/lib/python/ZConfig/tests/test_schema.py	Thu Jan 23 17:01:57 2003
@@ -226,6 +226,38 @@
         self.assertEqual(conf.c, [41, 42, 43])
         self.assertEqual(conf.d, [])
 
+    def test_multikey_required(self):
+        schema = self.load_schema_text("<schema>"
+                                       "  <multikey name='k' required='yes'/>"
+                                       "</schema>")
+        self.assertRaises(ZConfig.ConfigurationError,
+                          self.load_config_text, schema, "")
+
+    def test_multisection_required(self):
+        schema = self.load_schema_text(
+            "<schema>"
+            "  <sectiontype name='s'/>"
+            "  <multisection name='*' attribute='s' type='s' required='yes'/>"
+            "</schema>")
+        self.assertRaises(ZConfig.ConfigurationError,
+                          self.load_config_text, schema, "")
+
+    def test_key_required_but_missing(self):
+        schema = self.load_schema_text("<schema>"
+                                       "  <key name='k' required='yes'/>"
+                                       "</schema>")
+        self.assertRaises(ZConfig.ConfigurationError,
+                          self.load_config_text, schema, "")
+
+    def test_section_required_but_missing(self):
+        schema = self.load_schema_text("<schema>"
+                                       "  <sectiontype name='k'/>"
+                                       "  <section name='k' type='k'"
+                                       "           required='yes'/>"
+                                       "</schema>")
+        self.assertRaises(ZConfig.ConfigurationError,
+                          self.load_config_text, schema, "")
+
     def test_key_default_element(self):
         self.assertRaises(ZConfig.SchemaError, self.load_schema_text,
                           "<schema>"
@@ -606,6 +638,27 @@
                           "  <sectiontype name='t2' extends='t1'"
                           "               keytype='integer'/>"
                           "</schema>")
+
+    def test_schema_keytype(self):
+        schema = self.load_schema_text("<schema keytype='ipaddr-or-hostname'>"
+                                       "  <key name='+' attribute='table'"
+                                       "       datatype='ipaddr-or-hostname'/>"
+                                       "</schema>")
+        conf = self.load_config_text(schema,
+                                     "host.example.com 127.0.0.1\n"
+                                     "www.example.org 127.0.0.2\n")
+        table = conf.table
+        self.assertEqual(len(table), 2)
+        L = table.items()
+        L.sort()
+        self.assertEqual(L, [("host.example.com", "127.0.0.1"),
+                             ("www.example.org", "127.0.0.2")])
+
+        self.assertRaises(ZConfig.ConfigurationError,
+                          self.load_config_text, schema, "abc.  127.0.0.1")
+
+    def test_datatype_casesensitivity(self):
+        self.load_schema_text("<schema datatype='NULL'/>")
 
 
 def test_suite():