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'
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']
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']
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']
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'
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'
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)