Exemple #1
0
def pubpen(event_loop):
    pubpen = PubPen(event_loop)
    pubpen.loop = mock.MagicMock()
    # In the real code, we store a weakref to the handlers.  We use lambda
    # here to wrape the actual handler once to emulate the aspects of the
    # weakref that are important to this test
    pubpen._event_handlers['test_event1'][0] = lambda: handler1
    pubpen._event_handlers['test_event2'][1] = lambda: handler2
    pubpen._event_handlers['test_event2'][2] = lambda: handler3
    return pubpen
Exemple #2
0
def pubpen_handlers_dealloc(event_loop):
    pubpen = PubPen(event_loop)
    pubpen.loop = mock.MagicMock()
    pubpen._subscriptions[0] = 'test_event1'
    pubpen._subscriptions[1] = 'test_event1'
    # In the real code, we store a weakref to the handlers.  We use lambda
    # here to wrape the actual handler once to emulate the aspects of the
    # weakref that are important to this test
    pubpen._event_handlers['test_event1'][0] = lambda: handler1
    # But this one represents a weakref where the target has been deallocated.
    # In that case, calling the weakref returns None
    pubpen._event_handlers['test_event1'][1] = lambda: None
    return pubpen
Exemple #3
0
def pubpen_handlers_partially_removed(event_loop):
    """
    The handler has been deallocated (because it's a weakref) but it's only
    been removed from the _subscriptions list already.
    """
    pubpen = PubPen(event_loop)
    pubpen.loop = mock.MagicMock()
    pubpen._subscriptions[0] = 'test_event1'
    # In the real code, we store a weakref to the handlers.  We use lambda
    # here to wrape the actual handler once to emulate the aspects of the
    # weakref that are important to this test
    pubpen._event_handlers['test_event1'][0] = lambda: handler1
    # But this one represents a weakref where the target has been deallocated.
    # In that case, calling the weakref returns None
    pubpen._event_handlers['test_event1'][1] = lambda: None
    return pubpen
Exemple #4
0
def pubpen_predefined(event_loop):
    pubpen = PubPen(event_loop, event_list=['test_event1', 'test_event2'])
    pubpen.loop = mock.MagicMock()
    return pubpen