smartpush 1.0.9__py3-none-any.whl → 1.1.0__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,11 +1,9 @@
1
- import contextlib
2
1
  import os
3
2
  import re
3
+ import warnings
4
4
  from io import BytesIO
5
5
  from urllib.parse import unquote
6
6
  import pandas as pd
7
- import numpy as np
8
- import warnings
9
7
  from requests import request
10
8
 
11
9
  """
@@ -25,6 +23,13 @@ def read_excel_from_oss(url="", method="get"):
25
23
  print(f"读取oss报错 {url} 时出错:{e}")
26
24
 
27
25
 
26
+ def read_excel_data(excel_data, **kwargs):
27
+ with warnings.catch_warnings():
28
+ warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
29
+ dfs = pd.read_excel(excel_data, sheet_name=None, engine="openpyxl", na_filter=False, **kwargs)
30
+ return dfs
31
+
32
+
28
33
  def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
29
34
  """excel内容并写入到内存dict中
30
35
  :param excel_data:excel的io对象, 参数和file_name互斥
@@ -35,19 +40,17 @@ def read_excel_and_write_to_dict(excel_data=None, file_name=None, **kwargs):
35
40
  pass
36
41
  elif file_name is not None:
37
42
  excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
38
- with warnings.catch_warnings():
39
- warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
40
- df = pd.read_excel(excel_data, engine="openpyxl", **kwargs)
43
+ dfs = read_excel_data(excel_data)
41
44
  # 将DataFrame转换为字典,以行为单位存储数据
42
45
  row_dict = {} # 创建一个空字典来存储按行转换的数据
43
- for index, row in df.iterrows(): # 遍历DataFrame中的每一行
46
+ for index, row in dfs.iterrows(): # 遍历DataFrame中的每一行
44
47
  row_dict[index] = row.to_dict() # 将每一行转换为字典并存储在row_dict中
45
48
  return row_dict
46
49
  except Exception as e:
47
50
  print(f"excel写入dict时出错:{e}")
48
51
 
49
52
 
50
- def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
53
+ def read_excel_and_write_to_list(excel_data=None, sheet_name=None, file_name=None, **kwargs):
51
54
  """excel内容并写入到内存list中
52
55
  :param excel_data:excel的io对象, 参数和file_name互斥
53
56
  :file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
@@ -78,6 +81,7 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
78
81
  storage_options:存储选项。
79
82
  dtype_backend:数据类型后端。
80
83
  engine_kwargs:传递给引擎的额外参数。
84
+ @param sheet_name:
81
85
 
82
86
 
83
87
  """
@@ -87,11 +91,13 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None, **kwargs):
87
91
  elif file_name is not None:
88
92
  excel_data = os.path.join(os.path.dirname(os.getcwd()) + "/check_file/" + file_name)
89
93
 
90
- with warnings.catch_warnings():
91
- warnings.filterwarnings("ignore", category=UserWarning, module=re.escape('openpyxl.styles.stylesheet'))
92
- df = pd.read_excel(excel_data, engine="openpyxl", na_filter=False, **kwargs)
93
- # 将DataFrame转换为字典,以行为单位存储数据
94
- rows_list = df.values.tolist()
94
+ dfs = read_excel_data(excel_data)
95
+ rows_list = []
96
+ # 多sheet处理
97
+ for name, df in dfs.items():
98
+ rows_list.append(df.values.tolist())
99
+ if len(dfs) <= 1:
100
+ rows_list = rows_list[0]
95
101
  return rows_list
96
102
  except Exception as e:
97
103
  print(f"excel写入list时出错:{e}")
@@ -108,23 +114,35 @@ def read_excel_and_write_to_csv(excel_data, file_name, **kwargs):
108
114
  print(f"excel写入csv时出错:{e}")
109
115
 
110
116
 
111
- def read_excel_data_to_oss_link(oss, sheet_name=None, **kwargs) -> dict:
117
+ def read_excel_data_for_oss_write_to_dict(oss, **kwargs) -> dict:
112
118
  """
113
119
  1、根据oss link 直接读出 dict-list
114
- 2、支持多sheet,默认heet_name =None查全部
120
+ 2、支持多sheet,默认sheet_name =None查全部
115
121
  3、返回dict结构 {'sheet_name':[rows_list]}
116
122
  """
117
123
  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)
124
+ dfs = read_excel_data(read_excel_from_oss(oss))
121
125
  result = {}
122
126
  for sheet_name, df in dfs.items():
123
127
  rows_list = df.values.tolist()
124
128
  result[sheet_name] = rows_list
125
129
  return result
126
130
  except Exception as e:
127
- print(f"excel写入list时出错:{e}")
131
+ print(f"excel生成dict出错:{e}")
132
+
133
+
134
+ def read_excel_header_for_oss_write_to_list(oss) -> list:
135
+ """
136
+ 1、根据oss link 直接读出excel的头列 list
137
+ """
138
+ try:
139
+ dfs = read_excel_data(read_excel_from_oss(oss))
140
+ result = []
141
+ for sheet_name, df in dfs.items():
142
+ result.append(df.keys().values.tolist())
143
+ return result
144
+ except Exception as e:
145
+ print(f"excel生成header-dict出错:{e}")
128
146
 
129
147
 
130
148
  def check_excel(check_type="content", **kwargs):
