Пример #1
0
def _qualifies_for_simplification(arg_model):
    if detect_shape_structure(arg_model) == 'structure(scalar)':
        members = arg_model.members
        if (len(members) == 1 and list(members.keys())[0] == 'Value'
                and list(members.values())[0].type_name == 'boolean'):
            return True
    return False
Пример #2
0
 def test_recursive_shape(self):
     shapes = {
         'InputStructure': {
             'type': 'structure',
             'members': {
                 'A': {
                     'shape': 'RecursiveShape'
                 }
             }
         },
         'RecursiveShape': {
             'type': 'structure',
             'members': {
                 'B': {
                     'shape': 'StringType'
                 },
                 'C': {
                     'shape': 'RecursiveShape'
                 },
             }
         },
         'StringType': {
             'type': 'string'
         }
     }
     shape = model.StructureShape(
         shape_name='InputStructure',
         shape_model=shapes['InputStructure'],
         shape_resolver=model.ShapeResolver(shape_map=shapes))
     self.assertIn('recursive', detect_shape_structure(shape))
Пример #3
0
def _qualifies_for_simplification(arg_model):
    if detect_shape_structure(arg_model) == 'structure(scalar)':
        members = arg_model.members
        if (len(members) == 1 and
            list(members.keys())[0] == 'Value' and
            list(members.values())[0].type_name == 'boolean'):
            return True
    return False
Пример #4
0
def pull_up_bool(argument_table, event_handler, **kwargs):
    # List of tuples of (positive_bool, negative_bool)
    # This is used to validate that we don't specify
    # an --option and a --no-option.
    boolean_pairs = []
    event_handler.register(
        'operation-args-parsed.ec2.*',
        partial(validate_boolean_mutex_groups, boolean_pairs=boolean_pairs))
    for key, value in list(argument_table.items()):
        if hasattr(value, 'argument_object'):
            arg_object = value.argument_object
            if detect_shape_structure(arg_object) == 'structure(scalar)' and \
                    len(arg_object.members) == 1 and \
                    arg_object.members[0].name == 'Value' and \
                    arg_object.members[0].type == 'boolean':
                # Swap out the existing CLIArgument for two args:
                # one that supports --option and --option <some value>
                # and another arg of --no-option.
                new_arg = PositiveBooleanArgument(value.name, arg_object,
                                                  value.operation_object,
                                                  value.name)
                argument_table[value.name] = new_arg
                negative_name = 'no-%s' % value.name
                negative_arg = NegativeBooleanParameter(negative_name,
                                                        new_arg.py_name,
                                                        arg_object,
                                                        value.operation_object,
                                                        action='store_true',
                                                        dest='no_%s' %
                                                        new_arg.py_name,
                                                        group_name=value.name)
                argument_table[negative_name] = negative_arg
                # If we've pulled up a structure(scalar) arg
                # into a pair of top level boolean args, we need
                # to validate that a user only provides the argument
                # once.  They can't say --option/--no-option, nor
                # can they say --option --option Value=false.
                boolean_pairs.append((new_arg, negative_arg))
Пример #5
0
 def test_recursive_shape(self):
     shapes = {
         'InputStructure': {
             'type': 'structure',
             'members': {
                 'A': {'shape': 'RecursiveShape'}
             }
         },
         'RecursiveShape': {
             'type': 'structure',
             'members': {
                 'B': {'shape': 'StringType'},
                 'C': {'shape': 'RecursiveShape'},
             }
         },
         'StringType': {
             'type': 'string'
         }
     }
     shape = model.StructureShape(shape_name='InputStructure',
                                  shape_model=shapes['InputStructure'],
                                  shape_resolver=model.ShapeResolver(
                                      shape_map=shapes))
     self.assertIn('recursive', detect_shape_structure(shape))
Пример #6
0
def pull_up_bool(argument_table, event_handler, **kwargs):
    # List of tuples of (positive_bool, negative_bool)
    # This is used to validate that we don't specify
    # an --option and a --no-option.
    boolean_pairs = []
    event_handler.register(
        'operation-args-parsed.ec2.*',
        partial(validate_boolean_mutex_groups,
                boolean_pairs=boolean_pairs))
    for key, value in list(argument_table.items()):
        if hasattr(value, 'argument_object'):
            arg_object = value.argument_object
            if detect_shape_structure(arg_object) == 'structure(scalar)' and \
                    len(arg_object.members) == 1 and \
                    arg_object.members[0].name == 'Value' and \
                    arg_object.members[0].type == 'boolean':
                # Swap out the existing CLIArgument for two args:
                # one that supports --option and --option <some value>
                # and another arg of --no-option.
                new_arg = PositiveBooleanArgument(
                    value.name, arg_object, value.operation_object,
                    value.name)
                argument_table[value.name] = new_arg
                negative_name = 'no-%s' % value.name
                negative_arg = NegativeBooleanParameter(
                    negative_name, new_arg.py_name,
                    arg_object, value.operation_object,
                    action='store_true', dest='no_%s' % new_arg.py_name,
                    group_name=value.name)
                argument_table[negative_name] = negative_arg
                # If we've pulled up a structure(scalar) arg
                # into a pair of top level boolean args, we need
                # to validate that a user only provides the argument
                # once.  They can't say --option/--no-option, nor
                # can they say --option --option Value=false.
                boolean_pairs.append((new_arg, negative_arg))
Пример #7
0
 def assert_shape_type(self, spec, expected_type):
     p = self.get_param_object(spec)
     actual_structure = detect_shape_structure(p)
     self.assertEqual(actual_structure, expected_type)
Пример #8
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument = CustomArgument('test', schema=schema)
     argument.create_argument_object()
     actual_structure = detect_shape_structure(argument.argument_object)
     self.assertEqual(actual_structure, expected_type)
Пример #9
0
 def assert_shape_type(self, spec, expected_type):
     p = self.get_param_object(spec)
     actual_structure = detect_shape_structure(p)
     self.assertEqual(actual_structure, expected_type)
Пример #10
0
 def assert_shape_type(self, spec, expected_type):
     p = self.get_param_model(spec)
     actual_structure = detect_shape_structure(p.argument_model)
     self.assertEqual(actual_structure, expected_type)
Пример #11
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument_model = create_argument_model_from_schema(schema)
     argument = CustomArgument('test', argument_model=argument_model)
     actual_structure = detect_shape_structure(argument.argument_model)
     self.assertEqual(actual_structure, expected_type)
Пример #12
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument = CustomArgument('test', schema=schema)
     argument.create_argument_object()
     actual_structure = detect_shape_structure(argument.argument_object)
     self.assertEqual(actual_structure, expected_type)
Пример #13
0
 def assert_custom_shape_type(self, schema, expected_type):
     argument_model = create_argument_model_from_schema(schema)
     argument = CustomArgument('test', argument_model=argument_model)
     actual_structure = detect_shape_structure(argument.argument_model)
     self.assertEqual(actual_structure, expected_type)
Пример #14
0
 def assert_shape_type(self, spec, expected_type):
     p = self.get_param_model(spec)
     actual_structure = detect_shape_structure(p.argument_model)
     self.assertEqual(actual_structure, expected_type)