[Zope-Checkins] CVS: Packages/ZConfig/tests - test_schema.py:1.1.2.1

Fred L. Drake, Jr. fred@zope.com
Wed, 11 Dec 2002 15:10:53 -0500


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

Added Files:
      Tag: zconfig-schema-devel-branch
	test_schema.py 
Log Message:
Some preliminary tests of the schema support.

=== Added File Packages/ZConfig/tests/test_schema.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Tests of ZConfig schemas."""

import unittest
import urlparse

import ZConfig

from ZConfig.loader import ConfigLoader
from ZConfig.tests.test_config import CONFIG_BASE


class SchemaTestCase(unittest.TestCase):
    def load(self, relurl):
        self.url = urlparse.urljoin(CONFIG_BASE, relurl)
        self.schema = ZConfig.loadSchema(self.url)
        self.assert_(self.schema.issection())
        return self.schema

    def loadBoth(self, schema_url, conf_url):
        schema = self.load(schema_url)
        conf_url = urlparse.urljoin(CONFIG_BASE, conf_url)
        conf = ConfigLoader(schema).loadURL(conf_url)
        return schema, conf

    def test_minimal_schema(self):
        schema = self.load("minimal.xml")
        self.assertEqual(len(schema), 0)
        self.assertEqual(schema.getchildnames(), [])
        self.assertRaises(IndexError,
                          lambda schema=schema: schema[0])
        self.assertRaises(ZConfig.ConfigurationError,
                          schema.getinfo, "foo")

    def test_simple(self):
        schema, conf = self.loadBoth("simple.xml", "simple.conf")
        eq = self.assertEqual
        eq(conf.var1, 'abc')
        eq(conf.int_var, 12)
        eq(conf.float_var, 12.02)
        eq(conf.neg_int, -2)

        check = self.assert_
        check(conf.true_var_1)
        check(conf.true_var_2)
        check(conf.true_var_3)
        check(not conf.false_var_1)
        check(not conf.false_var_2)
        check(not conf.false_var_3)


def test_suite():
    return unittest.makeSuite(SchemaTestCase)

if __name__ == '__main__':
    unittest.main(defaultTest='test_suite')