smartpush 1.2.7__py3-none-any.whl → 1.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smartpush/export/basic/ExcelExportChecker.py +68 -3
- smartpush/export/basic/ReadExcel.py +2 -1
- smartpush/test.py +5 -1
- smartpush/utils/DataTypeUtils.py +30 -0
- {smartpush-1.2.7.dist-info → smartpush-1.2.9.dist-info}/METADATA +1 -1
- {smartpush-1.2.7.dist-info → smartpush-1.2.9.dist-info}/RECORD +8 -7
- {smartpush-1.2.7.dist-info → smartpush-1.2.9.dist-info}/WHEEL +0 -0
- {smartpush-1.2.7.dist-info → smartpush-1.2.9.dist-info}/top_level.txt +0 -0
@@ -2,6 +2,8 @@ import copy
|
|
2
2
|
import json
|
3
3
|
from urllib.parse import unquote
|
4
4
|
from smartpush.export.basic.ReadExcel import *
|
5
|
+
from datetime import datetime
|
6
|
+
from smartpush.utils import DataTypeUtils
|
5
7
|
|
6
8
|
"""
|
7
9
|
用于excel校验
|
@@ -95,14 +97,17 @@ def check_excel_content_form_dict(actual, expected, **kwargs):
|
|
95
97
|
return check_excel_content(actual, expected)
|
96
98
|
|
97
99
|
|
98
|
-
def check_excel_content_including_expected(actual, expected, **kwargs):
|
100
|
+
def check_excel_content_including_expected(actual, expected, expected_oss, **kwargs):
|
99
101
|
"""
|
100
102
|
通过 OSS URL 比较 Excel 内容,期望是包含的结果,actual传的是生成的oss
|
101
103
|
"""
|
102
104
|
actual, expected = read_excel_and_write_to_dict(actual, **kwargs), read_excel_and_write_to_dict(
|
103
105
|
expected, **kwargs)
|
104
106
|
# 判断是否存在差异
|
105
|
-
|
107
|
+
if kwargs.get("export_type") == "flow":
|
108
|
+
missing_items = assert_flow(expected, actual, expected_oss)
|
109
|
+
else:
|
110
|
+
missing_items = find_missing_elements(expected.values(), actual.values())
|
106
111
|
return (False, {"与期望结果存在差异": missing_items}) if missing_items else (True, "校验期望结果包含校验通过")
|
107
112
|
|
108
113
|
|
@@ -114,6 +119,33 @@ def find_missing_elements(list1, list2):
|
|
114
119
|
return missing
|
115
120
|
|
116
121
|
|
122
|
+
def assert_flow(expected, actual, expected_oss):
|
123
|
+
# 判断预期数据in实际导出的数据
|
124
|
+
ex_sheet0 = expected.get("sheet0", [])
|
125
|
+
ac_sheet0 = actual.get("sheet0", [])
|
126
|
+
ex_sheet1 = expected.get("Flow node data by sending time", [])
|
127
|
+
ac_sheet1 = actual.get("Flow node data by sending time", [])
|
128
|
+
differences = []
|
129
|
+
res=[]
|
130
|
+
ex_sheet1.append(ex_sheet0)
|
131
|
+
ac_sheet1.append(ac_sheet0)
|
132
|
+
for i in ac_sheet1:
|
133
|
+
if i not in ex_sheet1:
|
134
|
+
differences.append(i)
|
135
|
+
# 判断对应的列数据
|
136
|
+
for diff in differences:
|
137
|
+
if len(diff) != 24:
|
138
|
+
res.append("列预期不正确")
|
139
|
+
# 判断多出的行,获取今天的日期,与预期日期对比
|
140
|
+
ex_data = expected_oss.split("/")[4].split("-")
|
141
|
+
today = datetime.today()
|
142
|
+
target_date = datetime(int(ex_data[0]), int(ex_data[1]), int(ex_data[2]))
|
143
|
+
diff_days = (today - target_date).days
|
144
|
+
if len(differences) != diff_days:
|
145
|
+
res.append("日期预期不正确")
|
146
|
+
return res
|
147
|
+
|
148
|
+
|
117
149
|
def check_excel_content_form_list(actual, expected):
|
118
150
|
"""
|
119
151
|
通过 内容 比较 Excel 内容,不包含表头
|
@@ -134,7 +166,8 @@ def check_excel_all(actual_oss, expected_oss, check_type=None, **kwargs):
|
|
134
166
|
flag1, name_result = check_excel_name(actual_oss, expected_oss)
|
135
167
|
flag3, header_result = check_excel_header(actual_data_copy, expected_data_copy, type=file_type, **kwargs)
|
136
168
|
if check_type == "including":
|
137
|
-
flag2, content_result = check_excel_content_including_expected(actual, expected, type=file_type,
|
169
|
+
flag2, content_result = check_excel_content_including_expected(actual, expected, expected_oss, type=file_type,
|
170
|
+
**kwargs)
|
138
171
|
else:
|
139
172
|
flag2, content_result = check_excel_content_form_dict(actual, expected, type=file_type, **kwargs)
|
140
173
|
print(json.dumps(
|
@@ -326,3 +359,35 @@ def compare_lists(actual_dict_list, expected_dict_list):
|
|
326
359
|
if item1 != item2:
|
327
360
|
diff.append(('列表索引的不同值', i, (item1, item2)))
|
328
361
|
return diff
|
362
|
+
|
363
|
+
|
364
|
+
def check_field_format(actual_oss, **kwargs):
|
365
|
+
"""
|
366
|
+
逐个校验字段类型
|
367
|
+
**kwargs: fileds为需检查字段,结构为dict,如{"0": {"1": "email", "2": "time"}},
|
368
|
+
即校验第一个sheet第二个字段需符合email格式,第二个字段需符合time格式
|
369
|
+
"""
|
370
|
+
# 获取oss内容并存入dict
|
371
|
+
actual = read_excel_from_oss(actual_oss)
|
372
|
+
actual_data_copy = copy.deepcopy(actual)
|
373
|
+
actual_dict = read_excel_and_write_to_dict(actual, **kwargs)
|
374
|
+
# 解析参数并校验字段类型
|
375
|
+
errors = []
|
376
|
+
actual_dict_key = list(actual_dict.keys())
|
377
|
+
for key in kwargs["fileds"].keys():
|
378
|
+
if isinstance(key, int) and 0 <= key < len(actual_dict):
|
379
|
+
for filed_key in kwargs["fileds"][key].keys():
|
380
|
+
num = 1
|
381
|
+
for row in actual_dict[actual_dict_key[key]]:
|
382
|
+
if kwargs["fileds"][key][filed_key] == "email":
|
383
|
+
fool = DataTypeUtils.DataTypeUtils().check_email_format(email=row[filed_key])
|
384
|
+
if not fool:
|
385
|
+
errors.append(f"{actual_dict_key[key]} 表, 第{num}行{filed_key}列{kwargs['fileds'][key][filed_key]}格式不符合规范, 值为:{row[filed_key]}")
|
386
|
+
elif kwargs["fileds"][key][filed_key] == "time":
|
387
|
+
fool = DataTypeUtils.DataTypeUtils().check_time_format(time_str=row[filed_key], precision=kwargs.get('precision', 's'))
|
388
|
+
if not fool:
|
389
|
+
errors.append(
|
390
|
+
f"{actual_dict_key[key]} 表, 第{num}行{filed_key}列{kwargs['fileds'][key][filed_key]}格式不符合规范, 值为:{row[filed_key]}")
|
391
|
+
num += 1
|
392
|
+
print(errors if len(errors) > 0 else "都校验成功")
|
393
|
+
return False if len(errors) > 0 else True
|
@@ -95,7 +95,8 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
|
95
95
|
row_dict = {} # 创建一个空字典来存储按行转换的数据
|
96
96
|
for sheet_name, row in dfs.items():
|
97
97
|
row = row.to_dict(orient='records')
|
98
|
-
if kwargs.get("ignore_sort") is not None
|
98
|
+
if kwargs.get("ignore_sort") is not None and StringUtils.to_lower(sheet_name) == \
|
99
|
+
StringUtils.to_lower(kwargs.get("ignore_sort_sheet_name", sheet_name)): # 可传参指定那个sheet_name
|
99
100
|
sorted_data_asc = sorted(row[1:], key=lambda x: x.get(kwargs.get("ignore_sort"), 0),
|
100
101
|
reverse=True) # 内部排序
|
101
102
|
sorted_data_asc = [row[0]] + sorted_data_asc
|
smartpush/test.py
CHANGED
@@ -27,7 +27,11 @@ if __name__ == '__main__':
|
|
27
27
|
# # print(read_excel_and_write_to_dict(read_excel_from_oss(oss1), type=".xlsx"))
|
28
28
|
# print(check_excel(check_type="all", actual_oss=actual_oss, expected_oss=expected_oss))
|
29
29
|
# print(check_excel_all(actual_oss=oss1, expected_oss=oss2,skiprows =1))
|
30
|
-
print(check_excel_all(actual_oss=oss1, expected_oss=oss2, ignore_sort=0))
|
30
|
+
#print(check_excel_all(actual_oss=oss1, expected_oss=oss2, ignore_sort=0))
|
31
31
|
# print(check_excel_all(actual_oss=a_person_oss2, expected_oss=e_person_oss1, check_type="including"))
|
32
32
|
# print(check_excel_all(actual_oss=e_person_oss1, expected_oss=a_person_oss2, check_type="person"))
|
33
33
|
# read_excel_csv_data(type=)
|
34
|
+
|
35
|
+
flow_ex="https://cdn.smartpushedm.com/material_ec2/2025-02-20/ad9e1534b8134dd098e96813f17d4b4d/%E6%B5%8B%E8%AF%95flow%E6%95%B0%E6%8D%AE%E6%8A%A5%E5%91%8A%E5%AF%BC%E5%87%BA%E5%8B%BF%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
|
36
|
+
flow_ac="https://cdn.smartpushedm.com/material_ec2/2025-03-04/0c8f919f28d4455f9908f905aada7efb/测试flow数据报告导出勿动数据概览.xlsx"
|
37
|
+
print(check_excel_all(actual_oss=flow_ac, expected_oss=flow_ex, check_type="including",export_type="flow",skiprows=1))
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import re
|
2
|
+
from datetime import datetime
|
3
|
+
|
4
|
+
|
5
|
+
class DataTypeUtils:
|
6
|
+
|
7
|
+
def check_email_format(self, email):
|
8
|
+
# 检查邮箱是否符合格式
|
9
|
+
if email != "" or email is not None:
|
10
|
+
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
11
|
+
return bool(re.match(pattern, email))
|
12
|
+
|
13
|
+
def check_time_format(self, time_str, precision="s"):
|
14
|
+
# 检查时间是否符合格式,并校验是精确到秒还是分
|
15
|
+
if precision == 's':
|
16
|
+
try:
|
17
|
+
# 尝试按照精确到秒的格式解析
|
18
|
+
datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S')
|
19
|
+
return True
|
20
|
+
except ValueError:
|
21
|
+
return False
|
22
|
+
elif precision == 'm':
|
23
|
+
try:
|
24
|
+
# 尝试按照精确到分钟的格式解析
|
25
|
+
datetime.strptime(time_str, '%Y-%m-%d %H:%M')
|
26
|
+
return True
|
27
|
+
except ValueError:
|
28
|
+
return False
|
29
|
+
else:
|
30
|
+
raise ValueError("Invalid precision parameter. Use 's' for seconds or 'm' for minutes.")
|
@@ -1,14 +1,15 @@
|
|
1
1
|
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
2
|
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
3
|
-
smartpush/test.py,sha256=
|
3
|
+
smartpush/test.py,sha256=pMXVJzsiQc7INFYmH_ZUPkHBbjl0xmFD8-9yKL8Wn1o,3564
|
4
4
|
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
-
smartpush/export/basic/ExcelExportChecker.py,sha256=
|
5
|
+
smartpush/export/basic/ExcelExportChecker.py,sha256=BOcIEqYrZD9yhMSvHrqPFDOUj_5zKhm2_OyQSN7KOds,17718
|
6
6
|
smartpush/export/basic/GetOssUrl.py,sha256=zlExF_jy_TRV5lp0fws8Wed5MF_byp7JAEmvARVqlIg,3263
|
7
|
-
smartpush/export/basic/ReadExcel.py,sha256=
|
7
|
+
smartpush/export/basic/ReadExcel.py,sha256=ZnG2mtYqLY-xuYx9SyulbdYUP_0E5jIeKDewfakAsTw,7342
|
8
8
|
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
9
|
+
smartpush/utils/DataTypeUtils.py,sha256=BC7ioztO3vAfKd1EOoNvXdVuXYY8qjNskV1DP7LhW-M,1082
|
9
10
|
smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
|
10
11
|
smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
11
|
-
smartpush-1.2.
|
12
|
-
smartpush-1.2.
|
13
|
-
smartpush-1.2.
|
14
|
-
smartpush-1.2.
|
12
|
+
smartpush-1.2.9.dist-info/METADATA,sha256=NLRbHHvxDiBoF4HDuR8tV_7F61tySFBVumFx0Jcebew,145
|
13
|
+
smartpush-1.2.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
14
|
+
smartpush-1.2.9.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
15
|
+
smartpush-1.2.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|