smartpush 1.0.5__py3-none-any.whl → 1.0.6__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 +111 -15
- smartpush/felix_test.py +13 -6
- {smartpush-1.0.5.dist-info → smartpush-1.0.6.dist-info}/METADATA +1 -1
- smartpush-1.0.6.dist-info/RECORD +10 -0
- smartpush-1.0.5.dist-info/RECORD +0 -10
- {smartpush-1.0.5.dist-info → smartpush-1.0.6.dist-info}/WHEEL +0 -0
- {smartpush-1.0.5.dist-info → smartpush-1.0.6.dist-info}/top_level.txt +0 -0
@@ -3,11 +3,11 @@ import os
|
|
3
3
|
import re
|
4
4
|
from io import BytesIO
|
5
5
|
from urllib.parse import unquote
|
6
|
-
|
7
6
|
import pandas as pd
|
8
7
|
import numpy as np
|
9
8
|
import warnings
|
10
9
|
from requests import request
|
10
|
+
|
11
11
|
"""
|
12
12
|
用于excel校验
|
13
13
|
"""
|
@@ -25,7 +25,7 @@ def read_excel_from_oss(url="", method="get"):
|
|
25
25
|
print(f"读取oss报错 {url} 时出错:{e}")
|
26
26
|
|
27
27
|
|
28
|
-
def read_excel_and_write_to_dict(excel_data=None, file_name=None):
|
28
|
+
def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
|
29
29
|
"""excel内容并写入到内存dict中
|
30
30
|
:param excel_data:excel的io对象, 参数和file_name互斥
|
31
31
|
:file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
|
@@ -37,7 +37,7 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None):
|
|
37
37
|
excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
|
38
38
|
with warnings.catch_warnings():
|
39
39
|
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
40
|
-
df = pd.read_excel(excel_data, engine="openpyxl")
|
40
|
+
df = pd.read_excel(excel_data, engine="openpyxl", **kwargs)
|
41
41
|
# 将DataFrame转换为字典,以行为单位存储数据
|
42
42
|
row_dict = {} # 创建一个空字典来存储按行转换的数据
|
43
43
|
for index, row in df.iterrows(): # 遍历DataFrame中的每一行
|
@@ -47,7 +47,7 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None):
|
|
47
47
|
print(f"excel写入dict时出错:{e}")
|
48
48
|
|
49
49
|
|
50
|
-
def read_excel_and_write_to_list(excel_data=None, file_name=None):
|
50
|
+
def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
|
51
51
|
"""excel内容并写入到内存list中
|
52
52
|
:param excel_data:excel的io对象, 参数和file_name互斥
|
53
53
|
:file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
|
@@ -89,7 +89,8 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None):
|
|
89
89
|
|
90
90
|
with warnings.catch_warnings():
|
91
91
|
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
92
|
-
df = pd.read_excel(excel_data, engine="openpyxl")
|
92
|
+
df = pd.read_excel(excel_data, engine="openpyxl", **kwargs)
|
93
|
+
print(df)
|
93
94
|
# 将DataFrame转换为字典,以行为单位存储数据
|
94
95
|
rows_list = df.values.tolist()
|
95
96
|
return rows_list
|
@@ -97,17 +98,36 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None):
|
|
97
98
|
print(f"excel写入list时出错:{e}")
|
98
99
|
|
99
100
|
|
100
|
-
def read_excel_and_write_to_csv(excel_data, file_name):
|
101
|
+
def read_excel_and_write_to_csv(excel_data, file_name, **kwargs):
|
101
102
|
"""excel内容并写入到csv中"""
|
102
103
|
try:
|
103
104
|
df = pd.read_excel(excel_data, engine="openpyxl")
|
104
105
|
local_csv_path = os.path.join(os.path.dirname(os.getcwd()) + "/temp_file/" + file_name)
|
105
|
-
df.to_csv(local_csv_path, index=False)
|
106
|
+
df.to_csv(local_csv_path, index=False, **kwargs)
|
106
107
|
return local_csv_path
|
107
108
|
except Exception as e:
|
108
109
|
print(f"excel写入csv时出错:{e}")
|
109
110
|
|
110
111
|
|
112
|
+
def read_excel_data_to_oss_link(oss, sheet_name=None, **kwargs) -> dict:
|
113
|
+
"""
|
114
|
+
1、根据oss link 直接读出 dict-list
|
115
|
+
2、支持多sheet,默认heet_name =None查全部
|
116
|
+
3、返回dict结构 {'sheet_name':[rows_list]}
|
117
|
+
"""
|
118
|
+
try:
|
119
|
+
with warnings.catch_warnings():
|
120
|
+
warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
|
121
|
+
dfs = pd.read_excel(read_excel_from_oss(oss), sheet_name, engine="openpyxl", **kwargs)
|
122
|
+
result = {}
|
123
|
+
for sheet_name, df in dfs.items():
|
124
|
+
rows_list = df.values.tolist()
|
125
|
+
result[sheet_name] = rows_list
|
126
|
+
return result
|
127
|
+
except Exception as e:
|
128
|
+
print(f"excel写入list时出错:{e}")
|
129
|
+
|
130
|
+
|
111
131
|
def check_excel(check_type="content", **kwargs):
|
112
132
|
"""对比excel
|
113
133
|
:param: type: 需要对比类型,
|
@@ -122,9 +142,10 @@ def check_excel(check_type="content", **kwargs):
|
|
122
142
|
if "actual" in kwargs.keys() and "expected" in kwargs.keys():
|
123
143
|
return check_excel_content(actual=kwargs["actual"], expected=kwargs["expected"])
|
124
144
|
else:
|
125
|
-
return check_excel_content(
|
126
|
-
|
127
|
-
|
145
|
+
return check_excel_content(
|
146
|
+
actual=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"])),
|
147
|
+
expected=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]))
|
148
|
+
)
|
128
149
|
elif check_type == "excelName":
|
129
150
|
return check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
130
151
|
elif check_type == "all":
|
@@ -140,6 +161,62 @@ def check_excel(check_type="content", **kwargs):
|
|
140
161
|
return False, [e]
|
141
162
|
|
142
163
|
|
164
|
+
# 定义比较类型和对应处理函数的映射
|
165
|
+
comparison_functions = {
|
166
|
+
# 内容
|
167
|
+
"content": lambda kwargs: check_excel_content(kwargs["actual"], kwargs[
|
168
|
+
"expected"])
|
169
|
+
if "actual" in kwargs and "expected" in kwargs
|
170
|
+
else check_excel_content(kwargs["actual_oss"], kwargs["expected_oss"]),
|
171
|
+
# excelName
|
172
|
+
"excelName": lambda kwargs: check_excel_name(kwargs["actual_oss"], kwargs["expected_oss"]),
|
173
|
+
# 全部
|
174
|
+
"all": lambda kwargs: check_excel_all(kwargs["actual_oss"], kwargs["expected_oss"])
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
def check_excel_for_lu(check_type="content", **kwargs):
|
179
|
+
"""对比excel
|
180
|
+
:param: type: 需要对比类型,
|
181
|
+
枚举:
|
182
|
+
content:对比两表格内容
|
183
|
+
方式1:传参actual_oss和expected_oss,参数类型str,url
|
184
|
+
放松1:传参actual和expected,参数类型list or dict
|
185
|
+
excelName: 对比两表格文件名称,传oss链接
|
186
|
+
all: 对比所有内容,传oss链接
|
187
|
+
"""
|
188
|
+
try:
|
189
|
+
# 根据 check_type 获取对应的处理函数
|
190
|
+
compare_func = comparison_functions.get(check_type)
|
191
|
+
if compare_func:
|
192
|
+
return compare_func(kwargs)
|
193
|
+
else:
|
194
|
+
return False, f"不支持此类型: {check_type}"
|
195
|
+
except KeyError as ke:
|
196
|
+
raise ke
|
197
|
+
print(f"类型对应参数缺失异常:{ke}")
|
198
|
+
return False, [str(ke)]
|
199
|
+
except Exception as e:
|
200
|
+
print(f"对比 Excel 异常:{e}")
|
201
|
+
return False, [str(e)]
|
202
|
+
|
203
|
+
|
204
|
+
def check_excel_content_form_oss(actual_oss, expected_oss):
|
205
|
+
"""通过 OSS URL 比较 Excel 内容"""
|
206
|
+
expected, actual = read_excel_and_write_to_list(read_excel_from_oss(expected_oss)), read_excel_and_write_to_list(
|
207
|
+
read_excel_from_oss(actual_oss))
|
208
|
+
return check_excel_content(actual=actual, expected=expected)
|
209
|
+
|
210
|
+
|
211
|
+
def check_excel_all(actual_oss, expected_oss):
|
212
|
+
"""
|
213
|
+
校验所有内容
|
214
|
+
"""
|
215
|
+
flag1, content_result = check_excel_content_form_oss(actual_oss, expected_oss)
|
216
|
+
flag2, name_result = check_excel_name(actual_oss, expected_oss)
|
217
|
+
return flag1 and flag2, {"文件名称": name_result, "导出内容": content_result}
|
218
|
+
|
219
|
+
|
143
220
|
def check_excel_name(actual_oss, expected_oss):
|
144
221
|
"""校验excel文件名称
|
145
222
|
:param actual_oss:实际oss链接
|
@@ -149,7 +226,7 @@ def check_excel_name(actual_oss, expected_oss):
|
|
149
226
|
actual_name = unquote(actual_oss.split("/")[-1])
|
150
227
|
expected_name = unquote(expected_oss.split("/")[-1])
|
151
228
|
if actual_name == expected_name:
|
152
|
-
return True, "excel
|
229
|
+
return True, "excel文件名称-完成匹配"
|
153
230
|
else:
|
154
231
|
return False, f"excel文件名称-不匹配, 实际: {actual_name}, 预期: {expected_name}"
|
155
232
|
except BaseException as msg:
|
@@ -162,6 +239,9 @@ def check_excel_content(actual, expected):
|
|
162
239
|
:param expected:预期内容:list或dict类型
|
163
240
|
"""
|
164
241
|
try:
|
242
|
+
# TODO 嵌套list -dict 比较失败
|
243
|
+
print(actual)
|
244
|
+
print(expected)
|
165
245
|
if actual == expected:
|
166
246
|
return True, ["excel内容-完全匹配"]
|
167
247
|
else:
|
@@ -174,7 +254,8 @@ def check_excel_content(actual, expected):
|
|
174
254
|
errors.append("excel内容-预期和实际行数相等,为" + str(actual_num) + "行")
|
175
255
|
else:
|
176
256
|
errors.append(
|
177
|
-
"excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(
|
257
|
+
"excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(
|
258
|
+
actual_num) + "预期: " + str(
|
178
259
|
expected_num))
|
179
260
|
# 断言不匹配行
|
180
261
|
if check_row >= 0:
|
@@ -182,15 +263,20 @@ def check_excel_content(actual, expected):
|
|
182
263
|
else:
|
183
264
|
num = len(actual)
|
184
265
|
for i in range(num):
|
266
|
+
# 将nan转换成None
|
267
|
+
actual[i] = [None if isinstance(x, (float, int)) and np.isnan(x) else x for x in actual[i]]
|
268
|
+
expected[i] = [None if isinstance(x, (float, int)) and np.isnan(x) else x for x in expected[i]]
|
185
269
|
if actual[i] == expected[i]:
|
186
270
|
continue
|
187
271
|
else:
|
188
272
|
errors.append(
|
189
|
-
"excel内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(
|
273
|
+
"excel内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(
|
274
|
+
actual[i]))
|
190
275
|
return False, errors
|
191
276
|
except Exception as e:
|
192
|
-
|
193
|
-
|
277
|
+
raise e
|
278
|
+
# print(f":excel内容-服务异常{e}")
|
279
|
+
# return False, [e]
|
194
280
|
|
195
281
|
|
196
282
|
def del_temp_file(file_name=""):
|
@@ -203,3 +289,13 @@ def del_temp_file(file_name=""):
|
|
203
289
|
print(f"文件 {file_path} 不存在。")
|
204
290
|
except Exception as e:
|
205
291
|
print(f"删除文件 {file_path} 时出错:{e}")
|
292
|
+
|
293
|
+
|
294
|
+
if __name__ == '__main__':
|
295
|
+
# print(check_excel_for_lu("content",actual_oss="https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2_prod/2025-01-20/fcb98e2965314ef2862db65760dcce1f/ab%E5%BC%B9%E7%AA%97%E6%B4%BB%E5%8A%A8-%E8%BD%AC%E5%8C%96%E7%8E%87%E8%8E%B7%E8%83%9C%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx",expected_oss="https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2_prod/2025-01-20/fcb98e2965314ef2862db65760dcce1f/ab%E5%BC%B9%E7%AA%97%E6%B4%BB%E5%8A%A8-%E8%BD%AC%E5%8C%96%E7%8E%87%E8%8E%B7%E8%83%9C%E9%94%80%E5%94%AE%E9%A2%9D%E6%98%8E%E7%BB%86%E6%95%B0%E6%8D%AE.xlsx"))
|
296
|
+
eexcelxcel = check_excel_for_lu("all",expected_oss="https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material/2025-01-24/3e1048ec9a7949b3be3727e71f4be645"
|
297
|
+
"/AutoTest-%E5%9B%BA%E5%AE%9AB-2025-01-24%20%E5%89%B5%E5%BB%BA%E7%9A%84Email12%E6%95%B0%E6%8D%AE%E6%A6%82%E8"
|
298
|
+
"%A7%88.xlsx", actual_oss = "https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material/2025-01-24/3e1048ec9a7949b3be3727e71f4be645"
|
299
|
+
"/AutoTest-%E5%9B%BA%E5%AE%9AB-2025-01-24%20%E5%89%B5%E5%BB%BA%E7%9A%84Email12%E6%95%B0%E6%8D%AE%E6%A6%82%E8"
|
300
|
+
"%A7%88.xlsx")
|
301
|
+
print(eexcelxcel)
|
smartpush/felix_test.py
CHANGED
@@ -4,10 +4,17 @@ from smartpush.export.basic import ExcelExportChecker
|
|
4
4
|
|
5
5
|
if __name__ == '__main__':
|
6
6
|
|
7
|
-
ossurl1 = "https://
|
8
|
-
ossurl2 = "https://
|
7
|
+
ossurl1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-10/94202be5d244428aa5fd560ce7ede732/%E7%94%A8%E6%88%B7%E7%95%99%E5%AD%98.xlsx"
|
8
|
+
ossurl2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-10/6df986e7855049f7846ae5fe1098c331/%E7%94%A8%E6%88%B7%E7%95%99%E5%AD%98.xlsx"
|
9
|
+
#
|
10
|
+
# # a = ExcelExportChecker.read_excel_and_write_to_list(excel_data=ExcelExportChecker.read_excel_from_oss(url=ossurl1))
|
11
|
+
# # b = ExcelExportChecker.read_excel_and_write_to_list(excel_data=ExcelExportChecker.read_excel_from_oss(url=ossurl2))
|
12
|
+
# # print(ExcelExportChecker.check_excel(actual=a, expected=b))
|
13
|
+
print(ExcelExportChecker.check_excel(check_type="all", actual_oss=ossurl1, expected_oss=ossurl2))
|
9
14
|
|
10
|
-
a =
|
11
|
-
b =
|
12
|
-
|
13
|
-
#
|
15
|
+
# a = ['2025-01-02', 1, '100%', 0.0, '0%', 0.0, '0%', nan, nan]
|
16
|
+
# b = ['2025-01-02', 1, '100%', 0.0, '0%', 0.0, '0%', nan, nan]
|
17
|
+
# if a == b:
|
18
|
+
# print(1)
|
19
|
+
# else:
|
20
|
+
# print(2)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
+
smartpush/felix_test.py,sha256=V6TMemTQDzz-tKRHEatUYQeEXLrbefKW7jLiBJ9wy7k,1016
|
3
|
+
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
4
|
+
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
+
smartpush/export/basic/ExcelExportChecker.py,sha256=HsxDvEjrbz7eOqGUWFl0nstDfFNEMHeQcu4xL03nZuk,13818
|
6
|
+
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
7
|
+
smartpush-1.0.6.dist-info/METADATA,sha256=Gq0meSdGsWSClFVvUfb3q2nyJCvwU09DqdskXexIys0,145
|
8
|
+
smartpush-1.0.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
9
|
+
smartpush-1.0.6.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
10
|
+
smartpush-1.0.6.dist-info/RECORD,,
|
smartpush-1.0.5.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
-
smartpush/felix_test.py,sha256=Lx5APlgJQ1bUY-632rE-BMW494IbXnUSWZjMj0GZgO4,904
|
3
|
-
smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
|
4
|
-
smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
|
5
|
-
smartpush/export/basic/ExcelExportChecker.py,sha256=ZGBIB9EW_x6EcKt9M2Q9CXj3vteJW63HqnFF7a9pOSY,9201
|
6
|
-
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
7
|
-
smartpush-1.0.5.dist-info/METADATA,sha256=qrXsMdpp3mo7roF1p2NcErmSAEMJZ2PUChNXZuYode8,145
|
8
|
-
smartpush-1.0.5.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
9
|
-
smartpush-1.0.5.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
10
|
-
smartpush-1.0.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|