• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ioc.Container类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mtm.ioc.Container的典型用法代码示例。如果您正苦于以下问题:Python Container类的具体用法?Python Container怎么用?Python Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Container类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test1

    def test1(self):
        config = {
            'PathVars': {
                'foo': 'yep [bar]',
                'bar': 'result2',
                'nest1': 'asdf [foo]',
            }
        }
        Container.bind('Config').toSingle(Config, [config])

        Container.bind('VarManager').toSingle(VarManager)

        pathMgr = Container.resolve('VarManager')

        assertThat(pathMgr.hasKey('foo'))
        assertThat(not pathMgr.hasKey('asdf'))
        assertThat(pathMgr.tryGet('bobsdf') == None)
        assertThat(pathMgr.expand('before [bar] after') == 'before result2 after')
        assertThat(pathMgr.expand('before [foo] after') == 'before yep result2 after')

        assertThat(not pathMgr.hasKey('qux'))
        pathMgr.add('qux', 'sadf')
        assertThat(pathMgr.hasKey('qux'))
        assertThat(pathMgr.expand('[qux]') == 'sadf')

        assertThat(pathMgr.expand('[nest1]') == 'asdf yep result2')

        print('Done')
开发者ID:AcamTech,项目名称:Zenject,代码行数:28,代码来源:TestVarManager.py


示例2: _request

    def _request(self):
        if not Container.hasBinding(self._identifier):
            return self._default

        obj = Container.resolve(self._identifier)
        self._assertion(obj)
        return obj
开发者ID:AcamTech,项目名称:Zenject,代码行数:7,代码来源:Inject.py


示例3: testSingletonType

    def testSingletonType(self):
        Container.bind('Qux').toSingle(Qux)

        test1 = Test1()
        test2 = Test2()

        self.assertIs(test1.qux, test2.qux)
开发者ID:AcamTech,项目名称:Zenject,代码行数:7,代码来源:TestSingletonsAndTransients.py


示例4: installBindings

def installBindings():

    Container.bind('LogStream').toSingle(LogStreamFile)
    Container.bind('LogStream').toSingle(LogStreamConsole, True, False)

    demoConfig = os.path.realpath(os.path.join(ProjenyDir, 'Demo/Projeny.yaml'))
    Prj.installBindings(demoConfig)
开发者ID:asmboom,项目名称:Projeny,代码行数:7,代码来源:PackageBuild.py


