def test_pretty_string(self): """Test return pretty string from list or string.""" myStr = 'Aloha' mylist = ['a', 'b', 'c'] expectedStr = 'Aloha' expectedStr2 = 'a, b, c' realStr = pretty_string(myStr) realStr2 = pretty_string(mylist) assert expectedStr == realStr, 'String not Ok' myMessage = 'Get %s should be % s' % (realStr2, expectedStr2) assert expectedStr2 == realStr2, myMessage
def get_plugins_as_table(dict_filter=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: * dict_filter = dictionary that contains filters - id = list_id - title = list_title - category : list_category - subcategory : list_subcategory - layertype : list_layertype - datatype : list_datatype - unit: list_unit - disabled : list_disabled # not included Returns: * table contains plugins match with dict_filter Raises: None """ if dict_filter is None: dict_filter = { 'id': [], 'title': [], 'category': [], 'subcategory': [], 'layertype': [], 'datatype': [], 'unit': [] } table_body = [] # use this list for avoiding wrong order in dict atts = ['category', 'subcategory', 'layertype', 'datatype', 'unit'] header = TableRow([ tr('Title'), tr('ID'), tr('Category'), tr('Sub Category'), tr('Layer type'), tr('Data type'), tr('Unit') ], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) not_found_value = 'N/A' for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): dict_found = { 'title': False, 'id': False, 'category': False, 'subcategory': False, 'layertype': False, 'datatype': False, 'unit': False } dict_req = parse_single_requirement(str(requirement)) # If the impact function is disabled, do not show it if dict_req.get('disabled', False): continue for myKey in dict_found.iterkeys(): myFilter = dict_filter.get(myKey, []) if myKey == 'title': myValue = str(get_function_title(func)) elif myKey == 'id': myValue = str(key) else: myValue = dict_req.get(myKey, not_found_value) if myFilter != []: for myKeyword in myFilter: if type(myValue) == type(str()): if myValue == myKeyword: dict_found[myKey] = True break elif type(myValue) == type(list()): if myKeyword in myValue: dict_found[myKey] = True break else: if myValue.find(str(myKeyword)) != -1: dict_found[myKey] = True break else: dict_found[myKey] = True add_row = True for found_value in dict_found.itervalues(): if not found_value: add_row = False break if add_row: row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) for myKey in atts: myValue = pretty_string( dict_req.get(myKey, not_found_value)) row.append(myValue) table_body.append(TableRow(row)) cw = 100 / 7 table_col_width = [ str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%' ] table = Table(table_body, col_width=table_col_width) table.caption = tr('Available Impact Functions') return table
def get_plugins_as_table(dict_filter=None): """Retrieve a table listing all plugins and their requirements. Or just a single plugin if name is passed. Args: * dict_filter = dictionary that contains filters - id = list_id - title = list_title - category : list_category - subcategory : list_subcategory - layertype : list_layertype - datatype : list_datatype - unit: list_unit - disabled : list_disabled # not included Returns: * table contains plugins match with dict_filter Raises: None """ if dict_filter is None: dict_filter = {'id': [], 'title': [], 'category': [], 'subcategory': [], 'layertype': [], 'datatype': [], 'unit': []} table_body = [] # use this list for avoiding wrong order in dict atts = ['category', 'subcategory', 'layertype', 'datatype', 'unit'] header = TableRow([tr('Title'), tr('ID'), tr('Category'), tr('Sub Category'), tr('Layer type'), tr('Data type'), tr('Unit')], header=True) table_body.append(header) plugins_dict = dict([(pretty_function_name(p), p) for p in FunctionProvider.plugins]) not_found_value = 'N/A' for key, func in plugins_dict.iteritems(): for requirement in requirements_collect(func): dict_found = {'title': False, 'id': False, 'category': False, 'subcategory': False, 'layertype': False, 'datatype': False, 'unit': False} dict_req = parse_single_requirement(str(requirement)) # If the impact function is disabled, do not show it if dict_req.get('disabled', False): continue for myKey in dict_found.iterkeys(): myFilter = dict_filter.get(myKey, []) if myKey == 'title': myValue = str(get_function_title(func)) elif myKey == 'id': myValue = str(key) else: myValue = dict_req.get(myKey, not_found_value) if myFilter != []: for myKeyword in myFilter: if type(myValue) == type(str()): if myValue == myKeyword: dict_found[myKey] = True break elif type(myValue) == type(list()): if myKeyword in myValue: dict_found[myKey] = True break else: if myValue.find(str(myKeyword)) != -1: dict_found[myKey] = True break else: dict_found[myKey] = True add_row = True for found_value in dict_found.itervalues(): if not found_value: add_row = False break if add_row: row = [] row.append(TableCell(get_function_title(func), header=True)) row.append(key) for myKey in atts: myValue = pretty_string(dict_req.get(myKey, not_found_value)) row.append(myValue) table_body.append(TableRow(row)) cw = 100 / 7 table_col_width = [str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%', str(cw) + '%'] table = Table(table_body, col_width=table_col_width) table.caption = tr('Available Impact Functions') return table