本文整理汇总了Python中azure.cli.core.mock.DummyCli.loader方法的典型用法代码示例。如果您正苦于以下问题:Python DummyCli.loader方法的具体用法?Python DummyCli.loader怎么用?Python DummyCli.loader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类azure.cli.core.mock.DummyCli
的用法示例。
在下文中一共展示了DummyCli.loader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_simple_commands
# 需要导入模块: from azure.cli.core.mock import DummyCli [as 别名]
# 或者: from azure.cli.core.mock.DummyCli import loader [as 别名]
def test_register_simple_commands(self):
def test_handler1():
pass
def test_handler2():
pass
cli = DummyCli()
cli.loader = mock.MagicMock()
cli.loader.cli_ctx = cli
command = AzCliCommand(cli.loader, 'command the-name', test_handler1)
command2 = AzCliCommand(cli.loader, 'sub-command the-second-name', test_handler2)
cmd_table = {'command the-name': command, 'sub-command the-second-name': command2}
cli.commands_loader.command_table = cmd_table
parser = AzCliCommandParser(cli)
parser.load_command_table(cli.commands_loader)
args = parser.parse_args('command the-name'.split())
self.assertIs(args.func, command)
args = parser.parse_args('sub-command the-second-name'.split())
self.assertIs(args.func, command2)
AzCliCommandParser.error = VerifyError(self,)
parser.parse_args('sub-command'.split())
self.assertTrue(AzCliCommandParser.error.called)
示例2: test_case_insensitive_enum_choices
# 需要导入模块: from azure.cli.core.mock import DummyCli [as 别名]
# 或者: from azure.cli.core.mock.DummyCli import loader [as 别名]
def test_case_insensitive_enum_choices(self):
from enum import Enum
class TestEnum(Enum): # pylint: disable=too-few-public-methods
opt1 = "ALL_CAPS"
opt2 = "camelCase"
opt3 = "snake_case"
def test_handler():
pass
cli = DummyCli()
cli.loader = mock.MagicMock()
cli.loader.cli_ctx = cli
command = AzCliCommand(cli.loader, 'test command', test_handler)
command.add_argument('opt', '--opt', required=True, **enum_choice_list(TestEnum))
cmd_table = {'test command': command}
cli.commands_loader.command_table = cmd_table
parser = AzCliCommandParser(cli)
parser.load_command_table(cli.commands_loader)
args = parser.parse_args('test command --opt alL_cAps'.split())
self.assertEqual(args.opt, 'ALL_CAPS')
args = parser.parse_args('test command --opt CAMELCASE'.split())
self.assertEqual(args.opt, 'camelCase')
args = parser.parse_args('test command --opt sNake_CASE'.split())
self.assertEqual(args.opt, 'snake_case')
示例3: test_parser_error_spellchecker
# 需要导入模块: from azure.cli.core.mock import DummyCli [as 别名]
# 或者: from azure.cli.core.mock.DummyCli import loader [as 别名]
def test_parser_error_spellchecker(self):
cli = DummyCli()
main_loader = MainCommandsLoader(cli)
cli.loader = main_loader
cli.loader.load_command_table(None)
parser = cli.parser_cls(cli)
parser.load_command_table(cli.loader)
logger_msgs = []
choice_lists = []
original_get_close_matches = difflib.get_close_matches
def mock_log_error(_, msg):
logger_msgs.append(msg)
def mock_get_close_matches(*args, **kwargs):
choice_lists.append(original_get_close_matches(*args, **kwargs))
# run multiple faulty commands and save error logs, as well as close matches
with mock.patch('logging.Logger.error', mock_log_error), \
mock.patch('difflib.get_close_matches', mock_get_close_matches):
faulty_cmd_args = [
'test module1 --opt enum_1',
'test extension1 --opt enum_1',
'test foo_bar --opt enum_3',
'test module --opt enum_3',
'test extension --opt enum_3'
]
for text in faulty_cmd_args:
with self.assertRaises(SystemExit):
parser.parse_args(text.split())
parser.parse_args('test module --opt enum_1'.split())
# assert the right type of error msg is logged for command vs argument parsing
self.assertEqual(len(logger_msgs), 5)
for msg in logger_msgs[:3]:
self.assertIn("not in the", msg)
self.assertIn("command group", msg)
for msg in logger_msgs[3:]:
self.assertIn("not a valid value for '--opt'.", msg)
# assert the right choices are matched as "close".
# If these don't hold, matching algorithm should be deemed flawed.
for choices in choice_lists[:2]:
self.assertEqual(len(choices), 1)
self.assertEqual(len(choice_lists[2]), 0)
for choices in choice_lists[3:]:
self.assertEqual(len(choices), 2)
for choice in ['enum_1', 'enum_2']:
self.assertIn(choice, choices)
示例4: test_register_command_from_extension
# 需要导入模块: from azure.cli.core.mock import DummyCli [as 别名]
# 或者: from azure.cli.core.mock.DummyCli import loader [as 别名]
def test_register_command_from_extension(self):
from azure.cli.core.commands import _load_command_loader
cli = DummyCli()
main_loader = MainCommandsLoader(cli)
cli.loader = main_loader
cmd_tbl = cli.loader.load_command_table(None)
ext1 = cmd_tbl['hello noodle']
ext2 = cmd_tbl['hello world']
self.assertTrue(isinstance(ext1.command_source, ExtensionCommandSource))
self.assertFalse(ext1.command_source.overrides_command)
self.assertTrue(isinstance(ext2.command_source, ExtensionCommandSource))
self.assertTrue(ext2.command_source.overrides_command)
示例5: test_nargs_parameter
# 需要导入模块: from azure.cli.core.mock import DummyCli [as 别名]
# 或者: from azure.cli.core.mock.DummyCli import loader [as 别名]
def test_nargs_parameter(self):
def test_handler():
pass
cli = DummyCli()
cli.loader = mock.MagicMock()
cli.loader.cli_ctx = cli
command = AzCliCommand(cli.loader, 'test command', test_handler)
command.add_argument('req', '--req', required=True, nargs=2)
cmd_table = {'test command': command}
cli.commands_loader.command_table = cmd_table
parser = AzCliCommandParser(cli)
parser.load_command_table(cli.commands_loader)
args = parser.parse_args('test command --req yep nope'.split())
self.assertIs(args.func, command)
AzCliCommandParser.error = VerifyError(self)
parser.parse_args('test command -req yep'.split())
self.assertTrue(AzCliCommandParser.error.called)