def testSimple(self): class I(Interface): def f(): pass class C: pass self.assertRaises(BrokenImplementation, implements, C, I) C.f=lambda self: None implements(C, I) self.assertEqual(C.__implements__, I)
def testAdd(self): class I(Interface): def f(): pass class I2(Interface): def g(): pass class C: __implements__=I2 self.assertRaises(BrokenImplementation, implements, C, I) self.assertRaises(BrokenImplementation, implements, C, I2) C.f=lambda self: None implements(C, I) self.assertEqual(C.__implements__, (I2, I)) self.assertRaises(BrokenImplementation, implements, C, I2) C.g=C.f implements(C, I) implements(C, I2)
from Interface.Implements import implements class Publisher: pass class Subscriber: message = "" def handleMessage(self, msg): self.message = msg class ITestMessage(Interface): pass class TestMessage: pass implements(TestMessage,ITestMessage) class ExtendString(str): pass class Test(TestCase): def setUp(self): ec=self.eventChannel = EventChannel() publisher=self.publisher=Publisher() ec.registerEvent("test", publisher, str) subscriber=self.subscriber=Subscriber() ec.subscribeToEvent("test",subscriber,str)