def test_component_not_found(): reg = Registry() assert reg.lookup([], ITarget, '') is None alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is None assert ITarget.component(alpha, lookup=reg, default=None) is None with pytest.raises(ComponentLookupError): ITarget.component(alpha, lookup=reg)
def test_component_not_found(): reg = Registry() assert reg.lookup([], ITarget, '') is None alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is None assert ITarget.component(alpha, lookup=reg, default=None) is None with py.test.raises(ComponentLookupError): ITarget.component(alpha, lookup=reg)
def test_component_class_based_registration(): reg = Registry() foo = object() reg.register((Alpha,), ITarget, '', foo) alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is foo assert ITarget.component(alpha, lookup=reg) is foo
def test_component_one_source(): reg = Registry() foo = object() reg.register((IAlpha,), ITarget, '', foo) alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is foo assert ITarget.component(alpha, lookup=reg) is foo
def test_component_class_based_registration(): reg = Registry() foo = object() reg.register((Alpha, ), ITarget, '', foo) alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is foo assert ITarget.component(alpha, lookup=reg) is foo
def test_component_one_source(): reg = Registry() foo = object() reg.register((IAlpha, ), ITarget, '', foo) alpha = Alpha() assert reg.lookup([alpha], ITarget, '') is foo assert ITarget.component(alpha, lookup=reg) is foo
def test_component_two_sources(): reg = Registry() foo = object() reg.register((IAlpha, IBeta), ITarget, '', foo) alpha = Alpha() beta = Beta() assert reg.lookup([alpha, beta], ITarget, '') is foo assert ITarget.component(alpha, beta, lookup=reg) is foo
def test_component_to_itself(): reg = Registry() alpha = Alpha() foo = object() reg.register([IAlpha], IAlpha, '', foo) assert reg.lookup([alpha], IAlpha, '') is foo assert IAlpha.component(alpha, lookup=reg) is foo
def test_component_inheritance(): reg = Registry() foo = object() class Gamma(object): pass class Delta(Gamma): pass reg.register([Gamma], ITarget, '', foo) delta = Delta() assert reg.lookup([delta], ITarget, '') is foo assert ITarget.component(delta, lookup=reg) is foo
def test_component_no_source(): reg = Registry() foo = object() reg.register((), ITarget, '', foo) assert reg.lookup([], ITarget, '') is foo assert ITarget.component(lookup=reg) is foo