Python Library Unittest
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

output.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #
  5. # STATUS_KEYS
  6. #
  7. STATUS_AVAILABLE = 'AVAILABLE'
  8. STATUS_CLEAN = 'CLEAN'
  9. STATUS_RELEASED = 'RELEASED'
  10. STATUS_SUCCESS = 'SUCCESS'
  11. #
  12. STATUS_CHANGED = 'CHANGED'
  13. STATUS_EXISTS = 'EXISTS'
  14. STATUS_IN_WORK = 'IN_WORK'
  15. STATUS_OLD = 'OLD'
  16. #
  17. STATUS_FAILED = 'FAILED'
  18. STATUS_MISSING = 'MISSING'
  19. STATUS_UNKNOWN = 'UNKNOWN'
  20. class termcolors:
  21. HEADER = '\033[95m'
  22. OKBLUE = '\033[94m'
  23. OKGREEN = '\033[92m'
  24. WARNING = '\033[93m'
  25. FAIL = '\033[91m'
  26. ENDC = '\033[0m'
  27. BOLD = '\033[1m'
  28. UNDERLINE = '\033[4m'
  29. STATUS_COLORS = {
  30. STATUS_AVAILABLE: termcolors.OKGREEN,
  31. STATUS_CLEAN: termcolors.OKGREEN,
  32. STATUS_RELEASED: termcolors.OKGREEN,
  33. STATUS_SUCCESS: termcolors.OKGREEN,
  34. #
  35. STATUS_CHANGED: termcolors.WARNING,
  36. STATUS_EXISTS: termcolors.WARNING,
  37. STATUS_IN_WORK: termcolors.WARNING,
  38. STATUS_OLD: termcolors.WARNING,
  39. #
  40. STATUS_FAILED: termcolors.FAIL,
  41. STATUS_MISSING: termcolors.FAIL,
  42. STATUS_UNKNOWN: termcolors.FAIL,
  43. }
  44. def print_header(txt):
  45. print(termcolors.BOLD + termcolors.WARNING + txt + termcolors.ENDC)
  46. def print_action(txt):
  47. print(termcolors.BOLD + ' * ' + txt + termcolors.ENDC)
  48. def status_output(txt, default_color):
  49. return STATUS_COLORS.get(txt, default_color) + txt + termcolors.ENDC
  50. def print_info(txt, default_color=termcolors.ENDC):
  51. print(' ' + status_output(txt, default_color))
  52. def coverage_output(lcov, bcov, length=None):
  53. if lcov is None or bcov is None:
  54. length = length or len(STATUS_UNKNOWN)
  55. return (length - len(STATUS_UNKNOWN)) * ' ' + status_output(STATUS_UNKNOWN, termcolors.FAIL)
  56. elif lcov > 90:
  57. rv = termcolors.OKGREEN + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC
  58. else:
  59. rv = termcolors.WARNING + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC
  60. if length is None:
  61. return rv
  62. else:
  63. return (length - 11) * ' ' + rv
  64. def print_coverage(lcov, bcov):
  65. print(' ' + coverage_output(lcov, bcov))