Python学习-读取xmind文件,计算用例数工具

Python学习-读取xmind文件,计算用例数工具,第1张

概述优先导入模块  xmindparser :pipinstallxmindparser代码如下:fromxmindparserimportxmind_to_dictimporttkinterastkfromtkinterimportfiledialogclassParseXmind:#统计文件中用例数defcount_case(self,li):foriinrange(len(li)):

优先导入模块  xmindparser :pip install xmindparser

代码如下:

from xmindparser import xmind_to_dictimport tkinter as tkfrom tkinter import filedialogclass ParseXmind:    # 统计文件中用例数    def count_case(self, li):        for i in range(len(li)):            if li[i].__contains__('topics'):  # 带topics标签意味着有子标题,递归执行方法                self.count_case(li[i]['topics'])            else:  # 不带topics意味着无子标题,此级别既是用例                # print(li[i]['Title'])                if li[i].__contains__('makers'):  # 有标记成功或失败时会有makers标签                    if li[i]['makers'].__contains__('task-done'):  # 标记成功的                        self.case_success += 1                    elif li[i]['makers'].__contains__('symbol-wrong'):  # 标记失败的                        self.case_fail += 1                    elif li[i]['makers'].__contains__('symbol-code'):  # 标记阻塞的                        self.case_block += 1                self.count += 1  # 用例总数                # print(self.count)     # 用例统计表新增一行    def new_line(self, filename, row_number):        self.count = 0        self.case_fail = 0        self.case_success = 0        self.case_block = 0        # 调用python中xmind_to_dict方法,将xmind转成字典        self.sheets = xmind_to_dict(filename)  # sheets是一个List,可包含多sheet页;        for sheet in self.sheets:            print(sheet)            self.my_List = sheet['topic']['topics']  # 字典的值sheet['topic']['topics']是一个List            # print(my_List)            self.count_case(self.my_List)        # 插入一行统计数据        lastname = filename.split('/')        self.label_file = tk.Label(self.frm2, text=lastname[-1], relIEf='groove', borderwIDth='2', wIDth=25)        self.label_file.grID(row=row_number, column=0)        self.label_case = tk.Label(self.frm2, text=self.count, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_case.grID(row=row_number, column=1)        self.label_pass = tk.Label(self.frm2, text=self.case_success, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_pass.grID(row=row_number, column=2)        self.label_fail = tk.Label(self.frm2, text=self.case_fail, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_fail.grID(row=row_number, column=3)        self.label_block = tk.Label(self.frm2, text=self.case_block, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_block.grID(row=row_number, column=4)        self.total_cases += self.count        self.total_success += self.case_success        self.total_fail += self.case_fail        self.total_block += self.case_block    # 用例统计表新增多行    def new_lines(self):        # total汇总用        self.total_cases = 0        self.total_success = 0        self.total_fail = 0        self.total_block = 0        lines = self.text.get(1.0, tk.END)  # 从text中获取所有行        row_number = 2        for line in lines.splitlines():  # 分隔成每行            if line == '':                break            print(line)            self.new_line(line, row_number)            row_number += 1        # total汇总行        self.label_file = tk.Label(self.frm2, text='total', relIEf='groove', borderwIDth='2', wIDth=25)        self.label_file.grID(row=row_number, column=0)        self.label_case = tk.Label(self.frm2, text=self.total_cases, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_case.grID(row=row_number, column=1)        self.label_pass = tk.Label(self.frm2, text=self.total_success, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_pass.grID(row=row_number, column=2)        self.label_fail = tk.Label(self.frm2, text=self.total_fail, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_fail.grID(row=row_number, column=3)        self.label_block = tk.Label(self.frm2, text=self.total_block, relIEf='groove', borderwIDth='2', wIDth=10)        self.label_block.grID(row=row_number, column=4)    # 上传多个文件,并插入text中    def upload_files(self):        select_files = tk.filedialog.askopenfilenames(title="可选择1个或多个文件")        for file in select_files:            self.text.insert(tk.END, file + '\n')            self.text.update()    def __init__(self, root):        # GUI        root.Title('Xmind用例个数统计')        wIDth = 570        height = 500        xscreen = root.winfo_screenwIDth()        yscreen = root.winfo_screenheight()        xmIDdle = (xscreen - wIDth)/2        ymIDdle = (yscreen - height)/2        root.geometry('%dx%d+%d+%d' % (wIDth, height, xmIDdle, ymIDdle))        self.frm1 = tk.Frame(root)        self.frm2 = tk.Frame(root)        self.frm1.grID(row=0, padx='20', pady='20')        self.frm2.grID(row=1, padx='30', pady='30')        self.but_upload = tk.button(self.frm1, text='上传xmind文件', command=self.upload_files, bg='#dfdfdf')        self.but_upload.grID(row=0, column=0, pady='10')        self.text = tk.Text(self.frm1, wIDth=55, height=10, bg='#f0f0f0')        self.text.grID(row=1, column=0)        self.but2 = tk.button(self.frm2, text="开始统计", command=self.new_lines, bg='#dfdfdf')        self.but2.grID(row=0, columnspan=5, pady='10')        self.label_file = tk.Label(self.frm2, text="文件名", relIEf='groove', borderwIDth='2', wIDth=25, bg='#FFD0A2')        self.label_file.grID(row=1, column=0)        self.label_case = tk.Label(self.frm2, text="用例数", relIEf='groove', borderwIDth='2', wIDth=10, bg='#FFD0A2').grID(row=1, column=1)        self.label_pass = tk.Label(self.frm2, text="成功", relIEf='groove', borderwIDth='2', wIDth=10, bg='#FFD0A2').grID(row=1, column=2)        self.label_fail = tk.Label(self.frm2, text="失败", relIEf='groove', borderwIDth='2', wIDth=10, bg='#FFD0A2').grID(row=1, column=3)        self.label_block = tk.Label(self.frm2, text="阻塞", relIEf='groove', borderwIDth='2', wIDth=10, bg='#FFD0A2').grID(row=1, column=4)root = tk.Tk()ParseXmind(root)root.mainloop()

txt文件写入执行命令:

cd D:.py文件所在目录python test.py

保存修改txt文件后缀为bat

双击bat文件即可执行.py文件

 

总结

以上是内存溢出为你收集整理的Python学习-读取xmind文件,计算用例数工具全部内容,希望文章能够帮你解决Python学习-读取xmind文件,计算用例数工具所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1189547.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存