unittest/module_status.py

48 lines
1.7 KiB
Python
Raw Normal View History

2020-01-26 16:19:29 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
import os
2021-03-04 18:36:23 +01:00
from unittest.output import termcolors, coverage_output
2020-01-26 16:19:29 +01:00
2021-03-04 18:36:23 +01:00
from unittest.output import STATUS_COLORS, STATUS_UNKNOWN
2021-03-04 19:09:49 +01:00
from unittest.jsonlog import lib_coverage, status_doc, status_git, status_lib_unittest, status_spec, versions_module
2020-01-26 16:19:29 +01:00
STATUS_LENGTH = 13
2021-03-04 18:36:23 +01:00
def status_output(status_or_text, default_color=STATUS_COLORS[STATUS_UNKNOWN]):
if status_or_text in STATUS_COLORS:
default_color = STATUS_COLORS[status_or_text]
return default_color + (STATUS_LENGTH - len(status_or_text[:STATUS_LENGTH])) * ' ' + status_or_text[:STATUS_LENGTH] + termcolors.ENDC
2020-01-26 16:19:29 +01:00
def module_status_head():
rv = termcolors.BOLD + termcolors.UNDERLINE + 'Status of the unittests for pylibs:\n' + termcolors.ENDC
LINE_FORMAT = '%25s%' + str(STATUS_LENGTH) + 's%' + str(STATUS_LENGTH) + 's%' + str(STATUS_LENGTH) + 's%' + str(STATUS_LENGTH) + 's%' + str(STATUS_LENGTH) + 's%' + str(STATUS_LENGTH) + 's\n'
rv += termcolors.BOLD + termcolors.HEADER + LINE_FORMAT % (
'Library',
'UT-Status',
'DOC-Status',
'Versions',
'UT-Coverage',
'SPEC-Status',
'GIT-Status',
)
rv += (25 + 6 * STATUS_LENGTH) * '-' + '\n' + termcolors.ENDC
return rv
2021-03-04 18:36:23 +01:00
def module_status_line(ut_folder):
2020-01-26 16:19:29 +01:00
rv = '%25s%s%s%s%s%s%s\n' % (
2021-03-04 18:36:23 +01:00
os.path.basename(ut_folder) + ':',
2021-03-04 19:09:49 +01:00
status_output(status_lib_unittest(ut_folder)),
2021-03-04 18:36:23 +01:00
status_output(status_doc(ut_folder)),
status_output(versions_module(ut_folder), termcolors.BOLD),
coverage_output(*lib_coverage(ut_folder), length=STATUS_LENGTH),
status_output(status_spec(ut_folder)),
status_output(status_git(ut_folder)),
2020-01-26 16:19:29 +01:00
)
return rv