コード例 #1
0
ファイル: test_help.py プロジェクト: LukaszStem/azure-cli
    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))
コード例 #2
0
ファイル: test_help.py プロジェクト: yashdeepgarg/azure-cli
    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))
コード例 #3
0
    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))
コード例 #4
0
ファイル: test_application.py プロジェクト: weinong/azure-cli
    def test_application_register_and_call_handlers(self):
        handler_called = [False]

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

        def other_handler(**kwargs):  # pylint: disable=unused-variable
            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')
コード例 #5
0
    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')