Skip to content

Commit f1a4c77

Browse files
committed
Use ArgTableArgParser in percent escaping tests
Update tests to use AWS CLI's ArgTableArgParser instead of standard argparse.ArgumentParser to properly test the CLI's argument parser abstraction. Extract common test logic into helper method to reduce code duplication.
1 parent 8113b5d commit f1a4c77

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

tests/unit/test_argprocess.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
from awscli.arguments import ListArgument, BooleanArgument
3333
from awscli.arguments import create_argument_model_from_schema
3434

35+
from awscli.argparser import ArgTableArgParser
36+
3537
import argparse
3638

3739
# These tests use real service types so that we can
@@ -452,27 +454,6 @@ def test_csv_syntax_errors(self):
452454
with self.assertRaisesRegex(ParamError, error_msg):
453455
self.parse_shorthand(p, ['ParameterKey=key,ParameterValue="foo,bar\''])
454456

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-
476457
class TestParamShorthandCustomArguments(BaseArgProcessTest):
477458

478459
def setUp(self):
@@ -915,6 +896,27 @@ def test_json_value_decode_error(self):
915896
with self.assertRaises(ParamError):
916897
unpack_cli_arg(self.p, value)
917898

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')
918920

919921
if __name__ == '__main__':
920922
unittest.main()

0 commit comments

Comments
 (0)