Example #1
0
def test_cached_class_lookup():
    reg = Registry()

    reg.register(ITarget, (), 'reg component')

    cached = CachedClassLookup(reg)

    assert cached.get(ITarget, ()) == 'reg component'

    # we change the registration
    reg.register(ITarget, (), 'reg component changed')

    # the cache won't know
    assert cached.get(ITarget, ()) == 'reg component'
Example #2
0
def test_cached_class_lookup_all():
    reg = Registry()

    reg.register(target, (), 'reg component')

    cached = CachingClassLookup(reg)

    assert list(cached.all(target, ())) == ['reg component']

    # we change the registration
    reg.register(target, (), 'reg component changed')

    # the cache won't know
    assert list(cached.all(target, ())) == ['reg component']
Example #3
0
def test_chain_class_lookup_all():
    reg1 = Registry()
    reg2 = Registry()

    reg1.register(target, (), 'reg1')
    reg2.register(target, (), 'reg2')

    lookup = ChainClassLookup(reg1, reg2)
    assert list(lookup.all(target, ())) == ['reg1', 'reg2']
Example #4
0
def test_list_class_lookup_all():
    reg1 = Registry()
    reg2 = Registry()

    reg1.register(target, (), 'reg1')
    reg2.register(target, (), 'reg2')

    lookup = ListClassLookup([reg1, reg2])
    assert list(lookup.all(target, ())) == ['reg1', 'reg2']
Example #5
0
def test_chain_class_lookup():
    reg1 = Registry()
    reg2 = Registry()

    reg2.register(target, (), 'reg2 component')

    lookup = ChainClassLookup(reg1, reg2)
    assert lookup.get(target, ()) == 'reg2 component'

    reg1.register(target, (), 'reg1 component')
    assert lookup.get(target, ()) == 'reg1 component'
Example #6
0
def test_list_class_lookup():
    reg1 = Registry()
    reg2 = Registry()

    reg2.register(target, (), 'reg2 component')

    lookup = ListClassLookup([reg1, reg2])
    assert lookup.get(target, ()) == 'reg2 component'

    reg1.register(target, (), 'reg1 component')
    assert lookup.get(target, ()) == 'reg1 component'
Example #7
0
File: perf.py Project: jean/reg
def myargs0():
    return "args0"

def myargs1(a):
    return "args1"

def myargs2(a, b):
    return "args2"

def myargs3(a, b, c):
    return "args3"

def myargs4(a, b, c, d):
    return "args4"

registry = ClassRegistry()
registry.register(args0, (), myargs0)
registry.register(args1, (Foo,), myargs1)
registry.register(args2, (Foo, Foo), myargs2)
registry.register(args3, (Foo, Foo, Foo), myargs3)
registry.register(args4, (Foo, Foo, Foo, Foo), myargs4)

lookup = Lookup(CachingClassLookup(registry))


def docall0():
    args0(lookup=lookup)

def docall1():
    args1(Foo(), lookup=lookup)