Python Library Unittest
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

output.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. STATUS_INCOMPLETE = 'INCOMPLETE'
  17. #
  18. STATUS_FAILED = 'FAILED'
  19. STATUS_MISSING = 'MISSING'
  20. STATUS_UNKNOWN = 'UNKNOWN'
  21. class termcolors:
  22. HEADER = '\033[95m'
  23. OKBLUE = '\033[94m'
  24. OKGREEN = '\033[92m'
  25. WARNING = '\033[93m'
  26. FAIL = '\033[91m'
  27. ENDC = '\033[0m'
  28. BOLD = '\033[1m'
  29. UNDERLINE = '\033[4m'
  30. STATUS_COLORS = {
  31. STATUS_AVAILABLE: termcolors.OKGREEN,
  32. STATUS_CLEAN: termcolors.OKGREEN,
  33. STATUS_RELEASED: termcolors.OKGREEN,
  34. STATUS_SUCCESS: termcolors.OKGREEN,
  35. #
  36. STATUS_CHANGED: termcolors.WARNING,
  37. STATUS_EXISTS: termcolors.WARNING,
  38. STATUS_IN_WORK: termcolors.WARNING,
  39. STATUS_OLD: termcolors.WARNING,
  40. STATUS_INCOMPLETE: termcolors.WARNING,
  41. #
  42. STATUS_FAILED: termcolors.FAIL,
  43. STATUS_MISSING: termcolors.FAIL,
  44. STATUS_UNKNOWN: termcolors.FAIL,
  45. }
  46. def print_header(txt):
  47. print(termcolors.BOLD + termcolors.WARNING + txt + termcolors.ENDC)
  48. def print_action(txt):
  49. print(termcolors.BOLD + ' * ' + txt + termcolors.ENDC)
  50. def status_output(txt, default_color):
  51. return STATUS_COLORS.get(txt, default_color) + txt + termcolors.ENDC
  52. def print_info(txt, default_color=termcolors.ENDC):
  53. print(' ' + status_output(txt, default_color))
  54. def coverage_output(lcov, bcov, length=None):
  55. if lcov is None or bcov is None:
  56. length = length or len(STATUS_UNKNOWN)
  57. return (length - len(STATUS_UNKNOWN)) * ' ' + status_output(STATUS_UNKNOWN, termcolors.FAIL)
  58. elif lcov > 90:
  59. rv = termcolors.OKGREEN + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC
  60. else:
  61. rv = termcolors.WARNING + '%3d%% (%3d%%)' % (lcov, bcov) + termcolors.ENDC
  62. if length is None:
  63. return rv
  64. else:
  65. return (length - 11) * ' ' + rv
  66. def print_coverage(lcov, bcov):
  67. print(' ' + coverage_output(lcov, bcov))