def _parse_array_item(name, value): """ :param name: the name of the property :type name: str :param value: the value to parse :type value: str :returns: the parsed value as an array with one element :rtype: (list of any, dcos.errors.Error) where any is string, int, float, bool, array or dict """ section, subkey = _split_key(name) config_schema = _get_config_schema(section) parser = jsonitem.find_parser(subkey, config_schema) if parser.schema['type'] != 'array': raise DCOSException( "Append/Prepend not supported on '{0}' properties - use 'dcos " "config set {0} {1}'".format(name, value)) if ('items' in parser.schema and parser.schema['items']['type'] == 'string'): value = '["' + value + '"]' else: # We are going to assume that wrapping it in an array is enough value = '[' + value + ']' return parser(value)
def test_find_parser(schema, jsonitem_tuple): key, string_value, value = jsonitem_tuple assert jsonitem.find_parser(key, schema)(string_value) == value