smartpush 1.0.5__py3-none-any.whl → 1.0.7__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.
@@ -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,7 @@ 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", na_filter=False, **kwargs)
93
93
  # 将DataFrame转换为字典,以行为单位存储数据
94
94
  rows_list = df.values.tolist()
95
95
  return rows_list
@@ -97,17 +97,36 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None):
97
97
  print(f"excel写入list时出错:{e}")
98
98
 
99
99
 
100
- def read_excel_and_write_to_csv(excel_data, file_name):
100
+ def read_excel_and_write_to_csv(excel_data, file_name, **kwargs):
101
101
  """excel内容并写入到csv中"""
102
102
  try:
103
103
  df = pd.read_excel(excel_data, engine="openpyxl")
104
104
  local_csv_path = os.path.join(os.path.dirname(os.getcwd()) + "/temp_file/" + file_name)
105
- df.to_csv(local_csv_path, index=False)
105
+ df.to_csv(local_csv_path, index=False, **kwargs)
106
106
  return local_csv_path
107
107
  except Exception as e:
108
108
  print(f"excel写入csv时出错:{e}")
109
109
 
110
110
 
111
+ def read_excel_data_to_oss_link(oss, sheet_name=None, **kwargs) -> dict:
112
+ """
113
+ 1、根据oss link 直接读出 dict-list
114
+ 2、支持多sheet,默认heet_name =None查全部
115
+ 3、返回dict结构 {'sheet_name':[rows_list]}
116
+ """
117
+ try:
118
+ with warnings.catch_warnings():
119
+ warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
120
+ dfs = pd.read_excel(read_excel_from_oss(oss), sheet_name, engine="openpyxl", **kwargs)
121
+ result = {}
122
+ for sheet_name, df in dfs.items():
123
+ rows_list = df.values.tolist()
124
+ result[sheet_name] = rows_list
125
+ return result
126
+ except Exception as e:
127
+ print(f"excel写入list时出错:{e}")
128
+
129
+
111
130
  def check_excel(check_type="content", **kwargs):
112
131
  """对比excel
113
132
  :param: type: 需要对比类型,
@@ -122,9 +141,10 @@ def check_excel(check_type="content", **kwargs):
122
141
  if "actual" in kwargs.keys() and "expected" in kwargs.keys():
123
142
  return check_excel_content(actual=kwargs["actual"], expected=kwargs["expected"])
124
143
  else:
125
- return check_excel_content(actual=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"])),
126
- expected=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]))
127
- )
144
+ return check_excel_content(
145
+ actual=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"])),
146
+ expected=read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]))
147
+ )
128
148
  elif check_type == "excelName":
129
149
  return check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
130
150
  elif check_type == "all":
@@ -140,6 +160,62 @@ def check_excel(check_type="content", **kwargs):
140
160
  return False, [e]
141
161
 
142
162
 
163
+ # 定义比较类型和对应处理函数的映射
164
+ comparison_functions = {
165
+ # 内容
166
+ "content": lambda kwargs: check_excel_content(kwargs["actual"], kwargs[
167
+ "expected"])
168
+ if "actual" in kwargs and "expected" in kwargs
169
+ else check_excel_content(kwargs["actual_oss"], kwargs["expected_oss"]),
170
+ # excelName
171
+ "excelName": lambda kwargs: check_excel_name(kwargs["actual_oss"], kwargs["expected_oss"]),
172
+ # 全部
173
+ "all": lambda kwargs: check_excel_all(kwargs["actual_oss"], kwargs["expected_oss"])
174
+ }
175
+
176
+
177
+ def check_excel_for_lu(check_type="content", **kwargs):
178
+ """对比excel
179
+ :param: type: 需要对比类型,
180
+ 枚举:
181
+ content:对比两表格内容
182
+ 方式1:传参actual_oss和expected_oss,参数类型str,url
183
+ 放松1:传参actual和expected,参数类型list or dict
184
+ excelName: 对比两表格文件名称,传oss链接
185
+ all: 对比所有内容,传oss链接
186
+ """
187
+ try:
188
+ # 根据 check_type 获取对应的处理函数
189
+ compare_func = comparison_functions.get(check_type)
190
+ if compare_func:
191
+ return compare_func(kwargs)
192
+ else:
193
+ return False, f"不支持此类型: {check_type}"
194
+ except KeyError as ke:
195
+ raise ke
196
+ print(f"类型对应参数缺失异常:{ke}")
197
+ return False, [str(ke)]
198
+ except Exception as e:
199
+ print(f"对比 Excel 异常:{e}")
200
+ return False, [str(e)]
201
+
202
+
203
+ def check_excel_content_form_oss(actual_oss, expected_oss):
204
+ """通过 OSS URL 比较 Excel 内容"""
205
+ expected, actual = read_excel_and_write_to_list(read_excel_from_oss(expected_oss)), read_excel_and_write_to_list(
206
+ read_excel_from_oss(actual_oss))
207
+ return check_excel_content(actual=actual, expected=expected)
208
+
209
+
210
+ def check_excel_all(actual_oss, expected_oss):
211
+ """
212
+ 校验所有内容
213
+ """
214
+ flag1, content_result = check_excel_content_form_oss(actual_oss, expected_oss)
215
+ flag2, name_result = check_excel_name(actual_oss, expected_oss)
216
+ return flag1 and flag2, {"文件名称": name_result, "导出内容": content_result}
217
+
218
+
143
219
  def check_excel_name(actual_oss, expected_oss):
144
220
  """校验excel文件名称