@@ -169,6 +187,7 @@ comparison_functions = {
169
187
  else check_excel_content(kwargs["actual_oss"], kwargs["expected_oss"]),
170
188
  # excelName
171
189
  "excelName": lambda kwargs: check_excel_name(kwargs["actual_oss"], kwargs["expected_oss"]),
190
+ 'header': lambda kwargs: check_excel_header(kwargs["actual_oss"], kwargs["expected_oss"]),
172
191
  # 全部
173
192
  "all": lambda kwargs: check_excel_all(kwargs["actual_oss"], kwargs["expected_oss"])
174
193
  }
@@ -213,7 +232,8 @@ def check_excel_all(actual_oss, expected_oss):
213
232
  """
214
233
  flag1, content_result = check_excel_content_form_oss(actual_oss, expected_oss)
215
234
  flag2, name_result = check_excel_name(actual_oss, expected_oss)
216
- return flag1 and flag2, {"文件名称": name_result, "导出内容": content_result}
235
+ flag3 = check_sheet_header(actual_oss, expected_oss)
236
+ return all([flag1, flag2, flag3]), {"文件名称": name_result, "导出内容": content_result, "校验结果": [flag1, flag2, flag3]}
217
237
 
218
238
 
219
239
  def check_excel_name(actual_oss, expected_oss):
@@ -251,7 +271,8 @@ def check_excel_content(actual, expected):
251
271
  errors.append("excel内容-预期和实际行数相等,为" + str(actual_num) + "行")
252
272
  else:
253
273
  errors.append(
254
- "excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(actual_num) + "预期: " + str(expected_num))
274
+ "excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(actual_num) + "预期: " + str(
275
+ expected_num))
255
276
  # 断言不匹配行
256
277
  if check_row >= 0:
257
278
  num = len(expected)
@@ -269,6 +290,18 @@ def check_excel_content(actual, expected):
269
290
  return False, [e]
270
291
 
271
292
 
293
+ def check_excel_header(actual_oss, expected_oss):
294
+ """
295
+ 比较两个文档第一列的header是否一致
296
+ @param actual_oss:
297
+ @param expected_oss:
298
+ @return:
299
+ """
300
+ actual, expected = read_excel_data_for_oss_write_to_dict(actual_oss), read_excel_data_for_oss_write_to_dict(
301
+ expected_oss)
302
+ return actual == expected
303
+
304
+
272
305
  def del_temp_file(file_name=""):
273
306
  """删除temp下临时文件"""
274
307
  file_path = os.path.join(os.path.dirname(os.getcwd()) + "/temp_file/" + file_name)
@@ -278,5 +311,4 @@ def del_temp_file(file_name=""):
278
311
  except FileNotFoundError:
279
312
  print(f"文件 {file_path} 不存在。")
280
313
  except Exception as e:
281
- print(f"删除文件 {file_path} 时出错:{e}")
282
-
314
+ print(f"删除文件 {file_path} 时出错:{e}")
smartpush/test.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from smartpush.export.basic.ExcelExportChecker import check_excel_for_lu
2
2
  from smartpush.export.basic.GetOssUrl import get_oss_address_with_retry
3
+ import urllib3
3
4
 
4
5
  if __name__ == '__main__':
5
6
  # 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"))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpush
3
- Version: 1.0.9
3
+ Version: 1.1.0
4
4
  Summary: 用于smartpush自动化测试工具包
5
5
  Author: 卢泽彬、邵宇飞、周彦龙
6
6
 
@@ -1,13 +1,13 @@
1
1
  smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
2
2
  smartpush/get_jira_info.py,sha256=dmCwkKa94xwyE2hegE1KBI3cV_LbrJ67P9osORUGPt4,2633
3
- smartpush/test.py,sha256=GR8R4qMkXgpp884X9RDV04N2TBGavyXQQe8PBitD1jE,2822
3
+ smartpush/test.py,sha256=Krng-vkKECW7UPYKwlgh-w0o0xDYrVkXW7W4-L61ueA,2837
4
4
  smartpush/export/__init__.py,sha256=D9GbWcmwnetEndFDty5XbVienFK1WjqV2yYcQp3CM84,99
5
- smartpush/export/basic/ExcelExportChecker.py,sha256=2EMa_KWErJ18un0YPKa9InHyKJ5cIUCnYyCpAjqVqss,12189
5
+ smartpush/export/basic/ExcelExportChecker.py,sha256=bEfadFHZ0tsPcFXbCLTZguD199PIoYdxhJ9Mce72N7M,12987
6
6
  smartpush/export/basic/GetOssUrl.py,sha256=O2-HtcYzbabck9dKgLu8ga21_AiyDIzgdfoDgvqBY3c,1541
7
7
  smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
8
8
  smartpush/utils/StringUtils.py,sha256=NXomJ4qmyBRAFnGj5hrFRWwQnRQMTcPzy20fk1dunSw,3980
9
9
  smartpush/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- smartpush-1.0.9.dist-info/METADATA,sha256=y3_SkqSb2-fPTteG2RZUOBURVjr3W-higEFBqhVJ5io,145
11
- smartpush-1.0.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
- smartpush-1.0.9.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
13
- smartpush-1.0.9.dist-info/RECORD,,
10
+ smartpush-1.1.0.dist-info/METADATA,sha256=LQEsjc2Kv6vo7urDwIaOi-Idf7_a0jBSmAqaS6kSPhk,145
11
+ smartpush-1.1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
12
+ smartpush-1.1.0.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
13
+ smartpush-1.1.0.dist-info/RECORD,,