示例#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)
示例#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)
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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