示例5: testMultiple

    def testMultiple(self):

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        # From 1
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        # From 2
        assertIsEqual(config.getString('thing1'), 'Foo')

        # Second one should override
        assertIsEqual(config.getString('foo2'), 'ipsum')

        assertIsEqual(config.getString('nest1', 'firstName'), 'Dorothy')

        # Test concatenating lists together
        assertIsEqual(config.getList('list1'), ['lorem', 'ipsum', 'asdf', 'joe', 'frank'])

        # Test concatenating dictionaries together
        assertIsEqual(config.getDictionary('dict1'), {'joe': 5, 'mary': 15, 'kate': 5, 'jim': 10})

        assertIsEqual(config.tryGetDictionary(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetDictionary({ 5: 1 }, 'asdfasdfasdf'), { 5: 1 })

        assertIsEqual(config.tryGetList(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetList([1, 2], 'asdfasdfasdf'), [1, 2])

        assertIsEqual(config.tryGetBool(False, 'zxvzasdfasdfasdf'), False)
        assertIsEqual(config.tryGetBool(True, 'zxvzasdfasdfasdf'), True)

        assertIsEqual(config.tryGetString('asdf', 'zxvzasdfasdfasdf'), 'asdf')

        assertIsEqual(config.tryGetInt(5, 'zxvzasdfasdfasdf'), 5)
开发者ID:Ariequ,项目名称:Projeny,代码行数:35,代码来源:TestConfigYaml.py


示例6: testTransientInstance

    def testTransientInstance(self):
        Container.bind('Qux').to(Qux)

        test1 = Test1()
        test2 = Test2()

        self.assertIsNot(test1.qux, test2.qux)
开发者ID:AcamTech,项目名称:Zenject,代码行数:7,代码来源:TestSingletonsAndTransients.py


示例7: testUseDefault

    def testUseDefault(self):
        Container.bind('Foo').to(1)
        Container.bind('Test1').toSingle(Test1)

        test1 = Container.resolve('Test1')

        self.assertEqual(test1.foo, 1)
        self.assertEqual(test1.bar, 5)
开发者ID:AcamTech,项目名称:Zenject,代码行数:8,代码来源:TestOptionalInjection.py


示例8: testSingletonMethodWithParam

    def testSingletonMethodWithParam(self):
        Container.bind('Qux').toSingle(GetQux, 4)

        test1 = Test1()
        test2 = Test2()

        self.assertIs(test1.qux, test2.qux)
        self.assertEqual(test1.qux.GetValue(), 4)
开发者ID:AcamTech,项目名称:Zenject,代码行数:8,代码来源:TestSingletonsAndTransients.py


示例9: testTransientInstanceWithParam

    def testTransientInstanceWithParam(self):
        Container.bind('Qux').to(Qux, 5)

        test1 = Test1()
        test2 = Test2()

        self.assertIsNot(test1.qux, test2.qux)
        self.assertEqual(test1.qux.GetValue(), 5)
开发者ID:AcamTech,项目名称:Zenject,代码行数:8,代码来源:TestSingletonsAndTransients.py


示例10: testTransientMethod

    def testTransientMethod(self):

        Container.bind('Qux').to(GetQux, 6)

        test1 = Test1()
        test2 = Test2()

        self.assertIsNot(test1.qux, test2.qux)
        self.assertEqual(test1.qux.GetValue(), 6)
开发者ID:AcamTech,项目名称:Zenject,代码行数:9,代码来源:TestSingletonsAndTransients.py


示例11: testSpecialChars

    def testSpecialChars(self):
        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        assertIsEqual(config.tryGetString(None, 'foo4'), 'asdf')

        assertIsEqual(config.tryGetString(None, 'foo5'), 'zxcv')

        assertIsEqual(config.tryGetString(None, 'foo6'), 'asdf')
        assertIsEqual(config.tryGetString(None, 'foo7'), 'zxcv')
开发者ID:Ariequ,项目名称:Projeny,代码行数:11,代码来源:TestConfigYaml.py


示例12: test1

    def test1(self):
        assertThat(False, "TODO")
        #Container.bind('Config').toSingle(ConfigXml)
        Container.bind('VarManager').toSingle(VarManager)
        Container.bind('SystemHelper').toSingle(SystemHelper)
        Container.bind('Logger').toSingle(Logger)

        self._test1(Container.resolve('SystemHelper'))
开发者ID:AcamTech,项目名称:Zenject,代码行数:8,代码来源:TestSystemHelper.py


示例13: testSimple

    def testSimple(self):
        yamlPath = ScriptDir + '/ExampleConfig.yaml'

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(yamlPath))

        config = Container.resolve('Config')

        assertIsEqual(config.getString('date'), '2012-08-06')
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        assertIsEqual(config.getList('places'), ['New Jersey', 'New York'])
        assertRaisesAny(lambda: config.getString('places'))
        assertRaisesAny(lambda: config.getDictionary('places'))

        assertIsEqual(config.getDictionary('customer'),
          {'first_name': 'Dorothy', 'family_name': 'Gale'})

        # Tests YAML references
        assertIsEqual(config.getString('foo1'), config.getString('receipt'))
开发者ID:Ariequ,项目名称:Projeny,代码行数:19,代码来源:TestConfigYaml.py


示例14: testOverrideDefault

    def testOverrideDefault(self):
        Container.bind('Foo').to(2)
        Container.bind('Test1').to(Test1)
        Container.bind('Bar').to(3)

        test1 = Container.resolve('Test1')

        self.assertEqual(test1.foo, 2)
        self.assertEqual(test1.bar, 3)
开发者ID:AcamTech,项目名称:Zenject,代码行数:9,代码来源:TestOptionalInjection.py


示例15: testOutputToFile

    def testOutputToFile(self):
        assertThat(False)
        #Container.bind('Config').toSingle(ConfigXml)
        Container.bind('VarManager').toSingle(VarManager, {
            'LogPath': ScriptDir + '/logtest.txt',
            'LogPathPrevious': ScriptDir + '/logtest.prev.txt',
        })

        log = Logger(False, True)

        log.heading("heading 1")
        log.info("info 1")
        log.error("error 1")
        log.good("good 1")
        log.info("info 2")
        log.heading("heading 2")
        log.info("info 3")
        log.finished("Done")

        log.dispose()
开发者ID:AcamTech,项目名称:Zenject,代码行数:20,代码来源:TestLogger.py


示例16: _main

def _main():
    # Here we split out some functionality into various methods
    # so that other python code can make use of them
    # if they want to extend projeny
    parser = argparse.ArgumentParser(description='Unity Package Manager')
    addArguments(parser)

    argv = sys.argv[1:]

    # If it's 2 then it only has the -cfg param
    if len(argv) == 0:
        parser.print_help()
        sys.exit(2)

    args = parser.parse_args(sys.argv[1:])

    Container.bind('LogStream').toSingle(LogStreamFile)
    Container.bind('LogStream').toSingle(LogStreamConsole, args.verbose, args.veryVerbose)

    if args.createConfig:
        _createConfig()
    else:
        if args.configPath:
            assertThat(os.path.isfile(args.configPath), "Could not find config file at '{0}'", args.configPath)
            mainConfigPath = args.configPath
        else:
            mainConfigPath = findMainConfigPath()

        installBindings(mainConfigPath)
        installPlugins()

        Container.resolve('PrjRunner').run(args)
开发者ID:Ariequ,项目名称:Projeny,代码行数:32,代码来源:Prj.py


示例17: testOutputToConsole

    def testOutputToConsole(self):
        self._installBindings()
        log = Container.resolve('Logger')

        with log.heading("heading 1"):
            log.info("test of params: {0}", 5)

            with log.heading("heading 2"):
                log.error("test of params: {0}", 5)
                log.good("test of params: {0}", 5)

            log.info("test of params: {0}", 5)
            log.info("info 1")
            log.error("error 1")
            log.good("good 1")
            log.info("info 2")

            with log.heading("heading 2"):
                log.info("info 3")
                log.good("Done")
开发者ID:Ariequ,项目名称:Projeny,代码行数:20,代码来源:TestLogger.py


示例18: setUp

 def setUp(self):
     Container.clear()
开发者ID:AcamTech,项目名称:Zenject,代码行数:2,代码来源:TestLogger.py


示例19: testIsInstanceSuccess

 def testIsInstanceSuccess(self):
     Container.bind('Title').to('yep')
     Test2().Run()
开发者ID:AcamTech,项目名称:Zenject,代码行数:3,代码来源:TestConditionalInjections.py


示例20: testIsInstanceFailure

 def testIsInstanceFailure(self):
     Container.bind('Title').to(2)
     Test2().Run()
开发者ID:AcamTech,项目名称:Zenject,代码行数:3,代码来源:TestConditionalInjections.py



注:本文中的mtm.ioc.Container类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cmdlinetool.LogFileTool类代码示例发布时间:2022-05-27
下一篇:
Python MtbfTestCase.GaiaMtbfTestCase类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap