|
32 | 32 | from awscli.arguments import ListArgument, BooleanArgument |
33 | 33 | from awscli.arguments import create_argument_model_from_schema |
34 | 34 |
|
35 | | -from awscli.clidriver import ServiceOperation, CLIOperationCaller |
36 | | -from awscli.argparser import ArgTableArgParser |
37 | | - |
| 35 | +import argparse |
38 | 36 |
|
39 | 37 | # These tests use real service types so that we can |
40 | 38 | # verify the real shapes of services. |
@@ -454,6 +452,26 @@ def test_csv_syntax_errors(self): |
454 | 452 | with self.assertRaisesRegex(ParamError, error_msg): |
455 | 453 | self.parse_shorthand(p, ['ParameterKey=key,ParameterValue="foo,bar\'']) |
456 | 454 |
|
| 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') |
457 | 475 |
|
458 | 476 | class TestParamShorthandCustomArguments(BaseArgProcessTest): |
459 | 477 |
|
@@ -897,28 +915,6 @@ def test_json_value_decode_error(self): |
897 | 915 | with self.assertRaises(ParamError): |
898 | 916 | unpack_cli_arg(self.p, value) |
899 | 917 |
|
900 | | -class TestPercentInDocumentation(BaseArgProcessTest): |
901 | | - def test_percent_characters_escaped_in_argument_help(self): |
902 | | - operation_caller = CLIOperationCaller(self.session) |
903 | | - for service_name in self.session.get_available_services(): |
904 | | - service_model = self.session.get_service_model(service_name) |
905 | | - for operation_name in service_model.operation_names: |
906 | | - operation_model = service_model.operation_model(operation_name) |
907 | | - if not operation_model.input_shape: |
908 | | - continue |
909 | | - has_percent = any( |
910 | | - '%' in (member.documentation or '') |
911 | | - for member in operation_model.input_shape.members.values() |
912 | | - ) |
913 | | - if has_percent: |
914 | | - service_op = ServiceOperation( |
915 | | - name=xform_name(operation_name, '-'), |
916 | | - parent_name=service_name, |
917 | | - operation_caller=operation_caller, |
918 | | - operation_model=operation_model, |
919 | | - session=self.session, |
920 | | - ) |
921 | | - ArgTableArgParser(service_op.arg_table) |
922 | 918 |
|
923 | 919 | if __name__ == '__main__': |
924 | 920 | unittest.main() |
0 commit comments