|
32 | 32 | from awscli.arguments import ListArgument, BooleanArgument |
33 | 33 | from awscli.arguments import create_argument_model_from_schema |
34 | 34 |
|
| 35 | +from awscli.argparser import ArgTableArgParser |
| 36 | + |
35 | 37 | import argparse |
36 | 38 |
|
37 | 39 | # These tests use real service types so that we can |
@@ -452,27 +454,6 @@ def test_csv_syntax_errors(self): |
452 | 454 | with self.assertRaisesRegex(ParamError, error_msg): |
453 | 455 | self.parse_shorthand(p, ['ParameterKey=key,ParameterValue="foo,bar\'']) |
454 | 456 |
|
455 | | - def _test_argument_escapes_percent(self, arg_class, arg_type, doc_string, expected_substring): |
456 | | - argument = self.create_argument({'Test': {'type': arg_type}}) |
457 | | - argument.argument_model.members['Test'].documentation = doc_string |
458 | | - arg = arg_class('test-arg', argument.argument_model.members['Test'], None, False) |
459 | | - parser = argparse.ArgumentParser() |
460 | | - arg.add_to_parser(parser) |
461 | | - action = parser._actions[-1] |
462 | | - self.assertIn(expected_substring, action.help) |
463 | | - |
464 | | - def test_cli_argument_escapes_percent_in_symbols(self): |
465 | | - self._test_argument_escapes_percent(CLIArgument, 'string', 'Symbols: ! @ # $ % ^ & * ( )', '% ^') |
466 | | - |
467 | | - def test_cli_argument_escapes_percent_in_url_encoding(self): |
468 | | - self._test_argument_escapes_percent(CLIArgument, 'string', 'test_file%283%29.png', '%28') |
469 | | - |
470 | | - def test_boolean_argument_escapes_percent_in_symbols(self): |
471 | | - self._test_argument_escapes_percent(BooleanArgument, 'boolean', 'Symbols: ! @ # $ % ^ & * ( )', '% ^') |
472 | | - |
473 | | - def test_boolean_argument_escapes_percent_in_url_encoding(self): |
474 | | - self._test_argument_escapes_percent(BooleanArgument, 'boolean', 'test_file%283%29.png', '%28') |
475 | | - |
476 | 457 | class TestParamShorthandCustomArguments(BaseArgProcessTest): |
477 | 458 |
|
478 | 459 | def setUp(self): |
@@ -915,6 +896,27 @@ def test_json_value_decode_error(self): |
915 | 896 | with self.assertRaises(ParamError): |
916 | 897 | unpack_cli_arg(self.p, value) |
917 | 898 |
|
| 899 | +class TestArgumentPercentEscaping(BaseArgProcessTest): |
| 900 | + def _test_percent_escaping(self, arg_type, arg_class, doc_string): |
| 901 | + argument = self.create_argument({'Test': {'type': arg_type}}) |
| 902 | + argument.argument_model.members['Test'].documentation = doc_string |
| 903 | + arg = arg_class('test-arg', argument.argument_model.members['Test'], mock.Mock(), mock.Mock(), is_required=False) |
| 904 | + arg_table = {arg.name: arg} |
| 905 | + parser = ArgTableArgParser(arg_table) |
| 906 | + help_output = parser.format_help() |
| 907 | + self.assertIn(arg.cli_name, help_output) |
| 908 | + |
| 909 | + def test_cli_argument_escapes_percent(self): |
| 910 | + self._test_percent_escaping('integer', CLIArgument, 'Symbols: % ^ & *') |
| 911 | + |
| 912 | + def test_boolean_argument_escapes_percent(self): |
| 913 | + self._test_percent_escaping('boolean', BooleanArgument, 'Symbols: % ^ & *') |
| 914 | + |
| 915 | + def test_cli_argument_escapes_url_encoded_percent(self): |
| 916 | + self._test_percent_escaping('integer', CLIArgument, 'File: test%28file%29.png') |
| 917 | + |
| 918 | + def test_boolean_argument_escapes_url_encoded_percent(self): |
| 919 | + self._test_percent_escaping('boolean', BooleanArgument, 'File: test%28file%29.png') |
918 | 920 |
|
919 | 921 | if __name__ == '__main__': |
920 | 922 | unittest.main() |
0 commit comments