Esempio n. 1
0
def test_listener_removal():
    """
    tests to make sure we can remove listeners as appropriate.
    """

    ee = Event_emitter()

    # Some functions to pass to the EE
    def first():
        return 1

    def second():
        return 2

    def third():
        return 3

    # If you want un-closed functions, you unfortunately have to
    # call ee without using decorator styles.
    ee.on("event", first)
    ee.on("event", second)
    ee.on("event", third)

    nt.assert_equal(ee._events["event"], [first, second, third])

    # uses the function itself to find/remove listener
    ee.remove_listener("event", second)
    nt.assert_equal(ee._events["event"], [first, third])

    # remove ALL the listeners!
    ee.remove_all_listeners("event")
    nt.assert_equal(ee._events["event"], [])
Esempio n. 2
0
File: tests.py Progetto: Zearin/pyee
def test_listener_removal():
    """
    tests to make sure we can remove listeners as appropriate.
    """

    ee = Event_emitter()


    #Some functions to pass to the EE
    def first():
        return 1

    ee.on('event', first)

    @ee.on('event')
    def second():
        return 2

    @ee.on('event')
    def third():
        return 3

    def fourth():
        return 4

    ee.on('event', fourth)

    nt.assert_equal(ee._events['event'], [first, second, third, fourth])

    #uses the function itself to find/remove listener
    ee.remove_listener('event', second)
    nt.assert_equal(ee._events['event'], [first, third, fourth])

    #uses the function itself to find/remove listener
    ee.remove_listener('event', first)
    nt.assert_equal(ee._events['event'], [third, fourth])

    #remove ALL the listeners!
    ee.remove_all_listeners('event')
    nt.assert_equal(ee._events['event'], [])
Esempio n. 3
0
def test_listener_removal():
    """Tests that we can remove listeners (as appropriate).
    """

    ee = Event_emitter()

    #Some functions to pass to the EE
    def first():
        return 1

    ee.on('event', first)

    @ee.on('event')
    def second():
        return 2

    @ee.on('event')
    def third():
        return 3

    def fourth():
        return 4

    ee.on('event', fourth)

    nt.assert_equal(ee._events['event'], [first, second, third, fourth])

    # uses the function itself to find/remove listener
    ee.remove_listener('event', second)
    nt.assert_equal(ee._events['event'], [first, third, fourth])

    # uses the function itself to find/remove listener
    ee.remove_listener('event', first)
    nt.assert_equal(ee._events['event'], [third, fourth])

    # Remove ALL listeners!
    ee.remove_all_listeners('event')
    nt.assert_equal(ee._events['event'], [])