Beispiel #1
0
def test_emit():
    """
    Test to show that event_emitters fire properly.
    """
    ee = Event_emitter()

    #Used in a decorator style.
    @ee.on('event')
    def event_handler(data):
        nt.assert_equals(data, 'emitter is emitted!')
        # Raise exception to prove it fired.
        raise ItWorkedException

    # Some nose bullshit to check for the firings
    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event', 'emitter is emitted!')
Beispiel #2
0
def test_listeners():
    """
    Test to make sure that the listeners method gives you access to the listeners array.
    """
    ee = Event_emitter()
    @ee.on('event')
    def event_handler():
        pass

    def raiser():
        raise ItWorkedException

    l = ee.listeners('event')
    l[0] = raiser

    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event')
Beispiel #3
0
def test_listeners():
    """Test that `listeners()` gives you access to the listeners array.
    """

    ee = Event_emitter()

    @ee.on('event')
    def event_handler():
        pass

    def raiser():
        raise ItWorkedException

    l = ee.listeners('event')
    l[0] = raiser

    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event')
Beispiel #4
0
def test_once():
    """
    Test to show that the "once" method works propers.
    """

    # very similar to "test_emit" but also makes sure that the event
    # gets removed afterwards

    ee = Event_emitter()

    @ee.once('event')
    def event_handler(data):
        nt.assert_equals(data, 'emitter is emitted!')
        raise ItWorkedException

    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event', 'emitter is emitted!')
        nt.assert_equal(ee._events['event'], [])
Beispiel #5
0
def test_emit():
    """
    Test to show that event_emitters fire properly.
    """
    ee = Event_emitter()

    #Used in a decorator style.
    @ee.on('event')
    def event_handler(data, **kwargs):
        nt.assert_equals(data, 'emitter is emitted!')
        # Raise exception to prove it fired.
        if (kwargs['error']):
            raise ItWorkedException

    #Making sure data is passed propers.
    ee.emit('event', 'emitter is emitted!', error=False)

    # Some nose bullshit to check for the firings. "Hides" other exceptions.
    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event', 'emitter is emitted!', error=True)
Beispiel #6
0
def test_emit():
    """Test that event_emitters fire properly.
    """
    ee = Event_emitter()

    # Used in a decorator style
    @ee.on('event')
    def event_handler(data, **kwargs):
        nt.assert_equals(data, 'emitter is emitted!')
        # Raise exception to prove it fired.
        if (kwargs['error']):
            raise ItWorkedException

    # Making sure data is passed propers
    ee.emit('event', 'emitter is emitted!', error=False)

    # Some nose bullshit to check for the firings.
    # "Hides" other exceptions.
    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event', 'emitter is emitted!', error=True)
Beispiel #7
0
def test_once():
    """Test that `once()` method works propers.
    """

    # very similar to "test_emit" but also makes sure that the event
    # gets removed afterwards

    ee = Event_emitter()

    def once_handler(data, error=None):
        nt.assert_equals(data, 'emitter is emitted!')
        if (error):
            raise ItWorkedException

    #Tests to make sure that after event is emitted that it's gone.
    ee.once('event', once_handler)
    ee.emit('event', 'emitter is emitted!')
    nt.assert_equal(ee._events['event'], [])

    #Tests to make sure callback fires. "Hides" other exceptions.
    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.once('event', once_handler)
        ee.emit('event', 'emitter is emitted!', True)
Beispiel #8
0
def test_once():
    """Test that `once()` method works propers.
    """

    # very similar to "test_emit" but also makes sure that the event
    # gets removed afterwards

    ee = Event_emitter()

    def once_handler(data, error=None):
        nt.assert_equals(data, 'emitter is emitted!')
        if (error):
            raise ItWorkedException

    #Tests to make sure that after event is emitted that it's gone.
    ee.once('event', once_handler)
    ee.emit('event', 'emitter is emitted!')
    nt.assert_equal(ee._events['event'], [])

    #Tests to make sure callback fires. "Hides" other exceptions.
    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.once('event', once_handler)
        ee.emit('event', 'emitter is emitted!', True)
Beispiel #9
0
def test_matching_topic():
    """Test that a pattern can be passed as an event"""

    ee = Event_emitter()

    @ee.on('event/+/ok')
    def event_handler(ev):
        raise ItWorkedException

    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event/first/ok')

    with nt.assert_raises(ItWorkedException) as it_worked:
        ee.emit('event/second/ok')

    ee.emit('event/first/ok2')