本文整理匯總了Python中azure.cli.core.mock.DummyCli.parser_cls方法的典型用法代碼示例。如果您正苦於以下問題:Python DummyCli.parser_cls方法的具體用法?Python DummyCli.parser_cls怎麽用?Python DummyCli.parser_cls使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類azure.cli.core.mock.DummyCli
的用法示例。
在下文中一共展示了DummyCli.parser_cls方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parser_error_spellchecker
# 需要導入模塊: from azure.cli.core.mock import DummyCli [as 別名]
# 或者: from azure.cli.core.mock.DummyCli import parser_cls [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)