def test_register_Nones(self): from repoze.component import provides class Two(object): provides("two") class One(Two): provides("one") class B(object): provides("b") class A(B): provides("a") instance1 = One() provides(instance1, "i") instance2 = A() provides(instance2, "i") registry = self._makeOne() registry.register("foo", "somevalue", None, None) result = registry.resolve("foo", instance1, instance2) self.assertEqual(result, "somevalue")
def test_register_Nones(self): from repoze.component import provides class Two(object): provides('two') class One(Two): provides('one') class B(object): provides('b') class A(B): provides('a') instance1 = One() provides(instance1, 'i') instance2 = A() provides(instance2, 'i') registry = self._makeOne() registry.register('foo', 'somevalue', None, None) result = registry.resolve('foo', instance1, instance2) self.assertEqual(result, 'somevalue')
def test_register_and_resolve_all(self): from repoze.component.registry import ALL from repoze.component import provides deckard = OSDeckard(None) provides(deckard, "deckard") registry = self._makeRegistry() result = registry.resolve("bladerunner", None, deckard, name=ALL) self.assertEqual(result, ["deckardvalue"]) registry.register("bladerunner", "deckardvalue2", None, "deckard", name="another") result = registry.resolve("bladerunner", None, deckard, name=ALL) self.assertEqual(result, ["deckardvalue", "deckardvalue2"])
def test_register_and_resolve_all(self): from repoze.component.registry import ALL from repoze.component import provides deckard = OSDeckard(None) provides(deckard, 'deckard') registry = self._makeRegistry() result = registry.resolve('bladerunner', None, deckard, name=ALL) self.assertEqual(result, ['deckardvalue']) registry.register('bladerunner', 'deckardvalue2', None, 'deckard', name='another') result = registry.resolve('bladerunner', None, deckard, name=ALL) self.assertEqual(result, ['deckardvalue', 'deckardvalue2'])
class Foo(object): provides('a', 'b')
class Foo: provides('a', 'b')
class A(B): provides('a')
class B(object): provides('b')
class One(Two): provides('one')
class OSLuckman: provides('luckman') def __init__(self, context): self.context = context
def test_register_and_resolve_oldstyle_instances_withdict(self): registry = self._makeRegistry() resolve = registry.resolve eq = self.assertEqual from repoze.component import provides deckard = OSDeckard(None) provides(deckard, "deckard") inheritsdeckard = OSInheritsDeckard(None) provides(inheritsdeckard, "inhherits") luckman = OSLuckman(None) provides(luckman, "luckman") barris = OSBarris(None) provides(barris, "barris") inheritsbarris = OSInheritsBarris(None) provides(inheritsbarris, "inherits") deckardbarris = OSDeckardBarris(None, None) provides(deckardbarris, "deckard", "barris") eq(resolve("bladerunner", None, deckard), "deckardvalue") eq(resolve("bladerunner", None, inheritsdeckard), "deckardvalue") eq(resolve("friend", luckman, name="name"), "luckmanvalue") eq(resolve("fight", barris, luckman), "barrisluckmanvalue") eq(resolve("fight", inheritsbarris, luckman), "barrisluckmanvalue") eq(resolve("fight", deckardbarris, luckman), "barrisluckmanvalue") eq(resolve("bladerunner", None, deckardbarris), "deckardvalue") eq(resolve("friend", luckman, default=None), None) eq(resolve("bladerunner", deckard, luckman, default=None), None) eq(resolve("bladerunner", luckman, deckard), "deckardvalue") eq(resolve("bladerunner", barris, deckard), "deckardvalue") eq(resolve("bladerunner", None, None, default=None), None)
class OSInheritsBarris(OSBarris): provides('inherits') def __init__(self, context): self.context = context
def test_register_and_resolve_oldstyle_instances_withdict(self): registry = self._makeRegistry() resolve = registry.resolve eq = self.assertEqual from repoze.component import provides deckard = OSDeckard(None) provides(deckard, 'deckard') inheritsdeckard = OSInheritsDeckard(None) provides(inheritsdeckard, 'inhherits') luckman = OSLuckman(None) provides(luckman, 'luckman') barris = OSBarris(None) provides(barris, 'barris') inheritsbarris = OSInheritsBarris(None) provides(inheritsbarris, 'inherits') deckardbarris = OSDeckardBarris(None, None) provides(deckardbarris, 'deckard', 'barris') eq(resolve('bladerunner', None, deckard), 'deckardvalue') eq(resolve('bladerunner', None, inheritsdeckard), 'deckardvalue') eq(resolve('friend', luckman, name='name'), 'luckmanvalue') eq(resolve('fight', barris, luckman), 'barrisluckmanvalue') eq(resolve('fight', inheritsbarris, luckman), 'barrisluckmanvalue') eq(resolve('fight', deckardbarris, luckman), 'barrisluckmanvalue') eq(resolve('bladerunner', None, deckardbarris), 'deckardvalue') eq(resolve('friend', luckman, default=None), None) eq(resolve('bladerunner', deckard, luckman, default=None), None) eq(resolve('bladerunner', luckman, deckard), 'deckardvalue') eq(resolve('bladerunner', barris, deckard), 'deckardvalue') eq(resolve('bladerunner', None, None, default=None), None)
class OSInheritsDeckard(OSDeckard): provides('inherits') def __init__(self, context): self.context = context
class OSDeckardBarris: provides('deckard', 'barris') def __init__(self, context1, context2): self.context1 = context1 self.context2 = context2
class OSBarris: provides('barris') def __init__(self, context): self.context = context
def _callFUT(self, obj, *types): from repoze.component import provides provides(obj, *types)
class Barris(object): provides('barris') def __init__(self, context): self.context = context
class Foo(object): provides('abc', 'def')
class Luckman(object): provides('luckman') def __init__(self, context): self.context = context
class Two(object): provides('two')
class OSDeckard: provides('deckard') def __init__(self, context): self.context = context
class Deckard(object): provides('deckard') def __init__(self, context): self.context = context