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


Python Application.execute方法代码示例

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


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

示例1: test_help_group_children

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_group_children(self):
        app = Application(Configuration([]))
        def test_handler():
            pass
        def test_handler2():
            pass

        command = CliCommand('group1 group3 n1', test_handler)
        command.add_argument('foobar', '--foobar', '-fb', required=False)
        command.add_argument('foobar2', '--foobar2', '-fb2', required=True)

        command2 = CliCommand('group1 group2 n1', test_handler2)
        command2.add_argument('foobar', '--foobar', '-fb', required=False)
        command2.add_argument('foobar2', '--foobar2', '-fb2', required=True)

        cmd_table = {'group1 group3 n1': command, 'group1 group2 n1': command2}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('group1 -h'.split())
        s = '\nGroup\n    az group1\n\nSubgroups:\n    group2\n    group3\n\n'
        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:27,代码来源:test_help.py

示例2: test_help_full_documentations

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_full_documentations(self, _):
        app = Application(Configuration())

        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('foobar', '--foobar', '-fb', required=False)
        command.add_argument('foobar2', '--foobar2', '-fb2', required=True)
        command.help = """
                short-summary: this module does xyz one-line or so
                long-summary: |
                    this module.... kjsdflkj... klsfkj paragraph1
                    this module.... kjsdflkj... klsfkj paragraph2
                parameters:
                    - name: --foobar -fb
                      type: string
                      required: false
                      short-summary: one line partial sentence
                      long-summary: text, markdown, etc.
                      populator-commands:
                        - az vm list
                        - default
                    - name: --foobar2 -fb2
                      type: string
                      required: true
                      short-summary: one line partial sentence
                      long-summary: paragraph(s)
                examples:
                    - name: foo example
                      text: example details
            """
        cmd_table = {'n1': command}

        config = Configuration()
        config.get_command_table = lambda args: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        s = """
Command
    az n1: This module does xyz one-line or so.
        This module.... kjsdflkj... klsfkj paragraph1
        this module.... kjsdflkj... klsfkj paragraph2.

Arguments
    --foobar2 -fb2 [Required]: One line partial sentence.
        Paragraph(s).
    --foobar -fb             : One line partial sentence.  Values from: az vm list, default.
        Text, markdown, etc.

Global Arguments
    --help -h                : Show this help message and exit.

Examples
    foo example
        example details
"""
        self.assertEqual(s, io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:62,代码来源:test_help.py

示例3: test_help_long_description_from_docstring

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_long_description_from_docstring(self):
        """ Verifies that the first sentence of a docstring is extracted as the short description.
        Verifies that line breaks in the long summary are removed and leaves the text wrapping
        to the help system. """

        def test_handler():
            """Short Description. Long description with\nline break."""
            pass

        setattr(sys.modules[__name__], test_handler.__name__, test_handler)

        cli_command(None, "test", "{}#{}".format(__name__, test_handler.__name__))
        _update_command_definitions(command_table)

        config = Configuration([])
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("test -h".split())
        self.assertEqual(
            True,
            io.getvalue().startswith(
                "\nCommand\n    az test: Short Description.\n        Long description with line break."
            ),
        )  # pylint: disable=line-too-long
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:27,代码来源:test_help.py

示例4: test_help_with_param_specified

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_with_param_specified(self, _):
        app = Application(Configuration([]))
        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 --arg foo -h'.split())

        s = """
Command
    az n1

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:32,代码来源:test_help.py

示例5: TestCommandWithConfiguredDefaults

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
class TestCommandWithConfiguredDefaults(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        self.argv = None
        self.application = None
        super(TestCommandWithConfiguredDefaults, self).__init__(*args, **kwargs)

    @classmethod
    def setUpClass(cls):
        # Ensure initialization has occurred correctly
        import azure.cli.main
        logging.basicConfig(level=logging.DEBUG)

    @classmethod
    def tearDownClass(cls):
        logging.shutdown()

    @staticmethod
    def sample_vm_list(resource_group_name):
        return resource_group_name

    def set_up_command_table(self, required_arg=False):
        command_table.clear()

        module_name = __name__ + '.' + self._testMethodName
        cli_command(module_name, 'test sample-vm-list',
                    '{}#TestCommandWithConfiguredDefaults.sample_vm_list'.format(__name__))

        register_cli_argument('test sample-vm-list', 'resource_group_name',
                              CliArgumentType(options_list=('--resource-group-name', '-g'),
                                              configured_default='group', required=required_arg))

        command_table['test sample-vm-list'].load_arguments()
        _update_command_definitions(command_table)

        self.argv = 'az test sample-vm-list'.split()
        config = Configuration()
        config.get_command_table = lambda argv: command_table
        self.application = Application(config)

    @mock.patch.dict(os.environ, {AzConfig.env_var_name('defaults', 'group'): 'myRG'})
    def test_apply_configured_defaults_on_required_arg(self):
        self.set_up_command_table(required_arg=True)

        # action
        res = self.application.execute(self.argv[1:])

        # assert
        self.assertEqual(res.result, 'myRG')

    @mock.patch.dict(os.environ, {AzConfig.env_var_name('defaults', 'group'): 'myRG'})
    def test_apply_configured_defaults_on_optional_arg(self):
        self.set_up_command_table(required_arg=False)

        # action
        res = self.application.execute(self.argv[1:])

        # assert
        self.assertEqual(res.result, 'myRG')
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:61,代码来源:test_command_with_configured_defaults.py

示例6: test_help_global_params

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_global_params(self, mock_register_extensions, _):
        def register_globals(global_group):
            global_group.add_argument(
                "--query2",
                dest="_jmespath_query",
                metavar="JMESPATH",
                help="JMESPath query string. See http://jmespath.org/ " "for more information and examples.",
            )

        mock_register_extensions.return_value = None

        def _register_global_parser(appl):
            # noqa pylint: disable=protected-access
            appl._event_handlers[appl.GLOBAL_PARSER_CREATED].append(register_globals)

        mock_register_extensions.side_effect = _register_global_parser

        def test_handler():
            pass

        command = CliCommand("n1", test_handler)
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        command.help = """
            long-summary: |
                line1
                line2
        """
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())

        s = """
Command
    az n1
        Line1
        line2.

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
    --query2 : JMESPath query string. See http://jmespath.org/ for more information and examples.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:55,代码来源:test_help.py

示例7: test_help_params_documentations

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_params_documentations(self, _):
        app = Application(Configuration())

        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('foobar', '--foobar', '-fb', required=False)
        command.add_argument('foobar2', '--foobar2', '-fb2', required=True)
        command.add_argument('foobar3', '--foobar3', '-fb3', required=False, help='the foobar3')
        command.help = """
            parameters:
                - name: --foobar -fb
                  type: string
                  required: false
                  short-summary: one line partial sentence
                  long-summary: text, markdown, etc.
                  populator-commands:
                    - az vm list
                    - default
                - name: --foobar2 -fb2
                  type: string
                  required: true
                  short-summary: one line partial sentence
                  long-summary: paragraph(s)
            """
        cmd_table = {'n1': command}

        config = Configuration()
        config.get_command_table = lambda argv: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        s = """
Command
    az n1

Arguments
    --foobar2 -fb2 [Required]: One line partial sentence.
        Paragraph(s).
    --foobar -fb             : One line partial sentence.  Values from: az vm list, default.
        Text, markdown, etc.
    --foobar3 -fb3           : The foobar3.

Global Arguments
    --help -h                : Show this help message and exit.
"""
        self.assertEqual(s, io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:51,代码来源:test_help.py

示例8: test_choice_list_with_ints

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_choice_list_with_ints(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False, choices=[1, 2, 3])
        command.add_argument('b', '-b', required=False, choices=['a', 'b', 'c'])
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application()
        app.initialize(config)
        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:17,代码来源:test_help.py

示例9: test_client_request_id_is_refreshed_after_execution

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_client_request_id_is_refreshed_after_execution(self):
        def _handler(args):
            return True

        config = Configuration()
        config.get_command_table = lambda *_: {'test': CliCommand('test', _handler)}
        app = Application(config)

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        old_id = app.session['headers']['x-ms-client-request-id']

        app.execute(['test'])
        self.assertIn('x-ms-client-request-id', app.session['headers'])
        self.assertNotEquals(old_id, app.session['headers']['x-ms-client-request-id'])
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:17,代码来源:test_application.py

示例10: test_help_plain_short_description

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_plain_short_description(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler, description="the description")
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())
        self.assertEqual(True, "n1: The description." in io.getvalue())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:18,代码来源:test_help.py

示例11: test_help_global_params

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_global_params(self, mock_register_extensions, _):
        def register_globals(global_group):
            global_group.add_argument('--query2', dest='_jmespath_query', metavar='JMESPATH',
                                      help='JMESPath query string. See http://jmespath.org/ '
                                      'for more information and examples.')

        mock_register_extensions.return_value = None
        mock_register_extensions.side_effect = lambda app: \
            app._event_handlers[app.GLOBAL_PARSER_CREATED].append(register_globals) # pylint: disable=protected-access

        def test_handler():
            pass

        command = CliCommand('n1', test_handler)
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = """
            long-summary: |
                line1
                line2
        """
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())

        s = """
Command
    az n1
        Line1
        line2.

Arguments
    --arg -a
    -b

Global Arguments
    --help -h: Show this help message and exit.
    --query2 : JMESPath query string. See http://jmespath.org/ for more information and examples.
"""

        self.assertEqual(s, io.getvalue())
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:48,代码来源:test_help.py

