forked from aws/aws-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_argparser.py
More file actions
43 lines (36 loc) · 1.71 KB
/
test_argparser.py
File metadata and controls
43 lines (36 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
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()
# The pre-existing command should still be able to be parsed
parsed_args = self.parser.parse_args(['pre-existing'])
self.assertEqual(parsed_args.command, 'pre-existing')
# The command added after the argument's creation should be
# able to be parsed as well.
parsed_args = self.parser.parse_args(['after'])
self.assertEqual(parsed_args.command, 'after')