Exemplo n.º 1
0
    class B:
        before = InstanceHook()
        after = InstanceHook()

        @after
        @before
        def greeting(self, name):
            return 'Hello {}'.format(name)
Exemplo n.º 2
0
    class B(Hookable):
        before = InstanceHook()

        @before
        def on_before1(self):
            assert isinstance(self, B)
            return 1
Exemplo n.º 3
0
    class B:
        before = InstanceHook(consume_generators=False)

        @before
        def generate_some(self):
            yield from range(3)

        @before
        def generate_more(self):
            yield from range(2)
Exemplo n.º 4
0
    class B:
        before = InstanceHook()
        after = ClassHook()

        @before
        def on_before(self, x):
            assert isinstance(self, B)
            return x * 3

        @after
        def on_after(cls, y):
            assert cls is B
            return y * 5
Exemplo n.º 5
0
    class C(B):
        between = InstanceHook()
        betwixt = ClassHook()

        @between
        def on_between(self, x):
            assert isinstance(self, C)
            return x * 4

        @betwixt
        def on_betwixt(cls, y):
            assert cls is C
            return y * 6
Exemplo n.º 6
0
    class Base(Hookable):
        before = InstanceHook()

        before(lambda: 1)
Exemplo n.º 7
0
 class Base(Hookable):
     before = InstanceHook()
Exemplo n.º 8
0
class Address:
    updated = InstanceHook()

    city = ObservableAttr('city')
    country = ObservableAttr('country')
Exemplo n.º 9
0
 class Field:
     parser = InstanceHook(single_handler=True)
Exemplo n.º 10
0
 class C:
     before = InstanceHook()
Exemplo n.º 11
0
def test_standalone_initialisation():
    before = InstanceHook('before')
    assert isinstance(before, InstanceHook)
    assert before.name == 'before'
Exemplo n.º 12
0
 class Derived(Base):
     after = InstanceHook()
Exemplo n.º 13
0
 class Base:
     before = InstanceHook()
Exemplo n.º 14
0
 class C(B):
     before = InstanceHook()  # overwrite, has no connection B.before
Exemplo n.º 15
0
 class B:
     before = InstanceHook()
Exemplo n.º 16
0
 class B:
     before = InstanceHook()
     after = InstanceHook()
Exemplo n.º 17
0
 class C:
     before = InstanceHook(args=['x', 'y'])