首页 > 编程语言 >python分析xmind的节点

python分析xmind的节点

时间:2022-11-18 19:22:34浏览次数:42  
标签:node case python list param xmind key test 节点

 由于测试用例是xmind格式,工具只能查询到总的节点数,于是网上找了一段解析xmind的代码。

如下(出处记不得了就没贴):

# 模块名称(文件名为:parse_xmind.py)
import requests
import xmindparser

"""
@desc:   定义xmind中测试用例和质保平台对应的字段的类
@author: 
@date:   
"""


class SaveTestCaseParam(object):
    def __init__(self):
        self.case_name = ""
        self.test_case_level = ""
        self.pre_condition = ""
        self.step = ""
        self.expected_results = ""


"""
@desc:   读取整个测试用例的根节点和对应的子节点
@author: 
@date:   
"""


def xmind_parse_file(file_path):
    content_dict = xmindparser.xmind_to_dict(file_path)
    for index1 in content_dict:
        node_lists = index1['topic']['topics']
        case_list = []
        read_node(node_lists, case_list)
    return case_list


"""
@desc:   拼装xmind中的每一条测试用例
@author: 
@date:   
"""

def read_node(node_lists, case_list):
    if len(node_lists) >= 1:
        for node in node_lists:
            # 如何知道遍历的是最后一个节点
            # 当前的node的所有的key中没有topics,那就说明是最后一个节点了
            if not list(node.keys()).__contains__("topics"):
                for k, v in node.items():
                    case_list.append(v)
                # test_case_param = SaveTestCaseParam()             #### 由于我们定义的是最后一个子节点为一条用例,所以接下来很多代码都注释掉了
                # for key in node:
                #     if key == "title":
                #         setattr(test_case_param, 'case_name', node[key])
                #         setattr(test_case_param, 'step', node[key])
                #         setattr(test_case_param, 'expected_results', node[key])
                #         continue
                #     if key == "makers":
                #         setattr(test_case_param, 'test_case_level', node[key][0])

                # 添加到list中
                # case_list.append(node.keys)

            # 倒数第二个节点
            # else:
            #     if list(node.keys()).__contains__("makers"):
            #         test_case_param = SaveTestCaseParam()
            #         for key in node:
            #             if key == "title":
            #                 setattr(test_case_param, 'case_name', node[key])
            #                 continue
            #             if key == 'topics':
            #                 parent_node = node[key]
            #                 for sub_node_key in parent_node:
            #                     for key1 in sub_node_key:
            #                         if key1 == "title":
            #                             title_content = sub_node_key['title']
            #                             if "前置条件" in title_content:
            #                                 setattr(test_case_param, 'pre_condition', title_content)
            #                                 continue
            #                             if "用例步骤" in title_content:
            #                                 setattr(test_case_param, 'step', title_content)
            #                                 continue
            #                             if "预期结果" in title_content:
            #                                 setattr(test_case_param, 'expected_results', title_content)
            #                 continue
            #             if key == 'makers':
            #                 setattr(test_case_param, 'test_case_level', node[key][0])
            #         # 添加到list中
            #         case_list.append(test_case_param)
            else:
                for key in node:
                    if key == 'topics':
                        read_node(node[key], case_list)


"""
@desc:   主入口
@author: 
@date:   
"""

if __name__ == '__main__':
    # 文件路径
    file_path = 'C:/Users/qgc/Desktop/111.xmind'
    case_list = xmind_parse_file(file_path)
    print("测试案例个数:", len(case_list))

 这种如果做个网页工具,应该算是比较好的。

标签:node,case,python,list,param,xmind,key,test,节点
From: https://www.cnblogs.com/qgc1995/p/16738308.html

相关文章

  • python爬虫实战一、爬取酷我音乐榜单并写入txt文件保存到本地
    python爬虫实战一、爬取酷我音乐榜单并写入txt文件保存到本地一、总代码和运行截图#加载需要的库importrequestsfrombs4importBeautifulSoupfromlxmlimportetreef=......
  • Python学习——小知识
    前言:因为没有系统学习过python语言,所以在看python代码的过程中十分吃力,因此决定把每次不懂的地方记录之,积土成山,积水成渊。1.判断变量的类型——​​isinstance()​​a=li......
  • python基础入门之进程
    python基础入门之进程目录python基础入门之进程阻塞与非阻塞同步与异步综合使用创建进程的多种方式进程间数据隔离进程的join方法IPC机制生产者消费模型进程对象的多种方......
  • Python 笔记
    Python笔记记录写Python需要注意的问题,以及一些技巧。在Python中EverythingisObject。Python中的模块standardmodulesbuilt-inmodulesdynamicmodules......
  • c++ 调用 python 数据类型对照表
    ParsingargumentsandbuildingvaluesThesefunctionsareusefulwhencreatingyourownextensionsfunctionsandmethods.Additionalinformationandexamplesa......
  • python-etcd
    安装pipinstallpython-etcdp查询所有的keys,或者以某个前缀的keysetcdctlget--prefix""etcdctlget--prefix "/nodes"只列出keys,不显示值etcdctlget--pre......
  • 加速python代码
    jupyter:jupytext:text_representation:extension:.mdformat_name:markdownformat_version:'1.2'jupytext_version:1.4.1kern......
  • Centos 7 部署 openGauss 3.1.0 级联备库集群及集群缩容删除节点-运维指南
    一、安装环境设置1.1硬件环境名称最低配置建议配置测试配置服务器数量3略略硬盘*至少1GB用于安装openGauss的应用程序。*每个主机需大约300MB用于......
  • python零基础入门教程(非常详细),从零基础入门到精通,看完这一篇就够了
    前言本文罗列了了python零基础入门到精通的详细教程,内容均以知识目录的形式展开。第一章:python基础之markdownTypora软件下载Typora基本使用Typora补充说明编程与编......
  • python每执行10次休息一会
       importtimen=0whilen<10:print(n,"删除数据成功")n=n+1ifn==10:n=0time.sleep(5)continueimportt......