Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mkasenberg committed Jul 3, 2024
1 parent 7f30204 commit 4fc23b2
Show file tree
Hide file tree
Showing 9 changed files with 470 additions and 512 deletions.
368 changes: 353 additions & 15 deletions autopts/bot/common.py

Large diffs are not rendered by default.

108 changes: 29 additions & 79 deletions autopts/bot/common_features/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
from autopts.bot.common_features import github
from autopts.bot import common
from autopts.client import PtsServer
from autopts.config import PTS_XMLS_FOLDER, TMP_DIR, REPORT_XLSX, REPORT_TXT, REPORT_DIFF_TXT, ERROR_TXT, \
ERRATA_DIR_PATH, AUTOPTS_ROOT_DIR

REPORT_XLSX = "report.xlsx"
REPORT_TXT = "report.txt"
REPORT_DIFF_TXT = "report-diff.txt"
ERROR_TXT = 'error.txt'

ERRATA_DIR_PATH = os.path.join(common.PROJECT_DIR, 'errata')
log = logging.debug


Expand All @@ -54,7 +50,7 @@ def get_errata(project_name):


def get_autopts_version():
repo = git.Repo(common.PROJECT_DIR)
repo = git.Repo(AUTOPTS_ROOT_DIR)
version = repo.git.show('-s', '--format=%H')

if repo.is_dirty():
Expand All @@ -75,8 +71,7 @@ def make_repo_status(repos_info):
# ****************************************************************************
# .xlsx spreadsheet file
# ****************************************************************************
def make_report_xlsx(results_dict, status_dict, regressions_list,
progresses_list, descriptions, xmls, project_name=''):
def make_report_xlsx(report_data):
"""Creates excel file containing test cases results and summary pie chart
:param results_dict: dictionary with test cases results
:param status_dict: status dictionary, where key is status and value is
Expand All @@ -87,10 +82,18 @@ def make_report_xlsx(results_dict, status_dict, regressions_list,
:return:
"""

results_dict = report_data['tc_results']
status_dict = report_data['status_count']
regressions_list = report_data['regressions']
progresses_list = report_data['progresses']
descriptions = report_data['descriptions']
xmls = report_data['pts_xml_folder']
errata = report_data.get('errata', [])

try:
xml_list = list(os.scandir(xmls))
except FileNotFoundError as e:
print("No XMLs found")
log("No XMLs found")
xml_list = None
matched_xml = ''

Expand All @@ -105,8 +108,6 @@ def find_xml_by_case(case):
matched_xml = xml.name
break

errata = get_errata(project_name)

header = "AutoPTS Report: " \
"{}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M"))
workbook = xlsxwriter.Workbook(REPORT_XLSX)
Expand Down Expand Up @@ -185,8 +186,7 @@ def find_xml_by_case(case):
# ****************************************************************************
# .txt result file
# ****************************************************************************
def make_report_txt(results_dict, regressions_list,
progresses_list, repo_status, project_name=''):
def make_report_txt(report_data):
"""Creates txt file containing test cases results
:param results_dict: dictionary with test cases results
:param regressions_list: list of regressions found
Expand All @@ -196,11 +196,15 @@ def make_report_txt(results_dict, regressions_list,
:return: txt file path
"""

results_dict = report_data['tc_results']
regressions_list = report_data['regressions']
progresses_list = report_data['progresses']
repo_status = report_data['repo_status']
errata = report_data.get('errata', [])

filename = os.path.join(os.getcwd(), REPORT_TXT)
f = open(filename, "w")

errata = get_errata(project_name)

f.write(f"{repo_status}, autopts={get_autopts_version()}\n")
for tc, result in list(results_dict.items()):
res = result[0]
Expand All @@ -217,7 +221,7 @@ def make_report_txt(results_dict, regressions_list,
if tc in errata:
result += ' - ERRATA ' + errata[tc]

# The first id in the test case is test group
# The first id in the test case is a test group
tg = tc.split('/')[0]
f.write("%s%s%s\n" % (tg.ljust(8, ' '), tc.ljust(32, ' '), result))

Expand All @@ -226,60 +230,6 @@ def make_report_txt(results_dict, regressions_list,
return filename


# ****************************************************************************
# autopts_report result folder
# ****************************************************************************
def make_report_folder(iut_logs, pts_logs, xmls, report_xlsx, report_txt,
report_diff_txt, readme_file, database_file, tag=''):
"""Creates folder containing .txt and .xlsx reports, pulled logs
from autoptsserver, iut logs and additional README.md.
"""

def get_deepest_dirs(logs_tree, dst_tree, max_depth):
def recursive(directory, depth=3):
depth -= 1

for file in os.scandir(directory):
if file.is_dir():
if depth > 0:
recursive(file.path, depth)
else:
dst_file = os.path.join(dst_tree, file.name)
try:
shutil.move(file.path, dst_file)
except: # skip waiting for BPV to release the file
try:
shutil.copy(file.path, dst_file)
except:
pass

recursive(logs_tree, max_depth)

report_dir = 'tmp/autopts_report'
shutil.rmtree(report_dir, ignore_errors=True)
Path(report_dir).mkdir(parents=True, exist_ok=True)

shutil.copy(report_diff_txt, os.path.join(report_dir, 'report-diff.txt'))
shutil.copy(report_txt, os.path.join(report_dir, 'report.txt'))
shutil.copy(report_txt, os.path.join(report_dir, 'report{}.txt'.format(tag)))
shutil.copy(report_xlsx, os.path.join(report_dir, 'report{}.xlsx'.format(tag)))
shutil.copy(readme_file, os.path.join(report_dir, 'README.md'))
shutil.copy(database_file, os.path.join(report_dir, os.path.basename(database_file)))

iut_logs_new = os.path.join(report_dir, 'iut_logs')
pts_logs_new = os.path.join(report_dir, 'pts_logs')
xmls_new = os.path.join(report_dir, 'XMLs/')

get_deepest_dirs(iut_logs, iut_logs_new, 3)
get_deepest_dirs(pts_logs, pts_logs_new, 3)
try:
shutil.move(xmls, xmls_new)
except FileNotFoundError:
print('XMLs directory doesn\'t exist')

return os.path.join(os.getcwd(), report_dir)


def report_parse_test_cases(report):
if not os.path.exists(report):
return None
Expand All @@ -300,12 +250,12 @@ def report_parse_test_cases(report):
return test_cases[1:]


def make_report_diff(log_git_conf, results, regressions,
progresses, new_cases):
old_report_txt = os.path.join(log_git_conf['path'],
log_git_conf['subdir'],
'autopts_report',
REPORT_TXT)
def make_report_diff(report_data):
old_report_txt = report_data['old_report_txt']
results = report_data['tc_results']
regressions = report_data['regressions']
progresses = report_data['progresses']
new_cases = report_data['new_cases']

filename = os.path.join(os.getcwd(), REPORT_DIFF_TXT)
f = open(filename, "w")
Expand Down Expand Up @@ -432,8 +382,8 @@ def pull_server_logs(args):
else:
workspace_dir = workspace_name

logs_folder = 'tmp/' + workspace_name
xml_folder = 'tmp/XMLs'
logs_folder = os.path.join(TMP_DIR, workspace_name)
xml_folder = PTS_XMLS_FOLDER
shutil.rmtree(logs_folder, ignore_errors=True)
shutil.rmtree(xml_folder, ignore_errors=True)
Path(xml_folder).mkdir(parents=True, exist_ok=True)
Expand Down
Loading

0 comments on commit 4fc23b2

Please sign in to comment.