0001 """
0002 # SPDX-License-Identifier: GPL-2.0
0003 tdc_helper.py - tdc helper functions
0004
0005 Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com>
0006 """
0007
0008 def get_categorized_testlist(alltests, ucat):
0009 """ Sort the master test list into categories. """
0010 testcases = dict()
0011
0012 for category in ucat:
0013 testcases[category] = list(filter(lambda x: category in x['category'], alltests))
0014
0015 return(testcases)
0016
0017
0018 def get_unique_item(lst):
0019 """ For a list, return a list of the unique items in the list. """
0020 if len(lst) > 1:
0021 return list(set(lst))
0022 else:
0023 return lst
0024
0025
0026 def get_test_categories(alltests):
0027 """ Discover all unique test categories present in the test case file. """
0028 ucat = []
0029 for t in alltests:
0030 ucat.extend(get_unique_item(t['category']))
0031 ucat = get_unique_item(ucat)
0032 return ucat
0033
0034 def list_test_cases(testlist):
0035 """ Print IDs and names of all test cases. """
0036 for curcase in testlist:
0037 print(curcase['id'] + ': (' + ', '.join(curcase['category']) + ") " + curcase['name'])
0038
0039
0040 def list_categories(testlist):
0041 """ Show all categories that are present in a test case file. """
0042 categories = set(map(lambda x: x['category'], testlist))
0043 print("Available categories:")
0044 print(", ".join(str(s) for s in categories))
0045 print("")
0046
0047
0048 def print_list(cmdlist):
0049 """ Print a list of strings prepended with a tab. """
0050 for l in cmdlist:
0051 if (type(l) == list):
0052 print("\t" + str(l[0]))
0053 else:
0054 print("\t" + str(l))
0055
0056
0057 def print_sll(items):
0058 print("\n".join(str(s) for s in items))
0059
0060
0061 def print_test_case(tcase):
0062 """ Pretty-printing of a given test case. """
0063 print('\n==============\nTest {}\t{}\n'.format(tcase['id'], tcase['name']))
0064 for k in tcase.keys():
0065 if (isinstance(tcase[k], list)):
0066 print(k + ":")
0067 print_list(tcase[k])
0068 else:
0069 if not ((k == 'id') or (k == 'name')):
0070 print(k + ": " + str(tcase[k]))