当前位置: 首页>>代码示例>>Python>>正文


Python Application.register方法代码示例

本文整理汇总了Python中azure.cli.core.application.Application.register方法的典型用法代码示例。如果您正苦于以下问题:Python Application.register方法的具体用法?Python Application.register怎么用?Python Application.register使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在azure.cli.core.application.Application的用法示例。


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

示例1: test_help_loads

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import register [as 别名]
    def test_help_loads(self):
        app = Application()
        app.initialize(Configuration())
        with mock.patch('azure.cli.core.commands.arm.APPLICATION', app):
            from azure.cli.core.commands.arm import add_id_parameters
            parser_dict = {}
            cmd_tbl = app.configuration.get_command_table()
            app.parser.load_command_table(cmd_tbl)
            for cmd in cmd_tbl:
                try:
                    app.configuration.load_params(cmd)
                except KeyError:
                    pass
            app.register(app.COMMAND_TABLE_PARAMS_LOADED, add_id_parameters)
            app.raise_event(app.COMMAND_TABLE_PARAMS_LOADED, command_table=cmd_tbl)
            app.parser.load_command_table(cmd_tbl)
            _store_parsers(app.parser, parser_dict)

            for name, parser in parser_dict.items():
                try:
                    help_file = _help.GroupHelpFile(name, parser) \
                        if _is_group(parser) \
                        else _help.CommandHelpFile(name, parser)
                    help_file.load(parser)
                except Exception as ex:
                    raise _help.HelpAuthoringException('{}, {}'.format(name, ex))
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:28,代码来源:test_help.py

示例2: test_application_register_and_call_handlers

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import register [as 别名]
    def test_application_register_and_call_handlers(self):
        handler_called = [False]

        def handler(**kwargs):
            kwargs['args'][0] = True

        def other_handler(**kwargs):
            self.assertEqual(kwargs['args'], 'secret sauce')

        app = Application()
        app.initialize(Configuration())

        app.raise_event('was_handler_called', args=handler_called)
        self.assertFalse(handler_called[0],
                         "Raising event with no handlers registered somehow failed...")

        app.register('was_handler_called', handler)
        self.assertFalse(handler_called[0])

        # Registered handler won't get called if event with different name
        # is raised...
        app.raise_event('other_handler_called', args=handler_called)
        self.assertFalse(handler_called[0], 'Wrong handler called!')

        app.raise_event('was_handler_called', args=handler_called)
        self.assertTrue(handler_called[0], "Handler didn't get called")

        app.raise_event('other_handler_called', args='secret sauce')
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:30,代码来源:test_application.py

示例3: test_help_loads

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import register [as 别名]
    def test_help_loads(self):
        app = Application()
        with mock.patch('azure.cli.core.commands.arm.APPLICATION', app):
            from azure.cli.core.commands.arm import add_id_parameters
            parser_dict = {}
            cmd_tbl = app.configuration.get_command_table()
            app.parser.load_command_table(cmd_tbl)
            for cmd in cmd_tbl:
                try:
                    app.configuration.load_params(cmd)
                except KeyError:
                    pass
            app.register(app.COMMAND_TABLE_PARAMS_LOADED, add_id_parameters)
            app.raise_event(app.COMMAND_TABLE_PARAMS_LOADED, command_table=cmd_tbl)
            app.parser.load_command_table(cmd_tbl)
            _store_parsers(app.parser, parser_dict)

            for name, parser in parser_dict.items():
                try:
                    help_file = _help.GroupHelpFile(name, parser) \
                        if _is_group(parser) \
                        else _help.CommandHelpFile(name, parser)
                    help_file.load(parser)
                except Exception as ex:
                    raise _help.HelpAuthoringException('{}, {}'.format(name, ex))

            extras = [k for k in azure.cli.core.help_files.helps.keys() if k not in parser_dict]
            self.assertTrue(len(extras) == 0,
                            'Found help files that don\'t map to a command: '+ str(extras))
开发者ID:Azure,项目名称:azure-cli,代码行数:31,代码来源:test_help.py


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