本文整理匯總了Python中azure.cli.core.mock.DummyCli.invoke方法的典型用法代碼示例。如果您正苦於以下問題:Python DummyCli.invoke方法的具體用法?Python DummyCli.invoke怎麽用?Python DummyCli.invoke使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azure.cli.core.mock.DummyCli
的用法示例。
在下文中一共展示了DummyCli.invoke方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_help_loads
# 需要導入模塊: from azure.cli.core.mock import DummyCli [as 別名]
# 或者: from azure.cli.core.mock.DummyCli import invoke [as 別名]
def test_help_loads(self):
from azure.cli.core.commands.arm import register_global_subscription_argument, register_ids_argument
import knack.events as events
cli = DummyCli()
parser_dict = {}
cli = DummyCli()
help_ctx = cli.help_cls(cli)
try:
cli.invoke(['-h'])
except SystemExit:
pass
cmd_tbl = cli.invocation.commands_loader.command_table
cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
for cmd in cmd_tbl:
try:
cmd_tbl[cmd].loader.command_name = cmd
cmd_tbl[cmd].loader.load_arguments(cmd)
except KeyError:
pass
cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_global_subscription_argument)
cli.register_event(events.EVENT_INVOKER_POST_CMD_TBL_CREATE, register_ids_argument)
cli.raise_event(events.EVENT_INVOKER_CMD_TBL_LOADED, command_table=cmd_tbl)
cli.invocation.parser.load_command_table(cli.invocation.commands_loader)
_store_parsers(cli.invocation.parser, parser_dict)
for name, parser in parser_dict.items():
try:
help_file = GroupHelpFile(help_ctx, name, parser) if _is_group(parser) \
else CliCommandHelpFile(help_ctx, name, parser)
help_file.load(parser)
except Exception as ex:
raise HelpAuthoringException('{}, {}'.format(name, ex))
示例2: mock_echo_args
# 需要導入模塊: from azure.cli.core.mock import DummyCli [as 別名]
# 或者: from azure.cli.core.mock.DummyCli import invoke [as 別名]
def mock_echo_args(command_name, parameters):
from azure.cli.core.mock import DummyCli
try:
# TODO: continue work on this...
argv = ' '.join((command_name, parameters)).split()
cli = DummyCli()
cli.invoke(argv)
command_table = cli.invocation.commands_loader.command_table
prefunc = command_table[command_name].handler
command_table[command_name].handler = lambda args: args
cli.invoke(argv)
parsed_namespace = None # continue this too...
return parsed_namespace
finally:
command_table[command_name].handler = prefunc
示例3: test_client_request_id_is_refreshed_after_execution
# 需要導入模塊: from azure.cli.core.mock import DummyCli [as 別名]
# 或者: from azure.cli.core.mock.DummyCli import invoke [as 別名]
def test_client_request_id_is_refreshed_after_execution(self):
def _handler(args):
return True
class TestCommandsLoader(AzCommandsLoader):
def load_command_table(self, args):
super(TestCommandsLoader, self).load_command_table(args)
self.command_table = {'test': AzCliCommand(self, 'test', _handler)}
return self.command_table
cli = DummyCli(commands_loader_cls=TestCommandsLoader)
cli.invoke(['test'])
self.assertIn('x-ms-client-request-id', cli.data['headers'])
old_id = cli.data['headers']['x-ms-client-request-id']
cli.invoke(['test'])
self.assertIn('x-ms-client-request-id', cli.data['headers'])
self.assertNotEquals(old_id, cli.data['headers']['x-ms-client-request-id'])
示例4: TestHelpLoads
# 需要導入模塊: from azure.cli.core.mock import DummyCli [as 別名]
# 或者: from azure.cli.core.mock.DummyCli import invoke [as 別名]
#.........這裏部分代碼省略.........
{
"link": {
"command": "az test show",
"title": "Show test details. Json file"
}
}
]
},
{
"name": "ARG4",
"summary": "Arg4's summary, json. Positional arg, not required"
}
],
"examples": [
{
"summary": "A simple example from json",
"description": "More detail on the simple example.",
"command": "az test alpha --arg1 alpha --arg2 beta --arg3 chi",
"supported-profiles": "2018-03-01-hybrid, latest"
}
]
}
}
]
}
"""
return self._create_new_temp_file(json_help, suffix="help.json")
# Mock logic in core.MainCommandsLoader.load_command_table for retrieving installed modules.
@mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)])
@mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader)
def test_basic(self, mocked_load, mocked_pkg_util):
with self.assertRaises(SystemExit):
self.test_cli.invoke(["test", "alpha", "-h"])
# Mock logic in core.MainCommandsLoader.load_command_table for retrieving installed modules.
@mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)])
@mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader)
def test_load_from_help_py(self, mocked_load, mocked_pkg_util):
self.set_help_py()
create_invoker_and_load_cmds_and_args(self.test_cli)
group_help_obj = next((help for help in get_all_help(self.test_cli) if help.command == "test"), None)
command_help_obj = next((help for help in get_all_help(self.test_cli) if help.command == "test alpha"), None)
# Test that group and command help are successfully displayed.
with self.assertRaises(SystemExit):
self.test_cli.invoke(["test", "-h"])
with self.assertRaises(SystemExit):
self.test_cli.invoke(["test", "alpha", "-h"])
# Test group help
self.assertIsNotNone(group_help_obj)
self.assertEqual(group_help_obj.short_summary, "Foo Bar Group.")
self.assertEqual(group_help_obj.long_summary, "Foo Bar Baz Group is a fun group.")
# Test command help
self.assertIsNotNone(command_help_obj)
self.assertEqual(command_help_obj.short_summary, "Foo Bar Command.")
self.assertEqual(command_help_obj.long_summary, "Foo Bar Baz Command is a fun command.")
# test that parameters and help are loaded from command function docstring, argument registry help and help.py
obj_param_dict = {param.name: param for param in command_help_obj.parameters}
param_name_set = {"--arg1 -a", "--arg2 -b", "--arg3", "ARG4"}
self.assertTrue(set(obj_param_dict.keys()).issuperset(param_name_set))
self.assertEqual(obj_param_dict["--arg3"].short_summary, "Arg3's docstring help text.")