tdc_helper.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. # SPDX-License-Identifier: GPL-2.0
  3. tdc_helper.py - tdc helper functions
  4. Copyright (C) 2017 Lucas Bates <lucasb@mojatatu.com>
  5. """
  6. def get_categorized_testlist(alltests, ucat):
  7. """ Sort the master test list into categories. """
  8. testcases = dict()
  9. for category in ucat:
  10. testcases[category] = list(filter(lambda x: category in x['category'], alltests))
  11. return(testcases)
  12. def get_unique_item(lst):
  13. """ For a list, return a list of the unique items in the list. """
  14. if len(lst) > 1:
  15. return list(set(lst))
  16. else:
  17. return lst
  18. def get_test_categories(alltests):
  19. """ Discover all unique test categories present in the test case file. """
  20. ucat = []
  21. for t in alltests:
  22. ucat.extend(get_unique_item(t['category']))
  23. ucat = get_unique_item(ucat)
  24. return ucat
  25. def list_test_cases(testlist):
  26. """ Print IDs and names of all test cases. """
  27. for curcase in testlist:
  28. print(curcase['id'] + ': (' + ', '.join(curcase['category']) + ") " + curcase['name'])
  29. def list_categories(testlist):
  30. """ Show all categories that are present in a test case file. """
  31. categories = set(map(lambda x: x['category'], testlist))
  32. print("Available categories:")
  33. print(", ".join(str(s) for s in categories))
  34. print("")
  35. def print_list(cmdlist):
  36. """ Print a list of strings prepended with a tab. """
  37. for l in cmdlist:
  38. if (type(l) == list):
  39. print("\t" + str(l[0]))
  40. else:
  41. print("\t" + str(l))
  42. def print_sll(items):
  43. print("\n".join(str(s) for s in items))
  44. def print_test_case(tcase):
  45. """ Pretty-printing of a given test case. """
  46. print('\n==============\nTest {}\t{}\n'.format(tcase['id'], tcase['name']))
  47. for k in tcase.keys():
  48. if (isinstance(tcase[k], list)):
  49. print(k + ":")
  50. print_list(tcase[k])
  51. else:
  52. if not ((k == 'id') or (k == 'name')):
  53. print(k + ": " + str(tcase[k]))