数据解析代码

#!/usr/bin/python
# -*- coding: utf-8 -*- #
# ------------------------------------------------------------------
# File Name: goAtTest.py
# Author: hudeng@uniontech.com
# Created: 2021/11/3222 19:20
# Description: at测试统一运行入口
#
# Function List:
# ------------------------------------------------------------------

import os
import sys
import time
from robot.api import ExecutionResult
import subprocess
import json

json_template = {
"appName": "project_name",
"source" : "CRPCI",
"arch": "amd64",
"buildLocaltion":"wuhan",
"checkName": "ATtest",
"checkResult":"0,0,0%",
"checkStatus": "success",
"buildURL" : "jenkins构建地址",
"startTime": time.time(),
"endTime": time.time(),
"version": "1050"
}

def get_code():
command="git submodule update --init --recursive && cd dbus_autotest && git checkout dev-gsetting-1050 && cd ../dde_robot && git checkout dev-1050"
os.system(command)

def execute_gsetting_job(project_name):
command="cd dbus_autotest && python3 pytest_runner.py -md" + project_name
os.system(command)

def execute_robot_job(project_name):
command="cd dde_robot/tools && bash ci_run_robot.sh %sAND1050 2 ||true" % project_name
os.system(command)

def analysis_robot_report():
os.system('pwd')
pwd = os.getcwd()
xml_path = pwd + '/dde_robot/tests/robot/output.xml'
print(xml_path)
suite = ExecutionResult(xml_path).suite
allTests = suite.statistics.all
return allTests

def analysis_dbus_report():
pwd = os.getcwd()
csv_path = pwd + '/dbus_autotest/allure-report/data/suites.csv'
print(csv_path)
passed_command = 'grep -w passed %s | wc -l' % csv_path
failed_command = 'grep -w failed %s | wc -l' % csv_path
broken_command = 'grep -w broken %s | wc -l' % csv_path
passed = subprocess.getoutput(passed_command)
failed = subprocess.getoutput(failed_command)
broken = subprocess.getoutput(broken_command)
return passed, failed, broken

def analysis_report(project_name, json_template):
robot_report = analysis_robot_report()
robot_passed = int(robot_report.passed)
robot_failed = int(robot_report.failed)
robot_total = int(robot_report.total)
dbus_passed = int(analysis_dbus_report()[0])
dbus_failed = int(analysis_dbus_report()[1])
dbus_broken = int(analysis_dbus_report()[2])
dbus_total = dbus_passed + dbus_failed + dbus_broken
report_failed = robot_failed + dbus_failed
report_total = robot_total + dbus_total
report_failed_rate = str('%.1f' % (report_failed / report_total)) + '%'
data = '%s,%s,%s' % (str(report_failed), str(report_total), report_failed_rate)
json_template["appName"] = project_name
json_template["checkResult"] = data
json_tem = json.dumps(json_template)
print(json_tem)
file_name = project_name + '_at.json'
with open(file_name, 'w') as f:
f.write(json_tem)

if __name__=="__main__":
if sys.argv[1] == "dde-dock":
execute_robot_job("dock")
execute_gsetting_job("gsettings_dock")
analysis_report("dde-dock", json_template)
elif sys.argv[1] == "dde-control-center":
execute_robot_job("dcc")
execute_gsetting_job("gsettings_control_center")
analysis_report("dcc", json_template)
elif sys.argv[1] == "dde-launcher":
execute_robot_job("launcher")
execute_gsetting_job("gsettings_launcher")
analysis_report("dde-launcher", json_template)
else:
print("please enter correct project name")
转载请注明出处 每天努力多一点,忧愁少一点,快乐多一点 --->by晴朗sky
原文地址:https://www.cnblogs.com/qinlangsky/p/15633209.html