from argparse import ArgumentParser
from awscli.testutils import unittest
from awscli.argparser import CommandAction
class TestCommandAction(unittest.TestCase):
def setUp(self):
self.parser = ArgumentParser()
def test_choices(self):
command_table = {'pre-existing': object()}
self.parser.add_argument(
'command', action=CommandAction, command_table=command_table)
parsed_args = self.parser.parse_args(['pre-existing'])
self.assertEqual(parsed_args.command, 'pre-existing')
def test_choices_added_after(self):
command_table = {'pre-existing': object()}
self.parser.add_argument(
'command', action=CommandAction, command_table=command_table)
command_table['after'] = object()
parsed_args = self.parser.parse_args(['pre-existing'])
self.assertEqual(parsed_args.command, 'pre-existing')
parsed_args = self.parser.parse_args(['after'])
self.assertEqual(parsed_args.command, 'after')