smartpush 1.1.6__py3-none-any.whl → 1.1.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.
@@ -104,19 +104,22 @@ def check_excel_content_form_list(actual, expected):
104
104
  return check_excel_content(actual=actual, expected=expected)
105
105
 
106
106
 
107
- def check_excel_all(actual_oss, expected_oss):
107
+ def check_excel_all(actual_oss, expected_oss,**kwargs):
108
108
  """
109
109
  校验所有内容
110
110
  """
111
- file_type = check_and_get_file_suffix_name(expected_oss, actual_oss)
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)
113
113
  actual_data_copy = copy.deepcopy(actual)
114
114
  expected_data_copy = copy.deepcopy(expected)
115
- flag1, content_result = check_excel_content_form_dict(actual, expected, type=file_type)
116
- flag2, name_result = check_excel_name(actual_oss, expected_oss)
115
+
116
+ flag1, name_result = check_excel_name(actual_oss, expected_oss)
117
+ flag2, content_result = check_excel_content_form_dict(actual, expected, type=file_type, **kwargs)
117
118
  flag3, header_result = check_excel_header(actual_data_copy,expected_data_copy, type=file_type)
118
- return all([flag1, flag2]), json.dumps({f"文件名称-{flag1}": name_result, f"导出内容-{flag2}": content_result,f"表头校验-{flag3}": header_result},
119
- ensure_ascii=False)
119
+ print(json.dumps(
120
+ {f"文件名称-{flag1}": name_result, f"导出内容-{flag2}": content_result, f"表头校验-{flag3}": header_result},
121
+ ensure_ascii=False))
122
+ return all([flag1, flag2, flag3])
120
123
 
121
124
 
122
125
  def check_and_get_file_suffix_name(actual_oss, expected_oss) -> str:
@@ -225,32 +228,62 @@ def del_temp_file(file_name=""):
225
228
  print(f"删除文件 {file_path} 时出错:{e}")
226
229
 
227
230
 
228
- def compare_dicts(dict1, dict2):
231
+ def compare_dicts(actual_dict, expected_dict):
229
232
  diff = {}
230
233
  # 找出只在 dict1 中存在的键
231
- only_in_dict1 = set(dict1.keys()) - set(dict2.keys())
234
+ only_in_dict1 = set(actual_dict.keys()) - set(expected_dict.keys())
232
235
  if only_in_dict1:
233
- diff['only_in_dict1'] = {key: dict1[key] for key in only_in_dict1}
236
+ diff['only_in_dict1'] = {key: actual_dict[key] for key in only_in_dict1}
234
237
  # 找出只在 dict2 中存在的键
235
- only_in_dict2 = set(dict2.keys()) - set(dict1.keys())
238
+ only_in_dict2 = set(expected_dict.keys()) - set(actual_dict.keys())
236
239
  if only_in_dict2:
237
- diff['only_in_dict2'] = {key: dict2[key] for key in only_in_dict2}
240
+ diff['only_in_dict2'] = {key: expected_dict[key] for key in only_in_dict2}
238
241
  # 处理两个字典都有的键
239
- common_keys = set(dict1.keys()) & set(dict2.keys())
242
+ common_keys = set(actual_dict.keys()) & set(expected_dict.keys())
240
243
  for key in common_keys:
241
- value1 = dict1[key]
242
- value2 = dict2[key]
244
+ value1 = actual_dict[key]
245
+ value2 = expected_dict[key]
243
246
  if isinstance(value1, dict) and isinstance(value2, dict):
244
247
  # 如果值是字典,递归比较
245
248
  sub_diff = compare_dicts(value1, value2)
246
249
  if sub_diff:
247
- diff[f'different_sub_dicts_at_{key}'] = sub_diff
250
+ diff[f'不同的字典_at_{key}'] = sub_diff
248
251
  elif isinstance(value1, list) and isinstance(value2, list):
249
- # 如果值是列表,比较列表元素
250
- if value1 != value2:
251
- diff[f'different_lists_at_{key}'] = (value1, value2)
252
+ # 如果值是列表,递归比较列表元素
253
+ list_diff = compare_lists(value1, value2)
254
+ if list_diff:
255
+ diff[f'sheet【{key}】中存在差异'] = list_diff
252
256
  else:
253
257
  # 其他情况,直接比较值
254
258
  if value1 != value2:
