示例#1
0
    def test_all(self):
        o = Observable()

        args = ("undefevent", "param1", "param2")
        self.assertRaises(Exception, o.on, *args)

        o.define_events("add", "remove")

        # Add listeners
        def handler1(item):
            item["h1"] = True

        def handler2(item):
            item["h2"] = True

        o.on("add", handler1, handler2)
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
        self.assertTrue(item["h2"])

        # Remove listener
        o.un("add", handler2)
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
        self.assertFalse(item.has_key("h2"))

        # Suspend events
        o.suspend_events()
        item = {}
        o.fire("add", item)
        self.assertFalse(item.has_key("h1"))

        # Resume events
        o.resume_events()
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
示例#2
0
 def test_ways_to_add_listeners(self):
     o = Observable()
     o.define_events("add", "remove", "apply")
     o.on(add=None, remove=None)
示例#3
0
 def __init__(self):
     Observable.__init__(self)
     self.define_events("msg_event")
示例#4
0
    def test_all(self):
        o = Observable()

        args = ("undefevent", "param1", "param2")
        self.assertRaises(Exception, o.on, *args)

        o.define_events("add", "remove")

        # Add listeners
        def handler1(item):
            item["h1"] = True
        def handler2(item):
            item["h2"] = True

        o.on("add", handler1, handler2)
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
        self.assertTrue(item["h2"])


        # Remove listener
        o.un("add", handler2)
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
        self.assertFalse(item.has_key("h2"))


        # Suspend events
        o.suspend_events()
        item = {}
        o.fire("add", item)
        self.assertFalse(item.has_key("h1"))


        # Resume events
        o.resume_events()
        item = {}
        o.fire("add", item)
        self.assertTrue(item["h1"])
示例#5
0
 def test_ways_to_add_listeners(self):
     o = Observable()
     o.define_events("add", "remove", "apply")
     o.on(add=None, remove=None)
示例#6
0
 def __init__(self):
     Observable.__init__(self)
     self.define_events("msg_event")