예제 #1
0
    def runTest(self):
        @handler("foo", filter=True)
        def onFOO():
            pass

        @handler("bar")
        def onBAR():
            pass

        def onTEST():
            pass

        manager = Manager()

        manager.add(onFOO)
        manager.add(onBAR)
        self.assertTrue(onFOO in manager._globals)
        self.assertTrue(onBAR in manager._globals)

        manager.add(onFOO, ("*", "foo"))
        manager.add(onBAR, ("*", "bar"))
        self.assertTrue(onFOO in manager.channels[("*", "foo")])
        self.assertTrue(onBAR in manager.channels[("*", "bar")])

        self.assertFalse(onTEST in manager._globals)

        manager.remove(onFOO)
        self.assertTrue(onFOO not in manager._handlers)

        manager.remove(onBAR, ("*", "bar"))
        self.assertTrue(("*", "bar") not in manager.channels)
        self.assertTrue(onBAR in manager._globals)
        manager.remove(onBAR)
        self.assertTrue(onBAR not in manager._handlers)

        self.assertEquals(len(manager._handlers), 0)
예제 #2
0
    def runTest(self):
        import time

        self.flag = False
        self.foo = False

        @handler("test")
        def onTEST(test, time, stop=False):
            test.flag = True

        @handler("test")
        def onFOO(test, time, stop=False):
            test.foo = True

        @handler("bar")
        def onBAR(test, time):
            pass

        @handler(filter=True)
        def onSTOP(*args, **kwargs):
            return kwargs.get("stop", False)

        manager = Manager()

        manager.add(onSTOP)
        manager.add(onTEST, ("*", "test"))
        manager.add(onFOO, ("*", "test"))
        manager.add(onBAR, ("*", "bar"))

        self.assertTrue(onSTOP in manager._globals)
        self.assertTrue(onTEST in manager.channels[("*", "test")])
        self.assertTrue(onFOO in manager.channels[("*", "test")])
        self.assertTrue(onBAR in manager.channels[("*", "bar")])
        self.assertEquals(len(manager._handlers), 3)

        manager.push(Test(self, time.time()), "test")
        manager.flush()
        self.assertTrue(self.flag == True)
        self.flag = False
        self.assertTrue(self.foo == True)
        self.foo = False

        self.assertEquals(len(manager), 0)

        manager.send(Test(self, time.time()), "test")
        self.assertTrue(self.flag == True)
        self.flag = False

        manager.send(Test(self, time.time()), "test")
        self.assertTrue(self.flag == True)
        self.flag = False

        manager.send(Test(self, time.time(), stop=True), "test")
        self.assertTrue(self.flag == False)

        manager.remove(onSTOP)
        manager.remove(onTEST, ("*", "test"))
        manager.remove(onFOO, ("*", "test"))
        manager.remove(onBAR, ("*", "bar"))

        self.assertEquals(len(manager._handlers), 0)