255
- diff[f'different_values_at_{key}'] = (value1, value2)
259
+ diff[f'不同的值_at_{key}'] = (value1, value2)
260
+ return diff
261
+
262
+
263
+ def compare_lists(actual_dict_list, expected_dict_list):
264
+ diff = []
265
+ max_len = max(len(actual_dict_list), len(expected_dict_list))
266
+ for i in range(max_len):
267
+ if i >= len(actual_dict_list):
268
+ # list2 更长
269
+ diff.append(('只存在expected_dict_list的中', expected_dict_list[i]))
270
+ elif i >= len(expected_dict_list):
271
+ # list1 更长
272
+ diff.append(('只存在actual_dict_list中', actual_dict_list[i]))
273
+ else:
274
+ item1 = actual_dict_list[i]
275
+ item2 = expected_dict_list[i]
276
+ if isinstance(item1, dict) and isinstance(item2, dict):
277
+ # 如果元素是字典,递归比较
278
+ sub_diff = compare_dicts(item1, item2)
279
+ if sub_diff:
280
+ diff.append(('列表索引中存在不同的字典', i, sub_diff))
281
+ elif isinstance(item1, list) and isinstance(item2, list):
282
+ # 如果元素是列表,递归比较
283
+ sub_list_diff = compare_lists(item1, item2)
284
+ if sub_list_diff:
285
+ diff.append(('列表索引的存在不同的子列表', i, sub_list_diff))
286
+ else:
287
+ if item1 != item2:
288
+ diff.append(('列表索引的不同值', i, (item1, item2)))
256
289
  return diff
@@ -26,7 +26,7 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
26
26
  :param requestHeader:
27
27
  :return: 带有重试配置的获取 OSS 地址的
28
28
  """
29
- tries = kwargs.get('tries', 10) # 重试次数
29
+ tries = kwargs.get('tries', 20) # 重试次数
30
30
  delay = kwargs.get('delay', 2)
31
31
 
32
32
 
@@ -77,21 +77,3 @@ def get_oss_address_with_retry(target_id, url, requestHeader, requestParam, **kw
77
77
  if isinstance(e, RetryError):
78
78
  cancel_export_file(target_id)
79
79
  return None
80
-
81
-
82
- if __name__ == '__main__':
83
- url = "https://test.smartpushedm.com/api-em-ec2"
84
- requestHeader = {
85
- "cookie": "osudb_appid=SMARTPUSH;osudb_oar=#01#SID0000122BBLon+0gwvStide+qtdJAK57ZSK1ty+iW8b7tv/Uwl6Zo4gDfUg6B83n+jgqTVjoZ5qRGyRsuLaXc9woDN2WRh3mu1yn7anglBmaFoemhCy/ttS8nqv/y0kj8khbu6mtBmQrseNfnO/Mir8PQP+S;osudb_subappid=1;osudb_uid=4213785247;ecom_http_token=eyJhbGciOiJIUzI1NiIsIn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hcGktc3UtZWMyIiwiYXBpLWVtLWVjMiIsImZsb3ctcGx1Z2luIl0sImNsaWVudF9pZCI6ImVtYWlsLW1hcmtldCJ9.X2Birt-jiWILAvEjjwknUchil2ys8Y11omeRYgZ3K0I;",
86
- "Content-Type": "application/json"
87
- }
88
- requestParam = {
89
- "page": 1,
90
- "pageSize": 20,
91
- "type": "EXPORT",
92
- "status": None,
93
- "startTime": 1740033265288,
94
- "endTime": 1740044065288
95
- }
96
- id = "2334659"
97
- get_oss_address_with_retry(2334659, url, requestHeader, requestParam)
@@ -2,6 +2,7 @@ import io
2
2
  import os
3
3
  import re
4
4
  import warnings
5
+ import zipfile
5
6
  from io import BytesIO
6
7
  import pandas as pd
7
8
  from requests import request
@@ -27,9 +28,9 @@ def read_excel_header(excel_data, **kwargs) -> list:
27
28
  1、读出excel的头列 list
28
29
  """
29
30
  try:
30
- dfs = read_excel_csv_data(excel_data,**kwargs)
31
+ dfs = read_excel_csv_data(excel_data, **kwargs)
31
32
  result = []
32
- if kwargs['type'] in excel_extensions:
33
+ if kwargs.get('type', None) in excel_extensions:
33
34
  for sheet_name, df in dfs.items():
34
35
  result.append(df.keys().values.tolist())
35
36
  else:
@@ -43,9 +44,11 @@ def read_excel_header(excel_data, **kwargs) -> list:
43
44
  def read_excel_csv_data(excel_data, **kwargs):
44
45
  with warnings.catch_warnings():
45
46
  warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
46
- if kwargs['type'] in excel_extensions:
47
- dfs = pd.read_excel(excel_data, sheet_name=None, na_filter=False, engine="openpyxl") if isinstance(excel_data,
48
- io.BytesIO) \
47
+ if kwargs.get('type', None) in excel_extensions:
48
+ dfs = pd.read_excel(excel_data, sheet_name=None, na_filter=False, engine='openpyxl',
49
+ skiprows=kwargs.get('skiprows', None), header=kwargs.get('header', None)) if isinstance(
50
+ excel_data,
51
+ io.BytesIO) \
49
52
  else excel_data
