Пример #1
0
    def testOnetimeDispatch(self):
        d = EventDispatcher()
        msg = Element(("ns", "message"))
        cb = CallbackTracker()

        d.addOnetimeObserver("/message", cb.call)
        d.dispatch(msg)
        self.assertEquals(cb.called, 1)
        d.dispatch(msg)
        self.assertEquals(cb.called, 1)
Пример #2
0
    def test_cleanUpOnetimeEventObserver(self):
        """
        Test observer clean-up after onetime named events.
        """

        d = EventDispatcher()
        cb = CallbackTracker()

        d.addOnetimeObserver('//event/test', cb.call)
        d.dispatch(None, '//event/test')
        self.assertEqual(1, cb.called)
        self.assertEqual(0, len(d._eventObservers.pop(0)))
Пример #3
0
    def test_cleanUpOnetimeXPathObserver(self):
        """
        Test observer clean-up after onetime XPath events.
        """

        d = EventDispatcher()
        cb = CallbackTracker()
        msg = Element((None, "message"))

        d.addOnetimeObserver('/message', cb.call)
        d.dispatch(msg)
        self.assertEqual(1, cb.called)
        self.assertEqual(0, len(d._xpathObservers.pop(0)))
Пример #4
0
    def test_addOnetimeObserverInDispatch(self):
        """
        Test for registration of a onetime observer during dispatch.
        """
        d = EventDispatcher()
        msg = Element(("ns", "message"))
        cb = CallbackTracker()

        def onMessage(msg):
            d.addOnetimeObserver("/message", cb.call)

        d.addOnetimeObserver("/message", onMessage)

        d.dispatch(msg)
        self.assertEquals(cb.called, 0)

        d.dispatch(msg)
        self.assertEquals(cb.called, 1)

        d.dispatch(msg)
        self.assertEquals(cb.called, 1)