Commit 35697378 authored by Michel Pelletier's avatar Michel Pelletier

Interface Unit tests in trunk

parent 77e859e0
import Interface
class C:
def m1(self, a, b):
"return 1"
return 1
def m2(self, a, b):
"return 2"
return 2
# testInstancesOfClassImplements
IC=Interface.impliedInterface(C)
C.__implements__=IC
class I1(Interface.Base):
def ma(self):
"blah"
class I2(I1): pass
class I3(Interface.Base): pass
class I4(Interface.Base): pass
class A(I1.deferred()):
__implements__=I1
class B:
__implements__=I2, I3
class D(A, B): pass
class E(A, B):
__implements__ = A.__implements__, C.__implements__
class FooInterface(Interface.Base):
""" This is an Abstract Base Class """
foobar = Interface.Attribute("fuzzed over beyond all recognition")
def aMethod(self, foo, bar, bingo):
""" This is aMethod """
def anotherMethod(self, foo=6, bar="where you get sloshed", bingo=(1,3,)):
""" This is anotherMethod """
def wammy(self, zip, *argues):
""" yadda yadda """
def useless(self, **keywords):
""" useless code is fun! """
class Foo:
""" A concrete class """
__implements__ = FooInterface,
foobar = "yeah"
def aMethod(self, foo, bar, bingo):
""" This is aMethod """
return "barf!"
def anotherMethod(self, foo=6, bar="where you get sloshed", bingo=(1,3,)):
""" This is anotherMethod """
return "barf!"
def wammy(self, zip, *argues):
""" yadda yadda """
return "barf!"
def useless(self, **keywords):
""" useless code is fun! """
return "barf!"
foo_instance = Foo()
class Blah:
pass
FunInterface = Interface.new('FunInterface')
BarInterface = Interface.new('BarInterface', [FunInterface])
BobInterface = Interface.new('BobInterface')
BazInterface = Interface.new('BazInterface', [BobInterface, BarInterface])
# usage from lib/python:
#
# python unittest.py Interface.unittests.suite
import unittest
import Interface
from unitfixtures import * # hehehe
class InterfaceTests(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testClassImplements(self):
assert IC.isImplementedByInstancesOf(C)
assert I1.isImplementedByInstancesOf(A)
assert I1.isImplementedByInstancesOf(B)
assert not I1.isImplementedByInstancesOf(C)
assert I1.isImplementedByInstancesOf(D)
assert I1.isImplementedByInstancesOf(E)
assert not I2.isImplementedByInstancesOf(A)
assert I2.isImplementedByInstancesOf(B)
assert not I2.isImplementedByInstancesOf(C)
assert not I2.isImplementedByInstancesOf(D)
assert not I2.isImplementedByInstancesOf(E)
def testClassImplements(self):
assert IC.isImplementedBy(C())
assert I1.isImplementedBy(A())
assert I1.isImplementedBy(B())
assert not I1.isImplementedBy(C())
assert I1.isImplementedBy(D())
assert I1.isImplementedBy(E())
assert not I2.isImplementedBy(A())
assert I2.isImplementedBy(B())
assert not I2.isImplementedBy(C())
assert not I2.isImplementedBy(D())
assert not I2.isImplementedBy(E())
def testDeferredClass(self):
a = A()
self.assertRaises(Interface.BrokenImplementation, a.ma)
def testInterfaceExtendsInterface(self):
assert BazInterface.extends(BobInterface)
assert BazInterface.extends(BarInterface)
assert BazInterface.extends(FunInterface)
assert not BobInterface.extends(FunInterface)
assert not BobInterface.extends(BarInterface)
assert BarInterface.extends(FunInterface)
assert not BarInterface.extends(BazInterface)
def testVerifyImplementation(self):
assert Interface.verify_class_implementation(FooInterface, Foo)
assert Interface.verify_class_implementation(Interface.InterfaceInterface, I1)
def suite():
return unittest.makeSuite(InterfaceTests)
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