-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.py
More file actions
87 lines (76 loc) · 2.64 KB
/
debug.py
File metadata and controls
87 lines (76 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# 创 建 人: 李先生
# 文 件 名: debug.py
# 说 明:
# 创建时间: 2022/4/27 19:41
# @Version:V 0.1
# @desc :
import io
import csv
import json
import os
from public.help import check, CASE_PATH
from public import exceptions
def username():
return 'lixiaofeng'
def password():
return "123456"
def token():
return os.getenv("token")
def load_csv(file_path: str) -> list:
"""
读取参数化csv文件数据
:param file_path: 文件路径
:return:
"""
file_path = os.path.join(CASE_PATH, file_path)
parametrize_list = list()
# logger.info(f"加载 {file_path} 文件......")
with io.open(check(file_path), encoding='gbk') as f:
reader = csv.DictReader(f)
for value in reader:
parametrize = list()
# del value["case_name"]
validate_list = list()
params_list = list()
try:
key = ",".join(value.keys()).strip()
key_list = key.split(",,")
except Exception as error:
raise exceptions.CSVFormatError(f"csv文件数据格式异常!{error}")
if len(key_list) == 1:
params_list.append(value)
parametrize.append(params_list)
elif len(key_list) == 2:
params_key_list = key_list[0]
validate_key_list = key_list[1]
for k, v in value.items():
if k and k in params_key_list:
parametrize.append({k: v})
elif k and k in validate_key_list:
if v:
validate_value = eval(v)
validate_value.update({"check": k})
validate_list.append([validate_value])
parametrize.append({"validate": validate_list})
else:
raise exceptions.CSVFormatError("csv文件数据格式异常!")
parametrize_list.append(parametrize)
# logger.info(f"读到数据 ==>> {parametrize_list} ")
return parametrize_list
def load_json(file_path: str) -> (dict or list):
"""
加载json文件数据
:param file_path: 文件路径
:return:
"""
file_path = os.path.join(CASE_PATH, file_path)
# logger.info(f"加载 {file_path} 文件......")
with open(check(file_path), encoding='utf-8') as f:
try:
data = json.load(f)
except json.JSONDecodeError as ex:
raise exceptions.FileFormatError("file: {} error: {}".format(file_path, ex))
# logger.info(f"读到数据 ==>> {data} ")
return data