Commit 66dc2027 authored by 's avatar

more tests and minor changes

parent 57c09032
......@@ -38,7 +38,7 @@ def fromZ3Interface(z3i):
return _bridges[z3i]
name = z3i.getName()
bases = [fromZ3Interface(x) for x in z3i.getBases()]
bases = [ fromZ3Interface(x) for x in z3i.getBases() ]
attrs = {}
for k, v in z3i.namesAndDescriptions():
......@@ -48,14 +48,12 @@ def fromZ3Interface(z3i):
elif isinstance(v, Z3_Attribute):
v = fromZ3Attribute(v)
#TODO bridge Fields to Attributes?
attrs[k] = v
# XXX: Note that we pass the original interface's __module__;
# we may live to regret that.
z2i = Z2_InterfaceClass(name=name,
bases=bases,
bases=tuple(bases),
attrs=attrs,
__doc__=z3i.getDoc(),
__module__=z3i.__module__)
......@@ -73,21 +71,21 @@ def fromZ3Attribute(z3a):
return Z2_Attribute(z3a.getName(), z3a.getDoc())
def fromZ3Method(z3m):
""" Return a Zope 2 interface method corresponding to 'z3a'.
""" Return a Zope 2 interface method corresponding to 'z3m'.
o 'z3a' must be a Zope 3 interface method.
o 'z3m' must be a Zope 3 interface method.
"""
if not isinstance(z3m, Z3_Method):
raise ValueError, 'Not a Zope 3 interface method!'
m = Z2_Method(z3m.getName(), z3m.getDoc())
z2m = Z2_Method(z3m.getName(), z3m.getDoc())
sig = z3m.getSignatureInfo()
m.positional = sig['positional']
m.required = sig['required']
m.optional = sig['optional']
m.varargs = sig['varargs']
m.kwargs = sig['kwargs']
return m
z2m.positional = sig['positional']
z2m.required = sig['required']
z2m.optional = sig['optional']
z2m.varargs = sig['varargs']
z2m.kwargs = sig['kwargs']
return z2m
def createZope3Bridge(zope3, package, name):
# Map a Zope 3 interface into a Zope2 interface, seated within 'package'
......
......@@ -12,6 +12,7 @@ interfaces from the two generations:
>>> from zope.interface import Interface as Z3_Interface
>>> from zope.interface import Attribute as Z3_Attribute
>>> from zope.schema import List, TextLine
An empty interface
......@@ -21,11 +22,39 @@ An empty interface
... pass
>>> from Interface.bridge import fromZ3Interface
>>> converted = fromZ3Interface(IEmpty)
>>> IEmptyConverted = fromZ3Interface(IEmpty)
>>> Z2_Interface.isEqualOrExtendedBy(converted)
>>> Z2_Interface.isEqualOrExtendedBy(IEmptyConverted)
1
>>> len(converted.names())
>>> len(IEmptyConverted.names())
0
Bases
-----
>>> class IBase(Z3_Interface):
... pass
>>> class IDerived(IBase):
... pass
>>> IBase.getBases() == (Z3_Interface,)
True
>>> IDerived.getBases() == (IBase,)
True
>>> IDerived.extends(IBase)
True
>>> IDerived.extends(IEmpty)
False
>>> IBaseConverted = fromZ3Interface(IBase)
>>> IDerivedConverted = fromZ3Interface(IDerived)
>>> IBaseConverted.getBases() == (Z2_Interface,)
True
>>> IDerivedConverted.getBases() == (IBaseConverted,)
True
>>> IDerivedConverted.extends(IBaseConverted)
1
>>> IDerivedConverted.extends(IEmptyConverted)
0
......@@ -64,6 +93,42 @@ Attributes
'Another attribute'
Fields
------
>>> class IFields(Z3_Interface):
... one = TextLine(title=u'one', description=u'One field')
... another = List(title=u'another', description=u'Another field',
... value_type = TextLine())
>>> converted = fromZ3Interface(IFields)
>>> Z2_Interface.isEqualOrExtendedBy(converted)
1
>>> len(converted.names())
2
>>> 'one' in converted.names()
True
>>> 'another' in converted.names()
True
>>> one = converted.getDescriptionFor('one')
>>> isinstance(one, Z2_Attribute)
True
>>> one.getName()
'one'
>>> one.getDoc()
u'one\n\nOne field'
>>> another = converted.getDescriptionFor('another')
>>> isinstance(another, Z2_Attribute)
True
>>> another.getName()
'another'
>>> another.getDoc()
u'another\n\nAnother field'
Methods
-------
......@@ -91,6 +156,8 @@ Methods
'one'
>>> one.getDoc()
'One method.'
>>> one.getSignatureString()
'()'
>>> another = converted.getDescriptionFor('another')
>>> isinstance(another, Z2_Method)
......@@ -99,6 +166,8 @@ Methods
'another'
>>> another.getDoc()
'Another method, taking arguments.'
>>> another.getSignatureString()
'(arg1, arg2)'
Invalid parameters
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment