コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
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)