示例12: test_help_docstring_description_overrides_short_description

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_docstring_description_overrides_short_description(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler, description='short description')
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = 'short-summary: docstring summary'
        cmd_table = {'n1': command}

        config = Configuration()
        config.get_command_table = lambda args: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        self.assertEqual(True, 'n1: Docstring summary.' in io.getvalue())
开发者ID:LukaszStem,项目名称:azure-cli,代码行数:19,代码来源:test_help.py

示例13: test_help_long_description_and_short_description

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_long_description_and_short_description(self):
        def test_handler():
            pass

        command = CliCommand('n1', test_handler, description='short description')
        command.add_argument('arg', '--arg', '-a', required=False)
        command.add_argument('b', '-b', required=False)
        command.help = 'long description'
        cmd_table = {'n1': command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute('n1 -h'.split())
        self.assertEqual(True, io.getvalue().startswith('\nCommand\n    az n1: Short description.\n        Long description.')) # pylint: disable=line-too-long
开发者ID:BurtBiel,项目名称:azure-cli,代码行数:19,代码来源:test_help.py

示例14: test_help_param

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_param(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler)
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application()
        app.initialize(config)
        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())

        with self.assertRaises(SystemExit):
            app.execute("n1 --help".split())
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:20,代码来源:test_help.py

示例15: test_help_long_description_and_short_description

# 需要导入模块: from azure.cli.core.application import Application [as 别名]
# 或者: from azure.cli.core.application.Application import execute [as 别名]
    def test_help_long_description_and_short_description(self):
        def test_handler():
            pass

        command = CliCommand("n1", test_handler, description="short description")
        command.add_argument("arg", "--arg", "-a", required=False)
        command.add_argument("b", "-b", required=False)
        command.help = "long description"
        cmd_table = {"n1": command}

        config = Configuration([])
        config.get_command_table = lambda: cmd_table
        app = Application(config)

        with self.assertRaises(SystemExit):
            app.execute("n1 -h".split())
        self.assertEqual(
            True, io.getvalue().startswith("\nCommand\n    az n1: Short description.\n        Long description.")
        )  # pylint: disable=line-too-long
开发者ID:yugangw-msft,项目名称:azure-cli,代码行数:21,代码来源:test_help.py


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