def test_unload_components():
    _comps = (Interface1, Interface2)
    ctx.unload_components(_comps)
    for comp in _comps:
        assert_false(comp in InterfaceMeta._registry)

    # test that we fail silently if a component is not loaded
    ctx.unload_components(_comps)
def test_unload_components():
    _comps = (Interface1, Interface2)
    ctx.unload_components(_comps)
    for comp in _comps:
        assert_false(comp in InterfaceMeta._registry)

    # test that we fail silently if a component is not loaded
    ctx.unload_components(_comps)
def test_component_is_activated():
    assert_false(ctx.component_is_activated(Implementation1, ['tests.core.*']))
    assert_false(ctx.component_is_activated(Implementation1,
                                ['tests.core.test_components.Implementation1']))

    assert_true(ctx.component_is_activated(Implementation2,
                                ['tests.core.test_components.Implementation1']))

    eq_(ctx.load_packages(['tests.core.test_components'], ['tests.core.*']),
                          set([]))

    eq_(ctx.load_packages(['tests.core.test_components'],
                          ['tests.core.test_components.Implementation1']),
                          set([Implementation2, Implementation3]))
def test_component_is_activated():
    assert_false(ctx.component_is_activated(Implementation1, ['tests.core.*']))
    assert_false(
        ctx.component_is_activated(
            Implementation1, ['tests.core.test_components.Implementation1']))

    assert_true(
        ctx.component_is_activated(
            Implementation2, ['tests.core.test_components.Implementation1']))

    eq_(ctx.load_packages(['tests.core.test_components'], ['tests.core.*']),
        set([]))

    eq_(
        ctx.load_packages(['tests.core.test_components'],
                          ['tests.core.test_components.Implementation1']),
        set([Implementation2, Implementation3]))
def test_components():
    assert_true(Interface1._isinterface)
    assert_false(hasattr(Interface1, '_interfaces'))
    assert_false(Implementation1._isinterface)
    eq_(Implementation1._interfaces, set([Interface1]))
    eq_(Implementation2._interfaces, set([Interface1, Interface2]))

    # we return the component object unchanged so it does not
    # have any special attributes
    obj = Interface(ctx)
    assert_false(hasattr(obj, '_isinterface'))
    assert_false(hasattr(obj, '_interfaces'))
def test_components():
    assert_true(Interface1._isinterface)
    assert_false(hasattr(Interface1, '_interfaces'))
    assert_false(Implementation1._isinterface)
    eq_(Implementation1._interfaces, set([Interface1]))
    eq_(Implementation2._interfaces, set([Interface1, Interface2]))

    # we return the component object unchanged so it does not
    # have any special attributes
    obj = Interface(ctx)
    assert_false(hasattr(obj, '_isinterface'))
    assert_false(hasattr(obj, '_interfaces'))
def test_load_components():
    loaded = ctx.load_components([Implementation1, Implementation2, Implementation3])
    eq_(len(loaded), 3)

    assert_true(Implementation1 in loaded)
    assert_true(Implementation2 in loaded)
    assert_true(Implementation3 in loaded)
    assert_false(Interface1 in loaded)
    assert_false(Interface2 in loaded)
    assert_false(Interface3 in loaded)

    eq_(len(ctx.get_implementations(Interface1)), 2)
    eq_(len(ctx.get_implementations(Interface2)), 2)
def test_load_components():
    loaded = ctx.load_components(
        [Implementation1, Implementation2, Implementation3])
    eq_(len(loaded), 3)

    assert_true(Implementation1 in loaded)
    assert_true(Implementation2 in loaded)
    assert_true(Implementation3 in loaded)
    assert_false(Interface1 in loaded)
    assert_false(Interface2 in loaded)
    assert_false(Interface3 in loaded)

    eq_(len(ctx.get_implementations(Interface1)), 2)
    eq_(len(ctx.get_implementations(Interface2)), 2)