[Zodb-checkins] CVS: Packages/ZConfig/tests - support.py:1.1 test_config.py:1.5 test_loader.py:1.14 test_schema.py:1.14 test_zopeschema.py:1.4

Fred L. Drake, Jr. fred@zope.com
Wed, 19 Feb 2003 10:54:16 -0500


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

Modified Files:
	test_config.py test_loader.py test_schema.py 
	test_zopeschema.py 
Added Files:
	support.py 
Log Message:
Refactor common support into a separate module.

=== Added File Packages/ZConfig/tests/support.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################

"""Support code shared among the tests."""

import os
import StringIO
import unittest
import urllib

import ZConfig

from ZConfig.loader import ConfigLoader
from ZConfig.url import urljoin


try:
    __file__
except NameError:
    import sys
    __file__ = sys.argv[0]

d = os.path.abspath(os.path.join(os.path.dirname(__file__), "input"))
CONFIG_BASE = "file://%s/" % urllib.pathname2url(d)


class TestBase(unittest.TestCase):
    """Utility methods which can be used with the schema support."""

    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 = urljoin(CONFIG_BASE, relurl)
        self.schema = ZConfig.loadSchema(self.url)
        self.assert_(self.schema.issection())
        return self.schema

    def load_schema_text(self, text, url=None):
        sio = StringIO.StringIO(text)
        self.schema = ZConfig.loadSchemaFile(sio, url)
        return self.schema

    def load_config(self, schema, conf_url, num_handlers=0):
        conf_url = urljoin(CONFIG_BASE, 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, num_handlers=0, url=None):
        sio = StringIO.StringIO(text)
        self.conf, self.handlers = ZConfig.loadConfigFile(schema, sio, url)
        self.assertEqual(len(self.handlers), num_handlers)
        return self.conf


=== Packages/ZConfig/tests/test_config.py 1.4 => 1.5 ===
--- Packages/ZConfig/tests/test_config.py:1.4	Mon Jan 13 12:30:51 2003
+++ Packages/ZConfig/tests/test_config.py	Wed Feb 19 10:54:15 2003
@@ -17,21 +17,13 @@
 import StringIO
 import tempfile
 import unittest
-import urllib
 
 import ZConfig
 
 from ZConfig.Context import Context
 from ZConfig.url import urljoin
 
-try:
-    __file__
-except NameError:
-    import sys
-    __file__ = sys.argv[0]
-
-d = os.path.abspath(os.path.join(os.path.dirname(__file__), "input"))
-CONFIG_BASE = "file://%s/" % urllib.pathname2url(d)
+from ZConfig.tests.support import CONFIG_BASE
 
 
 class TestBase(unittest.TestCase):


=== Packages/ZConfig/tests/test_loader.py 1.13 => 1.14 ===
--- Packages/ZConfig/tests/test_loader.py:1.13	Mon Jan 27 15:59:18 2003
+++ Packages/ZConfig/tests/test_loader.py	Wed Feb 19 10:54:15 2003
@@ -25,7 +25,7 @@
 import ZConfig.loader
 import ZConfig.url
 
-from ZConfig.tests.test_config import CONFIG_BASE
+from ZConfig.tests.support import CONFIG_BASE
 
 
 try:


=== Packages/ZConfig/tests/test_schema.py 1.13 => 1.14 ===
--- Packages/ZConfig/tests/test_schema.py:1.13	Thu Feb  6 11:45:37 2003
+++ Packages/ZConfig/tests/test_schema.py	Wed Feb 19 10:54:15 2003
@@ -18,9 +18,7 @@
 
 import ZConfig
 
-from ZConfig.loader import ConfigLoader
-from ZConfig.url import urljoin
-from ZConfig.tests.test_config import CONFIG_BASE
+from ZConfig.tests.support import TestBase
 
 
 def uppercase(value):
@@ -35,39 +33,7 @@
         self.length = len(value)
 
 
-class BaseSchemaTest(unittest.TestCase):
-    """Utility methods which can be used with the schema support."""
-
-    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 = urljoin(CONFIG_BASE, relurl)
-        self.schema = ZConfig.loadSchema(self.url)
-        self.assert_(self.schema.issection())
-        return self.schema
-
-    def load_schema_text(self, text, url=None):
-        sio = StringIO.StringIO(text)
-        self.schema = ZConfig.loadSchemaFile(sio, url)
-        return self.schema
-
-    def load_config(self, schema, conf_url, num_handlers=0):
-        conf_url = urljoin(CONFIG_BASE, 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, num_handlers=0, url=None):
-        sio = StringIO.StringIO(text)
-        self.conf, self.handlers = ZConfig.loadConfigFile(schema, sio, url)
-        self.assertEqual(len(self.handlers), num_handlers)
-        return self.conf
-
-
-class SchemaTestCase(BaseSchemaTest):
+class SchemaTestCase(TestBase):
     """Tests of the basic schema support itself."""
 
     def test_minimal_schema(self):


=== Packages/ZConfig/tests/test_zopeschema.py 1.3 => 1.4 ===
--- Packages/ZConfig/tests/test_zopeschema.py:1.3	Fri Jan  3 17:38:30 2003
+++ Packages/ZConfig/tests/test_zopeschema.py	Wed Feb 19 10:54:15 2003
@@ -16,7 +16,7 @@
 import unittest
 import ZConfig
 
-from ZConfig.tests.test_schema import BaseSchemaTest
+from ZConfig.tests.support import TestBase
 
 try:
     True
@@ -114,7 +114,7 @@
     pos, kw = _get_arglist(arglist)
     return klass, pos, kw
 
-class ZopeSchemaTestCase(BaseSchemaTest):
+class ZopeSchemaTestCase(TestBase):
 
     # tests