Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/test_argparser.py
1566 views
1
# Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from argparse import ArgumentParser
14
15
from awscli.testutils import unittest
16
from awscli.argparser import CommandAction
17
18
19
class TestCommandAction(unittest.TestCase):
20
def setUp(self):
21
self.parser = ArgumentParser()
22
23
def test_choices(self):
24
command_table = {'pre-existing': object()}
25
self.parser.add_argument(
26
'command', action=CommandAction, command_table=command_table)
27
parsed_args = self.parser.parse_args(['pre-existing'])
28
self.assertEqual(parsed_args.command, 'pre-existing')
29
30
def test_choices_added_after(self):
31
command_table = {'pre-existing': object()}
32
self.parser.add_argument(
33
'command', action=CommandAction, command_table=command_table)
34
command_table['after'] = object()
35
36
# The pre-existing command should still be able to be parsed
37
parsed_args = self.parser.parse_args(['pre-existing'])
38
self.assertEqual(parsed_args.command, 'pre-existing')
39
40
# The command added after the argument's creation should be
41
# able to be parsed as well.
42
parsed_args = self.parser.parse_args(['after'])
43
self.assertEqual(parsed_args.command, 'after')
44
45