smartpush 1.1.7__py3-none-any.whl → 1.1.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.
@@ -1,7 +1,6 @@
1
1
  import copy
2
2
  import json
3
3
  from urllib.parse import unquote
4
-
5
4
  from smartpush.export.basic.ReadExcel import *
6
5
 
7
6
  """
@@ -104,9 +103,10 @@ def check_excel_content_form_list(actual, expected):
104
103
  return check_excel_content(actual=actual, expected=expected)
105
104
 
106
105
 
107
- def check_excel_all(actual_oss, expected_oss,**kwargs):
106
+ def check_excel_all(actual_oss, expected_oss, **kwargs):
108
107
  """
109
108
  校验所有内容
109
+ **kwargs: skiprows->int 用于跳过读取行数,如果第一行是动态变化的,建议单独过滤,第一行传1
110
110
  """
111
111
  file_type = check_and_get_file_suffix_name(actual_oss, expected_oss)
112
112
  actual, expected = read_excel_from_oss(actual_oss), read_excel_from_oss(expected_oss)
@@ -115,7 +115,7 @@ def check_excel_all(actual_oss, expected_oss,**kwargs):
115
115
 
116
116
  flag1, name_result = check_excel_name(actual_oss, expected_oss)
117
117
  flag2, content_result = check_excel_content_form_dict(actual, expected, type=file_type, **kwargs)
118
- flag3, header_result = check_excel_header(actual_data_copy,expected_data_copy, type=file_type)
118
+ flag3, header_result = check_excel_header(actual_data_copy, expected_data_copy, type=file_type, **kwargs)
119
119
  print(json.dumps(
120
120
  {f"文件名称-{flag1}": name_result, f"导出内容-{flag2}": content_result, f"表头校验-{flag3}": header_result},
121
121
  ensure_ascii=False))
@@ -173,17 +173,31 @@ def check_excel_content(actual, expected):
173
173
  # 断言2:对比具体行
174
174
  if isinstance(actual, list) and isinstance(expected, list):
175
175
  # 第一层提取sheet
176
- for i in range(min(len(expected), len(actual))):
177
- if actual[i] == expected[i]:
176
+ for i in range(max(len(expected), len(actual))):
177
+ if len(expected) <= i:
178
+ errors.append(f"预期结果不存在第{i + 1}个sheet")
179
+ continue
180
+ elif len(actual) <= i:
181
+ errors.append(f"预期结果不存在第{i + 1}个sheet")
178
182
  continue
179
183
  else:
180
- for row in range(min(len(expected[i]), len(actual[i]))):
181
- if actual[i][row] == expected[i][row]:
182
- continue
183
- else:
184
- errors.append(
185
- f"{i+1}个sheet的内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(
186
- actual[i]))
184
+ if actual[i] == expected[i]:
185
+ continue
186
+ else:
187
+ for row in range(max(len(expected[i]), len(actual[i]))):
188
+ if len(expected[i]) <= row:
189
+ errors.append(f"预期结果不存在第{row + 1}个行")
190
+ continue
191
+ elif len(actual[i]) <= row:
192
+ errors.append(f"实际内容不存在第{row + 1}个行")
193
+ continue
194
+ else:
195
+ if actual[i][row] == expected[i][row]:
196
+ continue
197
+ else:
198
+ errors.append(
199
+ f"第{i+1}个sheet的内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(
200
+ actual[i]))
187
201
  return False, errors
188
202
  else:
189
203
  return False, compare_dicts(actual, expected)
@@ -201,17 +215,20 @@ def check_excel_header(actual, expected, **kwargs):
201
215
  @return:
202
216
  """
203
217
  try:
204
- if all([isinstance(actual, str), isinstance(expected, str)]):
205
- actual1, expected1 = read_excel_header(read_excel_from_oss(actual), **kwargs), read_excel_header(
206
- read_excel_from_oss(
207
- expected), **kwargs)
208
- else:
209
- actual1, expected1 = read_excel_header(actual, **kwargs), read_excel_header(expected, **kwargs)
218
+ # if all([isinstance(actual, str), isinstance(expected, str)]):
219
+ # actual1, expected1 = read_excel_header(read_excel_from_oss(actual), **kwargs), read_excel_header(
220
+ # read_excel_from_oss(
221
+ # expected), **kwargs)
222
+ # else:
223
+ actual1, expected1 = read_excel_header(actual, return_type='dict', **kwargs), read_excel_header(expected,
224
+ return_type='dict',
225
+ **kwargs)
210
226
  try:
211
- assert actual1 == expected1
227
+ result = check_excel_content(actual1, expected1)
228
+ assert result[0]
212
229
  return True, "表头校验值与顺序一致"
213
230
  except Exception as e:
214
- return False, f"表头校验值与顺序失败 {e}"
231
+ return False, f"表头校验值与顺序失败 {result[1]}"
215
232
  except Exception as e:
216
233
  return False, f"表头校验异常 {e}"
217
234
 
@@ -1,9 +1,8 @@
1
- # from retry import retry
2
1
  import json
