[Zodb-checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.4

Fred L. Drake, Jr. fred@zope.com
Mon, 6 Jan 2003 14:35:48 -0500


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

Modified Files:
	test_schema.py 
Log Message:
Values now have location information stored along with the actual text of the
value.  This is used to improve error reporting to the end user.


=== Packages/ZConfig/tests/test_schema.py 1.3 => 1.4 ===
--- Packages/ZConfig/tests/test_schema.py:1.3	Mon Jan  6 13:19:41 2003
+++ Packages/ZConfig/tests/test_schema.py	Mon Jan  6 14:35:43 2003
@@ -49,9 +49,9 @@
         self.assert_(self.schema.issection())
         return self.schema
 
-    def load_schema_text(self, text):
+    def load_schema_text(self, text, url=None):
         sio = StringIO.StringIO(text)
-        self.schema = ZConfig.loadSchemaFile(sio)
+        self.schema = ZConfig.loadSchemaFile(sio, url)
         return self.schema
 
     def load_config(self, schema, conf_url, num_handlers=0):
@@ -60,9 +60,9 @@
         self.assertEqual(len(self.handlers), num_handlers)
         return self.conf
 
-    def load_config_text(self, schema, text, num_handlers=0):
+    def load_config_text(self, schema, text, num_handlers=0, url=None):
         sio = StringIO.StringIO(text)
-        self.conf, self.handlers = ZConfig.loadConfigFile(schema, sio)
+        self.conf, self.handlers = ZConfig.loadConfigFile(schema, sio, url)
         self.assertEqual(len(self.handlers), num_handlers)
         return self.conf
 
@@ -532,6 +532,31 @@
         conf = self.load_config_text(t, "<s/>")
         self.assertEqual(conf.tkey, "tkey-default")
         self.assertEqual(conf.section.skey, "skey-default")
+
+    def test_datatype_conversion_error(self):
+        schema_url = "file:///tmp/fake-url-1.xml"
+        config_url = "file:///tmp/fake-url-2.xml"
+        schema = self.load_schema_text("<schema>\n"
+                                       "  <key name='key' default='bogus'"
+                                       "       datatype='integer'/>"
+                                       "</schema>", url=schema_url)
+        e = self.get_data_conversion_error(
+            schema, "", config_url)
+        self.assertEqual(e.url, schema_url)
+        self.assertEqual(e.lineno, 2)
+
+        e = self.get_data_conversion_error(
+            schema, "# comment\n\n key splat\n", config_url)
+        self.assertEqual(e.url, config_url)
+        self.assertEqual(e.lineno, 3)
+
+    def get_data_conversion_error(self, schema, src, url):
+        try:
+            self.load_config_text(schema, src, url=url)
+        except ZConfig.DataConversionError, e:
+            return e
+        else:
+            self.fail("expected ZConfig.DataConversionError")
 
 
 def test_suite():