class B: before = InstanceHook() after = InstanceHook() @after @before def greeting(self, name): return 'Hello {}'.format(name)
class B(Hookable): before = InstanceHook() @before def on_before1(self): assert isinstance(self, B) return 1
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)
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
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
class Base(Hookable): before = InstanceHook() before(lambda: 1)
class Base(Hookable): before = InstanceHook()
class Address: updated = InstanceHook() city = ObservableAttr('city') country = ObservableAttr('country')
class Field: parser = InstanceHook(single_handler=True)
class C: before = InstanceHook()
def test_standalone_initialisation(): before = InstanceHook('before') assert isinstance(before, InstanceHook) assert before.name == 'before'
class Derived(Base): after = InstanceHook()
class Base: before = InstanceHook()
class C(B): before = InstanceHook() # overwrite, has no connection B.before
class B: before = InstanceHook()
class B: before = InstanceHook() after = InstanceHook()
class C: before = InstanceHook(args=['x', 'y'])