145
221
  :param actual_oss:实际oss链接
@@ -149,7 +225,7 @@ def check_excel_name(actual_oss, expected_oss):
149
225
  actual_name = unquote(actual_oss.split("/")[-1])
150
226
  expected_name = unquote(expected_oss.split("/")[-1])
151
227
  if actual_name == expected_name:
152
- return True, "excel文件名称-匹配"
228
+ return True, "excel文件名称-完成匹配"
153
229
  else:
154
230
  return False, f"excel文件名称-不匹配, 实际: {actual_name}, 预期: {expected_name}"
155
231
  except BaseException as msg:
@@ -162,6 +238,7 @@ def check_excel_content(actual, expected):
162
238
  :param expected:预期内容:list或dict类型
163
239
  """
164
240
  try:
241
+ # TODO 嵌套list -dict 比较失败
165
242
  if actual == expected:
166
243
  return True, ["excel内容-完全匹配"]
167
244
  else:
@@ -174,8 +251,7 @@ def check_excel_content(actual, expected):
174
251
  errors.append("excel内容-预期和实际行数相等,为" + str(actual_num) + "行")
175
252
  else:
176
253
  errors.append(
177
- "excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(actual_num) + "预期: " + str(
178
- expected_num))
254
+ "excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(actual_num) + "预期: " + str(expected_num))
179
255
  # 断言不匹配行
180
256
  if check_row >= 0:
181
257
  num = len(expected)
@@ -189,7 +265,7 @@ def check_excel_content(actual, expected):
189
265
  "excel内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(actual[i]))
190
266
  return False, errors
191
267
  except Exception as e:
192
- print(f"excel内容-服务异常:{e}")
268
+ print(f"excel内容-服务异常{e}")
193
269
  return False, [e]
194
270
 
195
271
 
@@ -203,3 +279,4 @@ def del_temp_file(file_name=""):
203
279
  print(f"文件 {file_path} 不存在。")
204
280
  except Exception as e:
205
281
  print(f"删除文件 {file_path} 时出错:{e}")
282
+
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://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2/2025-01-16/8556e34c8d4d45f0bb2d42dc8871a90b/%E8%A1%A8%E5%8D%95%E4%BB%BB%E5%8A%A1%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
8
- ossurl2 = "https://sl-smartfile.oss-ap-southeast-1.aliyuncs.com/material_ec2/2025-01-16/8556e34c8d4d45f0bb2d42dc8871a90b/%E8%A1%A8%E5%8D%95%E4%BB%BB%E5%8A%A1%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
7
+ ossurl1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-10/4f3c7f2ad92946a894e3df9176341e1c/%E7%94%A8%E6%88%B7%E7%95%99%E5%AD%98.xlsx"
8
+ ossurl2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-10/238f1f143d34441e9cfd61ba68ce8dd1/%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="content", actual_oss=ossurl1, expected_oss=ossurl2))
9
14
 
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_name(actual_oss=ossurl1, expected_oss=ossurl2))
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpush
3
- Version: 1.0.5
3
+ Version: 1.0.7
4
4
  Summary: 用于smartpush自动化测试工具包
5
5
  Author: 卢泽彬、邵宇飞、周彦龙
6
6
 
@@ -0,0 +1,10 @@
1
+ smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
2
+ smartpush/felix_test.py,sha256=CpB1NMDZ4RAtE028XVYfhxTU7RQPSqlWN6ejGO7ww7I,1020
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=T9eDPgNh5zekCAdKFu67aHjQPhKQKzK1BUGtn7UQuh0,12187
6
+ smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
7
+ smartpush-1.0.7.dist-info/METADATA,sha256=yzrYvDW9A0LEV_wFXD39PwOEGo7JjwSf4e-qprMvcVg,145
8
+ smartpush-1.0.7.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
9
+ smartpush-1.0.7.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
10
+ smartpush-1.0.7.dist-info/RECORD,,
@@ -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,,