def test_singleton_container(): ioc = IocManager(stats=True) ioc.set_class(name='singleton1', cls=TSingleton1, singleton=True) assert ioc.singleton1 is ioc.singleton1 ioc.print_stats()
def test_singleton_args_diff_container(): ioc = IocManager(stats=True) ioc.set_class(name='singleton2', cls=TSingleton2, singleton=True) ioc.set_class(name='Parent1', cls=Parent1, singleton=True) assert ioc.singleton2 is not None ioc.print_stats()
def test_value_container(): ioc = IocManager(stats=True) config_value = 'config_value' ioc.set_value('config', config_value) ioc.set_value('config1', config_value) ioc.set_value('config2', config_value) assert ioc.config is ioc.config1 assert ioc.config1 is ioc.config2 ioc.print_stats()
def test_singleton_args_diff2_container(): print('TSingleton2=%s (%s)' % (TSingleton2.__name__, TSingleton2)) print('example_func=%s (%s)' % (example_func.__name__, example_func)) ioc = IocManager(stats=True) ioc.set_class(name='singleton2', cls=TSingleton2, singleton=True) ioc.set_class(name='Parent1', cls=Parent1, singleton=True) assert ioc.singleton2 is not None ioc.print_stats()
def test_singleton_args_container(): stats = {} ioc = IocManager(stats) ioc.set_class(name='TSingleton1', cls=TSingleton1, singleton=True) ioc.set_class(name='singleton2', cls=TSingleton2, singleton=True) assert ioc.singleton2 is ioc.singleton2 assert ioc.TSingleton1 is ioc.TSingleton1 assert ioc.singleton2.ts is ioc.TSingleton1 ioc.print_stats()
def test_factory_container(): ioc = IocManager(stats=True) ioc.set_class(name='TSingleton1', cls=TSingleton1, singleton=True) ioc.set_class(name='TSingleton2', cls=TSingleton2, singleton=False) ioc.set_factory(name='TSingleton3', cls=MyIocFactory) ioc.set_class(name='TSingleton3dot1', cls=TSingleton3dot1, singleton=False) ioc.set_class(name='TSingleton3dot2', cls=TSingleton3dot2, singleton=False) ioc.set_class(name='TSingleton3dot3', cls=TSingleton3dot3, singleton=False) assert ioc.TSingleton1 is ioc.TSingleton1 ts3 = ioc.TSingleton3 assert isinstance(ts3, TSingleton3dot1) ioc.print_stats()