50
53
  else:
51
54
  dfs = pd.read_csv(excel_data, na_filter=False)
@@ -57,13 +60,14 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
57
60
  :param excel_data:excel的io对象, 参数和file_name互斥
58
61
  :file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
59
62
  """
63
+ dfs = None
60
64
  try:
61
65
  if excel_data is not None and file_name is not None:
62
66
  pass
63
67
  elif file_name is not None:
64
68
  excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
65
69
  dfs = read_excel_csv_data(excel_data, **kwargs)
66
- if kwargs['type'] in excel_extensions:
70
+ if kwargs.get('type', None) in excel_extensions:
67
71
  # 将DataFrame转换为字典,以行为单位存储数据
68
72
  row_dict = {} # 创建一个空字典来存储按行转换的数据
69
73
  for sheet_name, row in dfs.items():
@@ -71,6 +75,9 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
71
75
  else:
72
76
  row_dict = dfs.to_dict()
73
77
  return row_dict
78
+ except zipfile.BadZipFile:
79
+ print(f"文件读取错误,请检查文件是否为无效文件:{dfs}")
80
+ raise
74
81
  except Exception as e:
75
82
  print(f"excel写入dict时出错:{e}")
76
83
 
smartpush/test.py CHANGED
@@ -1,22 +1,21 @@
1
1
  # -*- codeing = utf-8 -*-
2
2
  # @Time :2025/2/20 00:27
3
3
  # @Author :luzebin
4
- from smartpush.export.basic.ExcelExportChecker import check_excel_all,read_excel_and_write_to_list,read_excel_from_oss,read_excel_csv_data,check_excel
5
- from smartpush.export.basic.ReadExcel import read_excel_from_oss
6
- from smartpush.export.basic.ReadExcel import read_excel_and_write_to_dict
7
- from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
4
+ from smartpush.export.basic.ExcelExportChecker import *
5
+ from smartpush.export.basic.ReadExcel import *
8
6
 
9
7
  if __name__ == '__main__':
10
- oss1 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/4d98418295524ab1b52340c2ed2afa4a/AutoTest-%E5%9B%BA%E5%AE%9AB-2025-02-14%20%E5%88%9B%E5%BB%BA%E7%9A%84Email33%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
11
- oss2 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/ddbe9965d83840199e678a66dc414518/%E8%90%A5%E9%94%80%E4%BB%BB%E5%8A%A1%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
12
- oss3 = "https://cdn.smartpushedm.com/material_ec2/2025-02-19/4d98418295524ab1b52340c2ed2afa4a/AutoTest-%E5%9B%BA%E5%AE%9AB-2025-02-14%20%E5%88%9B%E5%BB%BA%E7%9A%84Email33%E6%95%B0%E6%8D%AE%E6%A6%82%E8%A7%88.xlsx"
13
- # print(check_excel_all(oss1, oss1))
8
+ 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
+ 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))
14
13
 
15
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"
16
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"
17
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}')
18
17
  # res=read_excel_and_write_to_dict(read_excel_from_oss(actual_oss))
19
18
  # print(res)
20
- # print(read_excel_and_write_to_dict(read_excel_from_oss(oss1), type=".xlsx"))
21
- print(check_excel(check_type="all", actual_oss=oss1, expected_oss=oss3))
22
- # read_excel_csv_data(type=)
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.6
3
+ Version: 1.1.7
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=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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: bdist_wheel (0.45.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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=Pkk6y3snpYnJBT-O51LVujutuT2RSm-nGu-rtB1H-f4,2035
4
- smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
5
- smartpush/export/basic/ExcelExportChecker.py,sha256=pG6yccw44AIynCOkh_Sv0svLwUMzInMwD-C01qfAtxs,10840
6
- smartpush/export/basic/GetOssUrl.py,sha256=IYt-C-SBY4WU_y8dm9aH3uKj1d7M7sSNtitDrz4EfHU,4932
7
- smartpush/export/basic/ReadExcel.py,sha256=rL1D29VIHhp2-CN79ROsbEdnnGWAjKNOe6SbPlO_5hA,5368
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.6.dist-info/METADATA,sha256=6zoN_MFGdEjUOJFeG3644DSlCHgqO67QaKJN41rVBsc,145
12
- smartpush-1.1.6.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
13
- smartpush-1.1.6.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
14
- smartpush-1.1.6.dist-info/RECORD,,