Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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