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