[Zodb-checkins] CVS: Packages/ZConfig/tests - test_zopeschema.py:1.1.2.1
Chris McDonough
chrism@zope.com
Thu, 19 Dec 2002 15:41:40 -0500
Update of /cvs-repository/Packages/ZConfig/tests
In directory cvs.zope.org:/tmp/cvs-serv28565
Added Files:
Tag: zconfig-schema-devel-branch
test_zopeschema.py
Log Message:
Checkpoint checkin (tests fail).
=== Added File Packages/ZConfig/tests/test_zopeschema.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 ZConfig
from ZConfig.tests.test_schema import SchemaTestCase
class StreamHandler:
pass
class Formatter:
pass
def _get_arglist(s):
pos = []
kw = {}
args = s.split(',')
args = filter(None, args)
while args:
arg = args.pop(0)
try:
if '=' in arg:
k,v=arg.split('=', 1)
k = k.strip()
v = v.strip()
kw[k] = eval(v)
else:
arg = arg.strip()
pos.append(eval(arg))
except SyntaxError:
if not args:
raise
args[0] = '%s, %s' % (arg, args[0])
return pos, kw
def _get_classandargs(constructor):
klass, args = parse_constructor(constructor)
pos, kw = get_arglist(args)
return klass, pos, kw
def _parse_constructor(value):
parenmsg = (
'Invalid constructor (unbalanced parenthesis in "%s")' % value
)
openparen = value.find('(')
if openparen < 0:
raise ValueError(parenmsg)
klass = value[:openparen]
if not value.endswith(')'):
raise ValueError(parenmsg)
arglist = value[openparen+1:-1]
return klass, arglist
def _importer(name):
if not "." in name:
raise ValueError("unloadable datatype name: " + `name`)
components = name.split('.')
start = components[0]
g = globals()
package = __import__(start, g, g)
modulenames = [start]
for component in components[1:]:
modulenames.append(component)
try:
package = getattr(package, component)
except AttributeError:
n = '.'.join(modulenames)
package = __import__(n, g, g, component)
return package
def ipaddr(value):
if value is None:
return
import socket
try:
socket.gethostbyaddr(value)
except socket.error:
socket.gethostbyname(value)
def directory(value):
assert(os.path.exists(value))
return value
def dirname(value):
assert os.path.exists(os.path.dirname(value))
return value
def constructor(value):
klass, arglist = _parse_constructor(value)
_importer(klass)
pos, kw = _get_arglist(arglist)
return klass, pos, kw
class ZopeSchemaTestCase(SchemaTestCase):
# tests
def test_load_zope_schema(self):
schema = self.load_schema('zope.xml')
conf = self.load_config(schema, 'zope-allpopulated.conf')
def test_suite():
return unittest.makeSuite(ZopeSchemaTestCase)
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')