def test_import_module(): from inyoka.core.auth import models # import definite modules assert_true(models is list(_import_module('inyoka.core.auth.models'))[0]) # star import packages assert_true(models in list(_import_module('inyoka.core.*'))) # star import to definite modules not packages # we assert here to import the module rather than to raise a ValueError # as werkzeug's find_modules would do. list(_import_module('werkzeug._internal.*'))
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_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_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)