Exemple #1
0
def test_reaction_dispose3():
    # Test that connecting a "volatile" object to a static object works well
    # w.r.t. cleanup.

    relay = event.Component()

    class Foo:
        def bar(self, *events):
            pass

    foo = Foo()
    handler = relay.reaction(foo.bar, 'xx')

    handler_ref = weakref.ref(handler)
    foo_ref = weakref.ref(foo)

    del foo
    del handler

    gc.collect()

    assert foo_ref() is None
    assert handler_ref() is not None

    relay.emit('xx')
    loop.iter()
    gc.collect()

    assert foo_ref() is None
    assert handler_ref() is None
Exemple #2
0
def test_reaction_dispose2():

    h = event.Component()

    @h.reaction('x1', 'x2')
    def handler(*events):
        pass

    handler_ref = weakref.ref(handler)
    del handler
    gc.collect()
    assert handler_ref() is not None  # h is holding on

    h.dispose()  # <=== only this line is different from test_dispose1()
    gc.collect()
    assert handler_ref() is None
Exemple #3
0
def test_reaction_dispose1():

    h = event.Component()

    @h.reaction('!x1', '!x2')
    def handler(*events):
        pass

    handler_ref = weakref.ref(handler)
    del handler
    gc.collect()
    assert handler_ref() is not None  # h is holding on

    handler_ref().dispose()
    gc.collect()
    assert handler_ref() is None
Exemple #4
0
def test_reaction_exceptions1():
    m = event.Component()

    @m.reaction('!foo')
    def handle_foo(*events):
        1/0

    m.emit('foo', {})

    sys.last_traceback = None
    assert sys.last_traceback is None

    # No exception should be thrown here
    loop.iter()
    loop.iter()

    # But we should have prepared for PM debugging
    if sys.version_info[0] >= 3:  # not sure why
        assert sys.last_traceback

    # Its different for a direct call
    with raises(ZeroDivisionError):
        handle_foo()
Exemple #5
0
 def __init__(self):
     super().__init__()
     self.bar = event.Component()
     self.bars = [self.bar]