2
+ import urllib
3
3
 
4
4
  import requests
5
- from tenacity import retry, stop_after_attempt, wait_fixed,RetryError
6
-
5
+ from tenacity import retry, stop_after_attempt, wait_fixed, RetryError
7
6
  from smartpush.utils.StringUtils import StringUtils
8
7
 
9
8
 
@@ -29,7 +28,6 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
29
28
  tries = kwargs.get('tries', 20) # 重试次数
30
29
  delay = kwargs.get('delay', 2)
31
30
 
32
-
33
31
  @retry(stop=stop_after_attempt(tries), wait=wait_fixed(delay), after=log_attempt)
34
32
  def get_oss_address():
35
33
  _url = url + '/bulkOps/query'
@@ -45,8 +43,9 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
45
43
  id_url_dict = {item["id"]: item["url"] for item in result["resultData"]["datas"]}
46
44
  if target_id in id_url_dict:
47
45
  if len(id_url_dict[target_id]) == 1:
48
- print(f"{target_id} oss链接为:{id_url_dict[target_id][0]}")
49
- return id_url_dict[target_id][0]
46
+ target_url = urllib.parse.unquote(id_url_dict[target_id][0])
47
+ print(f"target_id [{target_id}] 的oss链接为: {target_url}")
48
+ return target_url
50
49
  else:
51
50
  raise ValueError(f"存在多条 id 为 {target_id} 的记录,记录为:{id_url_dict[target_id]}")
52
51
  else:
@@ -23,19 +23,30 @@ def read_excel_from_oss(url="", method="get"):
23
23
  print(f"读取oss报错 {url} 时出错:{e}")
24
24
 
25
25
 
26
- def read_excel_header(excel_data, **kwargs) -> list:
26
+ def read_excel_header(excel_data, return_type='list', **kwargs):
27
27
  """
28
28
  1、读出excel的头列 list
29
29
  """
30
30
  try:
31
- dfs = read_excel_csv_data(excel_data, **kwargs)
32
31
  result = []
32
+ result_dict = {}
33
+ skip_rows = kwargs.pop('skiprows', 0) - 1 if 'skiprows' in kwargs else 0
34
+ dfs = read_excel_csv_data(excel_data, **kwargs)
33
35
  if kwargs.get('type', None) in excel_extensions:
34
36
  for sheet_name, df in dfs.items():
35
- result.append(df.keys().values.tolist())
37
+ # result.append(df.keys().values.tolist())
38
+ headers = df.iloc[skip_rows].tolist()
39
+ result.append(headers)
40
+ result_dict[sheet_name] = headers
41
+ if return_type == 'list':
42
+ return result
43
+ else:
44
+ return result_dict
36
45
  else:
37
- result = dfs.keys().values.tolist()
38
- return result
46
+ # csv的头
47
+ # result = dfs.keys().values.tolist()
48
+ result = dfs.columns.tolist()
49
+ return result
39
50
  except Exception as e:
40
51
  print(f"excel生成header-list出错:{e}")
41
52
  raise
@@ -71,7 +82,12 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
71
82
  # 将DataFrame转换为字典,以行为单位存储数据
72
83
  row_dict = {} # 创建一个空字典来存储按行转换的数据
73
84
  for sheet_name, row in dfs.items():
74
- row_dict[sheet_name] = row.to_dict(orient='records')
85
+ row = row.to_dict(orient='records')
86
+ if kwargs.get("ignore_sort", False):
87
+ sorted_data_asc = sorted(row[0:], key=lambda x: x[0], reverse=True) # 内部排序
88
+ row_dict[sheet_name] = sorted_data_asc
89
+ else:
90
+ row_dict[sheet_name] = row
75
91
  else:
76
92
  row_dict = dfs.to_dict()
77
93
  return row_dict
smartpush/test.py CHANGED
@@ -1,21 +1,28 @@
1
1
  # -*- codeing = utf-8 -*-
2
2
  # @Time :2025/2/20 00:27
3
3
  # @Author :luzebin
4
- from smartpush.export.basic.ExcelExportChecker import *
5
- from smartpush.export.basic.ReadExcel import *
4
+ import pandas as pd
5
+
6
+ from smartpush.export.basic.ExcelExportChecker import check_excel_all, read_excel_and_write_to_list, \
7
+ read_excel_from_oss, read_excel_csv_data, check_excel
8
+ from smartpush.export.basic.ReadExcel import read_excel_from_oss
9
+ from smartpush.export.basic.ReadExcel import read_excel_and_write_to_dict
10
+ from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
6
11
 
7
12
  if __name__ == '__main__':
8
13
  oss1 = "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"
9
14
  oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-21/bbe660950493411d88b4a75ed0893ec8/%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"
