<s> import json <EOL> import mock <EOL> from botocore import xform_name <EOL> from botocore import model <EOL> from botocore . compat import OrderedDict <EOL> from awscli . testutils import unittest <EOL> from awscli . testutils import BaseCLIDriverTest <EOL> from awscli . testutils import temporary_file <EOL> from awscli . help import OperationHelpCommand <EOL> from awscli . argprocess import detect_shape_structure <EOL> from awscli . argprocess import unpack_cli_arg <EOL> from awscli . argprocess import ParamShorthand <EOL> from awscli . argprocess import ParamShorthandDocGen <EOL> from awscli . argprocess import ParamError <EOL> from awscli . argprocess import ParamUnknownKeyError <EOL> from awscli . argprocess import uri_param <EOL> from awscli . arguments import CustomArgument , CLIArgument <EOL> from awscli . arguments import ListArgument , BooleanArgument <EOL> from awscli . arguments import create_argument_model_from_schema <EOL> class BaseArgProcessTest ( BaseCLIDriverTest ) : <EOL> def get_param_model ( self , dotted_name ) : <EOL> service_name , operation_name , param_name = dotted_name . split ( '<STR_LIT:.>' ) <EOL> service_model = self . session . get_service_model ( service_name ) <EOL> operation = service_model . operation_model ( operation_name ) <EOL> input_shape = operation . input_shape <EOL> required_arguments = input_shape . required_members <EOL> is_required = param_name in required_arguments <EOL> member_shape = input_shape . members [ param_name ] <EOL> type_name = member_shape . type_name <EOL> cli_arg_name = xform_name ( param_name , '<STR_LIT:->' ) <EOL> if type_name == '<STR_LIT>' : <EOL> cls = BooleanArgument <EOL> elif type_name == '<STR_LIT:list>' : <EOL> cls = ListArgument <EOL> else : <EOL> cls = CLIArgument <EOL> return cls ( cli_arg_name , member_shape , mock . Mock ( ) , is_required ) <EOL> class TestURIParams ( BaseArgProcessTest ) : <EOL> def test_uri_param ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> with temporary_file ( '<STR_LIT>' ) as f : <EOL> json_argument = json . dumps ( [ { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" ] } ] ) <EOL> f . write ( json_argument ) <EOL> f . flush ( ) <EOL> result = uri_param ( '<STR_LIT>' , p , '<STR_LIT>' % f . name ) <EOL> self . assertEqual ( result , json_argument ) <EOL> def test_uri_param_no_paramfile_false ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> p . no_paramfile = False <EOL> with temporary_file ( '<STR_LIT>' ) as f : <EOL> json_argument = json . dumps ( [ { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" ] } ] ) <EOL> f . write ( json_argument ) <EOL> f . flush ( ) <EOL> result = uri_param ( '<STR_LIT>' , p , '<STR_LIT>' % f . name ) <EOL> self . assertEqual ( result , json_argument ) <EOL> def test_uri_param_no_paramfile_true ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> p . no_paramfile = True <EOL> with temporary_file ( '<STR_LIT>' ) as f : <EOL> json_argument = json . dumps ( [ { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" ] } ] ) <EOL> f . write ( json_argument ) <EOL> f . flush ( ) <EOL> result = uri_param ( '<STR_LIT>' , p , '<STR_LIT>' % f . name ) <EOL> self . assertEqual ( result , None ) <EOL> class TestArgShapeDetection ( BaseArgProcessTest ) : <EOL> def assert_shape_type ( self , spec , expected_type ) : <EOL> p = self . get_param_model ( spec ) <EOL> actual_structure = detect_shape_structure ( p . argument_model ) <EOL> self . assertEqual ( actual_structure , expected_type ) <EOL> def assert_custom_shape_type ( self , schema , expected_type ) : <EOL> argument_model = create_argument_model_from_schema ( schema ) <EOL> argument = CustomArgument ( '<STR_LIT:test>' , argument_model = argument_model ) <EOL> actual_structure = detect_shape_structure ( argument . argument_model ) <EOL> self . assertEqual ( actual_structure , expected_type ) <EOL> def test_detect_scalar ( self ) : <EOL> self . assert_shape_type ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_detect_list_of_strings ( self ) : <EOL> self . assert_shape_type ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_detect_structure_of_scalars ( self ) : <EOL> self . assert_shape_type ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_list_structure_scalars ( self ) : <EOL> self . assert_shape_type ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_list_structure_scalars_2 ( self ) : <EOL> self . assert_shape_type ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_list_structure_of_list_and_strings ( self ) : <EOL> self . assert_shape_type ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_map_scalar ( self ) : <EOL> self . assert_shape_type ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_struct_list_scalar ( self ) : <EOL> self . assert_custom_shape_type ( { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> } <EOL> } , '<STR_LIT>' ) <EOL> def test_recursive_shape ( self ) : <EOL> shapes = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:A>' : { '<STR_LIT>' : '<STR_LIT>' } <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:B>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT:C>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } <EOL> } <EOL> shape = model . StructureShape ( shape_name = '<STR_LIT>' , <EOL> shape_model = shapes [ '<STR_LIT>' ] , <EOL> shape_resolver = model . ShapeResolver ( <EOL> shape_map = shapes ) ) <EOL> self . assertIn ( '<STR_LIT>' , detect_shape_structure ( shape ) ) <EOL> class TestParamShorthand ( BaseArgProcessTest ) : <EOL> maxDiff = None <EOL> def setUp ( self ) : <EOL> super ( TestParamShorthand , self ) . setUp ( ) <EOL> self . simplify = ParamShorthand ( ) <EOL> def test_simplify_structure_scalars ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> value = '<STR_LIT>' <EOL> json_value = '<STR_LIT>' <EOL> returned = self . simplify ( p , value ) <EOL> json_version = unpack_cli_arg ( p , json_value ) <EOL> self . assertEqual ( returned , json_version ) <EOL> def test_parse_boolean_shorthand ( self ) : <EOL> bool_param = mock . Mock ( ) <EOL> bool_param . cli_type_name = '<STR_LIT>' <EOL> bool_param . argument_model . type_name = '<STR_LIT>' <EOL> self . assertTrue ( unpack_cli_arg ( bool_param , True ) ) <EOL> self . assertTrue ( unpack_cli_arg ( bool_param , '<STR_LIT:True>' ) ) <EOL> self . assertTrue ( unpack_cli_arg ( bool_param , '<STR_LIT:true>' ) ) <EOL> self . assertFalse ( unpack_cli_arg ( bool_param , False ) ) <EOL> self . assertFalse ( unpack_cli_arg ( bool_param , '<STR_LIT:False>' ) ) <EOL> self . assertFalse ( unpack_cli_arg ( bool_param , '<STR_LIT:false>' ) ) <EOL> def test_simplify_map_scalar ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> returned = self . simplify ( p , '<STR_LIT>' ) <EOL> json_version = unpack_cli_arg ( p , '<STR_LIT>' ) <EOL> self . assertEqual ( returned , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( returned , json_version ) <EOL> def test_list_structure_scalars ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> returned = self . simplify ( p , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( returned , [ { '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' } ] ) <EOL> def test_list_structure_list_scalar ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> expected = [ { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } , <EOL> { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" ] } ] <EOL> returned = self . simplify ( <EOL> p , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( returned , expected ) <EOL> returned2 = self . simplify ( <EOL> p , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( returned2 , expected ) <EOL> returned3 = self . simplify ( <EOL> p , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( returned3 , expected ) <EOL> def test_parse_empty_values ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> expected = [ { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ "<STR_LIT>" , "<STR_LIT>" ] } , <EOL> { "<STR_LIT:Name>" : "<STR_LIT>" , "<STR_LIT>" : [ '<STR_LIT>' ] } ] <EOL> returned = self . simplify ( <EOL> p , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . assertEqual ( returned , expected ) <EOL> def test_list_structure_list_scalar_2 ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> expected = [ <EOL> { "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : <NUM_LIT:4> } , <EOL> { "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> } <EOL> ] <EOL> simplified = self . simplify ( p , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> self . assertEqual ( simplified , expected ) <EOL> def test_empty_value_of_list_structure ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> expected = [ ] <EOL> simplified = self . simplify ( p , [ ] ) <EOL> self . assertEqual ( simplified , expected ) <EOL> def test_list_structure_list_multiple_scalar ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> returned = self . simplify ( <EOL> p , <EOL> [ '<STR_LIT>' <EOL> '<STR_LIT>' ] ) <EOL> self . assertEqual ( returned , [ { '<STR_LIT>' : [ <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] , <EOL> '<STR_LIT>' : '<STR_LIT:foo>' , <EOL> '<STR_LIT>' : <NUM_LIT:3> } ] ) <EOL> def test_list_structure_scalars_2 ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> expected = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> ] <EOL> returned = unpack_cli_arg ( <EOL> p , [ '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> self . assertEqual ( returned , expected ) <EOL> simplified = self . simplify ( p , [ <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ] ) <EOL> self . assertEqual ( simplified , expected ) <EOL> def test_keyval_with_long_values ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> value = '<STR_LIT>' <EOL> returned = self . simplify ( p , value ) <EOL> self . assertEqual ( returned , { '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : <NUM_LIT:10> } ) <EOL> def test_error_messages_for_structure_scalar ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> value = '<STR_LIT>' <EOL> error_msg = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , value ) <EOL> def test_improper_separator ( self ) : <EOL> p = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> value = '<STR_LIT>' <EOL> error_msg = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , value ) <EOL> def test_improper_separator_for_filters_param ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> error_msg = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , [ "<STR_LIT>" ] ) <EOL> def test_csv_syntax_escaped ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> returned = self . simplify ( <EOL> p , [ "<STR_LIT>" ] ) <EOL> expected = [ { "<STR_LIT>" : "<STR_LIT:key>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] <EOL> self . assertEqual ( returned , expected ) <EOL> def test_csv_syntax_double_quoted ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> returned = self . simplify ( <EOL> p , [ '<STR_LIT>' ] ) <EOL> expected = [ { "<STR_LIT>" : "<STR_LIT:key>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] <EOL> self . assertEqual ( returned , expected ) <EOL> def test_csv_syntax_single_quoted ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> returned = self . simplify ( <EOL> p , [ "<STR_LIT>" ] ) <EOL> expected = [ { "<STR_LIT>" : "<STR_LIT:key>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } ] <EOL> self . assertEqual ( returned , expected ) <EOL> def test_csv_syntax_errors ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> error_msg = "<STR_LIT>" <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , [ '<STR_LIT>' ] ) <EOL> with self . assertRaisesRegexp ( ParamError , error_msg ) : <EOL> self . simplify ( p , [ '<STR_LIT>' ] ) <EOL> class TestParamShorthandCustomArguments ( BaseArgProcessTest ) : <EOL> def setUp ( self ) : <EOL> super ( TestParamShorthandCustomArguments , self ) . setUp ( ) <EOL> self . simplify = ParamShorthand ( ) <EOL> def test_list_structure_list_scalar_custom_arg ( self ) : <EOL> schema = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:object>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:Name>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> argument_model = create_argument_model_from_schema ( schema ) <EOL> cli_argument = CustomArgument ( '<STR_LIT:foo>' , argument_model = argument_model ) <EOL> expected = [ <EOL> { "<STR_LIT:Name>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : [ "<STR_LIT:a>" , "<STR_LIT>" , "<STR_LIT:b>" ] } , <EOL> { "<STR_LIT:Name>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] } , <EOL> { "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] } , <EOL> { "<STR_LIT:Name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ "<STR_LIT:value>" ] } <EOL> ] <EOL> simplified = self . simplify ( cli_argument , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] ) <EOL> self . assertEqual ( simplified , expected ) <EOL> def test_struct_list_scalars ( self ) : <EOL> schema = { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> } <EOL> } <EOL> argument_model = create_argument_model_from_schema ( schema ) <EOL> cli_argument = CustomArgument ( '<STR_LIT:test>' , argument_model = argument_model ) <EOL> returned = self . simplify ( cli_argument , '<STR_LIT>' ) <EOL> self . assertEqual ( returned , { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } ) <EOL> class TestDocGen ( BaseArgProcessTest ) : <EOL> def setUp ( self ) : <EOL> super ( TestDocGen , self ) . setUp ( ) <EOL> self . shorthand_documenter = ParamShorthandDocGen ( ) <EOL> def get_generated_example_for ( self , argument ) : <EOL> return self . shorthand_documenter . generate_shorthand_example ( <EOL> argument . cli_name , argument . argument_model ) <EOL> def assert_generated_example_is ( self , argument , expected_docs ) : <EOL> generated_docs = self . get_generated_example_for ( argument ) <EOL> self . assertEqual ( generated_docs , expected_docs ) <EOL> def assert_generated_example_contains ( self , argument , expected_to_contain ) : <EOL> generated_docs = self . get_generated_example_for ( argument ) <EOL> self . assertIn ( expected_to_contain , generated_docs ) <EOL> def test_gen_map_type_docs ( self ) : <EOL> argument = self . get_param_model ( '<STR_LIT>' ) <EOL> expected_example_str = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assert_generated_example_contains ( argument , expected_example_str ) <EOL> def test_gen_list_scalar_docs ( self ) : <EOL> argument = self . get_param_model ( <EOL> '<STR_LIT>' ) <EOL> doc_string = '<STR_LIT>' <EOL> self . assert_generated_example_is ( argument , doc_string ) <EOL> def test_gen_list_structure_of_scalars_docs ( self ) : <EOL> argument = self . get_param_model ( '<STR_LIT>' ) <EOL> generated_example = self . get_generated_example_for ( argument ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> def test_gen_list_structure_multiple_scalar_docs ( self ) : <EOL> expected = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> arg = model . DenormalizedStructureBuilder ( ) . with_members ( OrderedDict ( [ <EOL> ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : OrderedDict ( [ <EOL> ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT:string>' } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT:string>' } ) , <EOL> ( '<STR_LIT>' , { <EOL> '<STR_LIT:type>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> } ) , <EOL> ] ) , <EOL> } } ) , <EOL> ] ) ) . build_model ( ) . members [ '<STR_LIT>' ] <EOL> rendered = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , arg ) <EOL> self . assertIn ( expected , rendered ) <EOL> def test_gen_list_structure_list_scalar_scalar_docs ( self ) : <EOL> argument = self . get_param_model ( '<STR_LIT>' ) <EOL> generated_example = self . get_generated_example_for ( argument ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> generated_example ) <EOL> def test_gen_structure_list_scalar_docs ( self ) : <EOL> schema = { <EOL> "<STR_LIT:type>" : "<STR_LIT:object>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:type>" : "<STR_LIT:string>" <EOL> } <EOL> } <EOL> } <EOL> } <EOL> argument_model = create_argument_model_from_schema ( schema ) <EOL> m = model . DenormalizedStructureBuilder ( ) . with_members ( OrderedDict ( [ <EOL> ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT:type>' : '<STR_LIT:list>' , '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' , } } ) , <EOL> ] ) ) . build_model ( ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIn ( '<STR_LIT>' , <EOL> generated_example ) <EOL> def test_can_gen_recursive_structure ( self ) : <EOL> argument = self . get_param_model ( '<STR_LIT>' ) <EOL> generated_example = self . get_generated_example_for ( argument ) <EOL> def test_can_document_nested_structs ( self ) : <EOL> argument = self . get_param_model ( '<STR_LIT>' ) <EOL> generated_example = self . get_generated_example_for ( argument ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> def test_can_document_nested_lists ( self ) : <EOL> m = model . DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT:A>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> } , <EOL> } , <EOL> } ) . build_model ( ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> def test_can_generated_nested_maps ( self ) : <EOL> m = model . DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT:A>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT:key>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> '<STR_LIT:value>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } <EOL> } , <EOL> } ) . build_model ( ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> def test_list_of_structures_with_triple_dots ( self ) : <EOL> list_shape = { <EOL> '<STR_LIT:type>' : '<STR_LIT:list>' , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> shapes = { <EOL> '<STR_LIT>' : list_shape , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : OrderedDict ( [ <EOL> ( '<STR_LIT:A>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT:B>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] ) <EOL> } <EOL> } <EOL> m = model . ListShape ( <EOL> shape_name = '<STR_LIT>' , <EOL> shape_model = list_shape , <EOL> shape_resolver = model . ShapeResolver ( shapes ) ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIn ( '<STR_LIT>' , generated_example ) <EOL> def test_handle_special_case_value_struct_not_documented ( self ) : <EOL> m = model . DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } <EOL> } ) . build_model ( ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIsNone ( generated_example ) <EOL> def test_can_document_recursive_struct ( self ) : <EOL> struct_shape = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : OrderedDict ( [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] ) , <EOL> } <EOL> shapes = { <EOL> '<STR_LIT>' : struct_shape , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : OrderedDict ( [ <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] ) , <EOL> } <EOL> } <EOL> m = model . StructureShape ( <EOL> shape_name = '<STR_LIT>' , <EOL> shape_model = struct_shape , <EOL> shape_resolver = model . ShapeResolver ( shapes ) ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertIn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> generated_example ) <EOL> def test_skip_deeply_nested_shorthand ( self ) : <EOL> m = model . DenormalizedStructureBuilder ( ) . with_members ( { <EOL> '<STR_LIT:A>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:B>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:C>' : { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:D>' : { '<STR_LIT:type>' : '<STR_LIT:string>' } , <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } <EOL> } , <EOL> } ) . build_model ( ) <EOL> generated_example = self . shorthand_documenter . generate_shorthand_example ( <EOL> '<STR_LIT>' , m ) <EOL> self . assertEqual ( generated_example , '<STR_LIT>' ) <EOL> class TestUnpackJSONParams ( BaseArgProcessTest ) : <EOL> def setUp ( self ) : <EOL> super ( TestUnpackJSONParams , self ) . setUp ( ) <EOL> self . simplify = ParamShorthand ( ) <EOL> def test_json_with_spaces ( self ) : <EOL> p = self . get_param_model ( '<STR_LIT>' ) <EOL> block_device_mapping = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> with self . assertRaises ( ParamError ) as e : <EOL> unpack_cli_arg ( p , block_device_mapping ) <EOL> self . assertIn ( '<STR_LIT>' , str ( e . exception ) ) <EOL> self . assertIn ( '<STR_LIT>' , str ( e . exception ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
