1119
1119
def setUp(self):
1120
1120
self.parser = argparse.ArgumentParser()
1121
1121
add_command_line_options(self.parser)
1122
def commands_from_args(self, args):
1123
self.options = self.parser.parse_args(args)
1124
return commands_from_options(self.options)
1122
def assert_command_from_args(self, args, command_cls, **cmd_attrs):
1123
"""Assert that parsing ARGS should result in an instance of
1124
COMMAND_CLS with (optionally) all supplied attributes (CMD_ATTRS)."""
1125
options = self.parser.parse_args(args)
1126
commands = commands_from_options(options)
1127
self.assertEqual(len(commands), 1)
1128
command = commands[0]
1129
self.assertIsInstance(command, command_cls)
1130
for key, value in cmd_attrs.items():
1131
self.assertEqual(getattr(command, key), value)
1125
1132
def test_default_is_show_table(self):
1126
commands = self.commands_from_args([])
1127
self.assertEqual(len(commands), 1)
1128
command = commands[0]
1129
self.assertIsInstance(command, PrintTableCmd)
1130
self.assertEqual(command.verbose, False)
1133
self.assert_command_from_args([], PrintTableCmd,
1131
1135
def test_show_table_verbose(self):
1132
commands = self.commands_from_args(["--verbose"])
1133
self.assertEqual(len(commands), 1)
1134
command = commands[0]
1135
self.assertIsInstance(command, PrintTableCmd)
1136
self.assertEqual(command.verbose, True)
1136
self.assert_command_from_args(["--verbose"], PrintTableCmd,
1137
1138
def test_enable(self):
1138
commands = self.commands_from_args(["--enable", "foo"])
1139
self.assertEqual(len(commands), 1)
1140
command = commands[0]
1141
self.assertIsInstance(command, EnableCmd)
1142
self.assertEqual(self.options.client, ["foo"])
1139
self.assert_command_from_args(["--enable"], EnableCmd)
1143
1140
def test_disable(self):
1144
commands = self.commands_from_args(["--disable", "foo"])
1145
self.assertEqual(len(commands), 1)
1146
command = commands[0]
1147
self.assertIsInstance(command, DisableCmd)
1148
self.assertEqual(self.options.client, ["foo"])
1141
self.assert_command_from_args(["--disable"], DisableCmd)