|
|
- import csv
- import os
-
- def deal_params(dev_list,fun):
- para_list=[]
- for i in dev_list:
- a=fun(i)
- dict1=demo(a)
- para_list.append(dict1)
- read_params_list=[]
- for i in para_list:
- if len(i)>0:
- for j,k in i.items():
- k.append(j)
- read_params_list.append(tuple(k))
- for l in range(len(k)):
- if isinstance(k[l],int):
- pass
- read_params_list=sort_list(read_params_list)
- return read_params_list
-
- def output_value_csv(data,header =["test_num","device_name","reg_name","offset","alter_value","expect_value"],file_name="data.csv"):
- if file_name=="data.csv":
- if os.path.exists(file_name):
- print("{}文件已存在".format(file_name))
- else:
- with open(file_name,"w",encoding="utf-8",newline='')as fq:
- writer=csv.writer(fq)
- writer.writerow(header)
- writer.writerows(data)
- else:
- if os.path.exists(file_name):
- print("{}已删除,重新生成".format(file_name))
- os.remove(file_name)
- with open(file_name,"w",encoding="utf-8",newline='')as fq:
- writer=csv.writer(fq)
- writer.writerow(header)
- writer.writerows(data)
-
- def out_put_test_reslut(data):
- file_name="testcase_result.csv"
- header=["tst_num","device_name","reg_name","offset","init_value","alter_value","expect_value","actual_value","test_result"]
- output_value_csv(data,header=header,file_name=file_name)
-
- def read_csv():
- try:
- reg_par_list=[]
- with open("data.csv") as f:
- f_csv=csv.reader(f)
- headers=next(f_csv)
- for row in f_csv:
- reg_params=(row[0],row[1],row[2],int(row[3],16),int(row[4],16),int(row[5],16))
- reg_par_list.append(reg_params)
- return reg_par_list
- except IndexError:
- print("请补充测试数据")
- except Exception as ep:
- print(ep)
-
- def demo(a):
- dict1={}
- for j,k in a.items():
- for i in range(len(k)):
- dict1[k[i]["name"]] = [j,k[i]["offset"]]
- return dict1
-
- def sort_list(a):
- for i in range(len(a)):
- for j in range(i+1,len(a)):
- if a[i][0] == a[j][0]:
- if a[i][1]>a[j][1]:
- a[i],a[j] = a[j],a[i]
- res=[]
- res1=[]
- for i in a:
- i=list(i)
- res.append(i)
- [res1.append(res[i][0]) for i in range(len(res)) if res[i][0] not in res1]
- for i in res1:
- a=1
- for k in res:
- if i in k:
- testcasenum="testcase{}_({})".format(str(a),i)
- k.insert(0,testcasenum)
- a+=1
- return res
|