[Zodb-checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.1.2.3
Fred L. Drake, Jr.
fred@zope.com
Wed, 11 Dec 2002 16:25:20 -0500
Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv31131/tests
Modified Files:
Tag: zconfig-schema-devel-branch
test_schema.py
Log Message:
More tests, some cleanup.
=== Packages/ZConfig/tests/test_schema.py 1.1.2.2 => 1.1.2.3 ===
--- Packages/ZConfig/tests/test_schema.py:1.1.2.2 Wed Dec 11 15:31:22 2002
+++ Packages/ZConfig/tests/test_schema.py Wed Dec 11 16:25:19 2002
@@ -28,7 +28,7 @@
# tests
def test_minimal_schema(self):
- schema = self.loadtext("<schema/>")
+ schema = self.load_schema_text("<schema/>")
self.assertEqual(len(schema), 0)
self.assertEqual(schema.getchildnames(), [])
self.assertRaises(IndexError,
@@ -37,7 +37,7 @@
schema.getinfo, "foo")
def test_simple(self):
- schema, conf = self.loadBoth("simple.xml", "simple.conf")
+ schema, conf = self.load_both("simple.xml", "simple.conf")
eq = self.assertEqual
eq(conf.var1, 'abc')
eq(conf.int_var, 12)
@@ -52,23 +52,46 @@
check(not conf.false_var_2)
check(not conf.false_var_3)
+ def test_multivalued_keys(self):
+ schema = self.load_schema_text(
+ "<schema>"
+ " <key name='a' minOccurs='2' maxOccurs='5' />"
+ " <key name='b' minOccurs='2' maxOccurs='2' >"
+ " <default>first</default>"
+ " <default>second</default>"
+ " </key>"
+ "</schema>")
+ conf = self.load_config_text(schema,
+ "a foo\n"
+ "a bar\n"
+ )
+ self.assertEqual(conf.a, ['foo', 'bar'])
+ self.assertEqual(conf.b, ['first', 'second'])
+
# utilities
- def load(self, relurl):
+ def load_both(self, schema_url, conf_url):
+ schema = self.load_schema(schema_url)
+ conf = self.load_config(schema, conf_url)
+ return schema, conf
+
+ def load_schema(self, relurl):
self.url = urlparse.urljoin(CONFIG_BASE, relurl)
self.schema = ZConfig.loadSchema(self.url)
self.assert_(self.schema.issection())
return self.schema
- def loadtext(self, text):
+ def load_schema_text(self, text):
sio = StringIO.StringIO(text)
return ZConfig.loadSchemaFile(sio)
- def loadBoth(self, schema_url, conf_url):
- schema = self.load(schema_url)
+ def load_config(self, schema, conf_url):
conf_url = urlparse.urljoin(CONFIG_BASE, conf_url)
- conf = ConfigLoader(schema).loadURL(conf_url)
- return schema, conf
+ return ConfigLoader(schema).loadURL(conf_url)
+
+ def load_config_text(self, schema, text):
+ sio = StringIO.StringIO(text)
+ return ConfigLoader(schema).loadFile(sio)
def test_suite():