[Zope-Checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.1.2.18
Fred L. Drake, Jr.
fred@zope.com
Fri, 13 Dec 2002 15:38:59 -0500
Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv32011/tests
Modified Files:
Tag: zconfig-schema-devel-branch
test_schema.py
Log Message:
Several changes:
- ZConfig.loader.SchemaLoader takes an optional datatype registry,
allowing it to be given a pre-loaded or app-specific package of
types.
- ZConfig.datatypes acts as a standard type registry, though it
provides the default implementation.
- Don't call handler functions as the configuration object is built
up; save them up and allow the application decide when to call
them. *** This changes the return values from the .loadURL() and
.loadFile() methods of SchemaLoader. ***
- ZConfig.schema.SchemaParser only uses types looked up from the
provided type registry; it provides no default implementations.
=== Packages/ZConfig/tests/test_schema.py 1.1.2.17 => 1.1.2.18 ===
--- Packages/ZConfig/tests/test_schema.py:1.1.2.17 Fri Dec 13 13:44:54 2002
+++ Packages/ZConfig/tests/test_schema.py Fri Dec 13 15:38:58 2002
@@ -25,6 +25,9 @@
from ZConfig.tests.test_config import CONFIG_BASE
+types = ZConfig.datatypes.Registry()
+
+
def uppercase(value):
return str(value).upper()
@@ -254,7 +257,7 @@
# datatype tests
def test_datatype_basickey(self):
- convert = ZConfig.datatypes.get("basic-key")
+ convert = types.get("basic-key")
eq = self.assertEqual
raises = self.assertRaises
@@ -269,7 +272,7 @@
raises(ValueError, convert, "")
def test_datatype_boolean(self):
- convert = ZConfig.datatypes.get("boolean")
+ convert = types.get("boolean")
check = self.assert_
raises = self.assertRaises
@@ -285,7 +288,7 @@
raises(ValueError, convert, 'junk')
def test_datatype_identifier(self):
- convert = ZConfig.datatypes.get("identifier")
+ convert = types.get("identifier")
eq = self.assertEqual
raises = self.assertRaises
@@ -302,7 +305,7 @@
raises(ValueError, convert, "")
def test_datatype_integer(self):
- convert = ZConfig.datatypes.get("integer")
+ convert = types.get("integer")
eq = self.assertEqual
raises = self.assertRaises
@@ -327,13 +330,13 @@
raises(ValueError, convert, '123-')
def test_datatype_locale(self):
- convert = ZConfig.datatypes.get("locale")
+ convert = types.get("locale")
# Python supports "C" even when the _locale module is not available
self.assertEqual(convert("C"), "C")
self.assertRaises(ValueError, convert, "no-such-locale")
def test_datatype_port(self):
- convert = ZConfig.datatypes.get("port-number")
+ convert = types.get("port-number")
eq = self.assertEqual
raises = self.assertRaises
@@ -362,15 +365,20 @@
def load_schema_text(self, text):
sio = StringIO.StringIO(text)
- return ZConfig.loadSchemaFile(sio)
+ self.schema = ZConfig.loadSchemaFile(sio)
+ return self.schema
- def load_config(self, schema, conf_url):
+ def load_config(self, schema, conf_url, num_handlers=0):
conf_url = urlparse.urljoin(CONFIG_BASE, conf_url)
- return ConfigLoader(schema).loadURL(conf_url)
+ self.conf, self.handlers = ConfigLoader(schema).loadURL(conf_url)
+ self.assertEqual(len(self.handlers), num_handlers)
+ return self.conf
- def load_config_text(self, schema, text):
+ def load_config_text(self, schema, text, num_handlers=0):
sio = StringIO.StringIO(text)
- return ConfigLoader(schema).loadFile(sio)
+ self.conf, self.handlers = ZConfig.loadConfigFile(schema, sio)
+ self.assertEqual(len(self.handlers), num_handlers)
+ return self.conf
def test_suite():