10
- # print(json.dumps(read_excel_and_write_to_dict(read_excel_csv_data(read_excel_from_oss(oss1))),ensure_ascii=False))
11
-
12
- # print((oss1, oss1))
15
+ # # print(check_excel_all(oss1, oss1))
16
+ # oss3 = "https://cdn.smartpushedm.com/material_ec2/2025-02-25/58c4a3a885884741b22380c360ac2894/【自动化导出】营销活动URL点击与热图.xlsx"
17
+ # oss4 = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/58cee630b4c84eec9572b867af4ce692/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8URL%E7%82%B9%E5%87%BB%E4%B8%8E%E7%83%AD%E5%9B%BE.xlsx"
18
+ expected_oss ="https://cdn.smartpushedm.com/material_ec2/2025-02-26/757df7e77ce544e193257c0da35a4983/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
19
+ actual_oss = "https://cdn.smartpushedm.com/material_ec2/2025-02-26/757df7e77ce544e193257c0da35a4983/%E3%80%90%E8%87%AA%E5%8A%A8%E5%8C%96%E5%AF%BC%E5%87%BA%E3%80%91%E8%90%A5%E9%94%80%E6%B4%BB%E5%8A%A8%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
20
+ # # #actual_oss= get_oss_address_with_retry("23161","https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx","",'{"page":1,"pageSize":10,"type":null,"status":null,"startTime":null,"endTime":null}')
21
+ # # res=read_excel_and_write_to_dict(read_excel_from_oss(actual_oss))
22
+ # # print(res)
23
+ # # print(read_excel_and_write_to_dict(read_excel_from_oss(oss1), type=".xlsx"))
24
+ print(check_excel(check_type="all", actual_oss=actual_oss, expected_oss=expected_oss))
25
+ # print(check_excel_all(actual_oss=oss1, expected_oss=oss2,skiprows=1))
26
+ # print(check_excel_all(actual_oss=oss1, expected_oss=oss2,ignore_sort =True))
27
+ # read_excel_csv_data(type=)
13
28
 
14
- # expected_oss ="https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
15
- # actual_oss = "https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
16
- # #actual_oss= get_oss_address_with_retry("23161","https://cdn.smartpushedm.com/material_ec2_prod/2025-02-20/dae941ec20964ca5b106407858676f89/%E7%BE%A4%E7%BB%84%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx","",'{"page":1,"pageSize":10,"type":null,"status":null,"startTime":null,"endTime":null}')
17
- # res=read_excel_and_write_to_dict(read_excel_from_oss(actual_oss))
18
- # print(res)
19
- # print(check_excel_all(actual_oss,expected_oss))
20
- print(check_excel("all", actual_oss=oss1, expected_oss=oss2, skiprows=1))
21
- print(check_excel_all(oss2, oss1, skiprows=1))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpush
3
- Version: 1.1.7
3
+ Version: 1.1.9
4
4
  Summary: 用于smartpush自动化测试工具包
5
5
  Author: 卢泽彬、邵宇飞、周彦龙
6
6
 
@@ -0,0 +1,14 @@
1
+ smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
2
+ smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
3
+ smartpush/test.py,sha256=MBz_SJ0cqQiGLJhBMKkyZbXBqp3QQ0KcHMhyThB2Sy0,2669
4
+ smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
5
+ smartpush/export/basic/ExcelExportChecker.py,sha256=Ku-UoBKqTE7VwAWA644DNGUmXmXnnjmY6ifLV4rznUI,13593
6
+ smartpush/export/basic/GetOssUrl.py,sha256=oCbPRGa5SqdPWzzeQ8sG10uZJByhrLAzUtwZi_IZgrg,3062
7
+ smartpush/export/basic/ReadExcel.py,sha256=uE6_Y7i1lzizatt1k8XbgJBVO7Bz1OucaymYfu6pQ6s,6319
8
+ smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
9
+ smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
10
+ smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ smartpush-1.1.9.dist-info/METADATA,sha256=xfanHJ-TadMM-ClWyRgjcf2YX28oX4-vXDywuCWKvD4,145
12
+ smartpush-1.1.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
13
+ smartpush-1.1.9.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
14
+ smartpush-1.1.9.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
2
- smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
3
- smartpush/test.py,sha256=epaCOwDSLN1Z4tsGTGyo5SOUAdTzaaHfdxnDskXPZS0,1733
4
- smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
5
- smartpush/export/basic/ExcelExportChecker.py,sha256=YOHMbWGg0OcnpwX-cenkERxyQtEU_BG_MlfXV-yFSKA,12304
6
- smartpush/export/basic/GetOssUrl.py,sha256=UfY4q1m_aRfQLKN8vsA3mgY7khDi2xOomE5UvzipAAs,3008
7
- smartpush/export/basic/ReadExcel.py,sha256=55LUWiq1mk135uBKt_iBmrAEG01DTVEH4zMu_bfgE7M,5595
8
- smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
9
- smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
10
- smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- smartpush-1.1.7.dist-info/METADATA,sha256=bBANzyGNE_7isatlIgW8oI6zYw4_R0lMGiS7yFHBUqQ,145
12
- smartpush-1.1.7.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
13
- smartpush-1.1.7.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
14
- smartpush-1.1.7.dist-info/RECORD,,