smartpush 1.0.4__py3-none-any.whl → 1.0.5__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 +91 -10
- smartpush/felix_test.py +6 -4
- {smartpush-1.0.4.dist-info → smartpush-1.0.5.dist-info}/METADATA +1 -1
- smartpush-1.0.5.dist-info/RECORD +10 -0
- smartpush-1.0.4.dist-info/RECORD +0 -10
- {smartpush-1.0.4.dist-info → smartpush-1.0.5.dist-info}/WHEEL +0 -0
- {smartpush-1.0.4.dist-info → smartpush-1.0.5.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,9 @@
|
|
1
|
+
import contextlib
|
1
2
|
import os
|
2
3
|
import re
|
3
4
|
from io import BytesIO
|
5
|
+
from urllib.parse import unquote
|
6
|
+
|
4
7
|
import pandas as pd
|
5
8
|
import numpy as np
|
6
9
|
import warnings
|
@@ -10,7 +13,8 @@ from requests import request
|
|
10
13
|
"""
|
11
14
|
warnings.simplefilter("ignore")
|
12
15
|
|
13
|
-
|
16
|
+
|
17
|
+
def read_excel_from_oss(url="", method="get"):
|
14
18
|
"""读取oss的excel内容并写入到本地csv"""
|
15
19
|
try:
|
16
20
|
result = request(method=method, url=url)
|
@@ -47,6 +51,35 @@ def read_excel_and_write_to_list(excel_data=None, file_name=None):
|
|
47
51
|
"""excel内容并写入到内存list中
|
48
52
|
:param excel_data:excel的io对象, 参数和file_name互斥
|
49
53
|
:file_name: excel文件名称,目前读取check_file目录下文件,参数和excel_data互斥
|
54
|
+
|
55
|
+
io:可以是文件路径、文件对象或 ExcelFile 对象,代表要读取的 Excel 文件。
|
56
|
+
sheet_name:指定要读取的工作表,默认为第一个工作表(索引为 0)。
|
57
|
+
header:指定哪一行作为列名,默认为第一行(索引为 0)。
|
58
|
+
names:可以为列提供自定义名称,如果设置了这个,会覆盖文件中的列名。
|
59
|
+
index_col:可以指定某一列或多列作为索引。
|
60
|
+
usecols:可以指定要读取的列,可以是列的索引、列名或一个筛选函数。
|
61
|
+
dtype:可以指定数据类型,控制数据的类型转换。
|
62
|
+
engine:指定使用的 Excel 引擎,比如 xlrd、openpyxl 等。
|
63
|
+
converters:可以为不同的列指定自定义的转换函数,以字典形式存储。
|
64
|
+
true_values 和 false_values:定义哪些值会被视为 True 或 False。
|
65
|
+
skiprows:可以指定要跳过的行,可以是一个整数序列、一个整数或一个函数。
|
66
|
+
nrows:可以指定要读取的行数。
|
67
|
+
na_values:可以指定哪些值会被视为 NaN。
|
68
|
+
keep_default_na:决定是否使用默认的 NaN 值。
|
69
|
+
na_filter:决定是否过滤 NaN 值。
|
70
|
+
verbose:决定是否输出详细信息。
|
71
|
+
parse_dates:决定是否解析日期,可以是一个列表、字典或布尔值。
|
72
|
+
date_parser:自定义的日期解析函数。
|
73
|
+
date_format:日期的格式设置。
|
74
|
+
thousands:千位分隔符。
|
75
|
+
decimal:小数点分隔符。
|
76
|
+
comment:注释字符,以该字符开头的行将被跳过。
|
77
|
+
skipfooter:指定要跳过的文件末尾的行数。
|
78
|
+
storage_options:存储选项。
|
79
|
+
dtype_backend:数据类型后端。
|
80
|
+
engine_kwargs:传递给引擎的额外参数。
|
81
|
+
|
82
|
+
|
50
83
|
"""
|
51
84
|
try:
|
52
85
|
if excel_data is not None and file_name is not None:
|
@@ -75,14 +108,62 @@ def read_excel_and_write_to_csv(excel_data, file_name):
|
|
75
108
|
print(f"excel写入csv时出错:{e}")
|
76
109
|
|
77
110
|
|
78
|
-
def check_excel(
|
79
|
-
"""
|
80
|
-
:param:
|
81
|
-
|
111
|
+
def check_excel(check_type="content", **kwargs):
|
112
|
+
"""对比excel
|
113
|
+
:param: type: 需要对比类型,
|
114
|
+
枚举:content:对比两表格内容
|
115
|
+
方式1:传参actual_oss和expected_oss,参数类型str,url
|
116
|
+
放松1:传参actual和expected,参数类型list or dict
|
117
|
+
excelName: 对比两表格文件名称
|
118
|
+
all: 对比所有内容
|
82
119
|
"""
|
120
|
+
try:
|
121
|
+
if check_type == "content":
|
122
|
+
if "actual" in kwargs.keys() and "expected" in kwargs.keys():
|
123
|
+
return check_excel_content(actual=kwargs["actual"], expected=kwargs["expected"])
|
124
|
+
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
|
+
)
|
128
|
+
elif check_type == "excelName":
|
129
|
+
return check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
130
|
+
elif check_type == "all":
|
131
|
+
actual_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["actual_oss"]))
|
132
|
+
expected_content = read_excel_and_write_to_list(excel_data=read_excel_from_oss(url=kwargs["expected_oss"]))
|
133
|
+
flag1, content_result = check_excel_content(actual=actual_content, expected=expected_content)
|
134
|
+
flag2, name_result = check_excel_name(actual_oss=kwargs["actual_oss"], expected_oss=kwargs["expected_oss"])
|
135
|
+
return flag1 and flag2, {"文件名称": name_result, "导出内容": content_result}
|
136
|
+
else:
|
137
|
+
return False, f"不支持此类型: {check_type}"
|
138
|
+
except Exception as e:
|
139
|
+
print(f"对比excel异常:{e}")
|
140
|
+
return False, [e]
|
141
|
+
|
142
|
+
|
143
|
+
def check_excel_name(actual_oss, expected_oss):
|
144
|
+
"""校验excel文件名称
|
145
|
+
:param actual_oss:实际oss链接
|
146
|
+
:param actual_oss:预期oss链接
|
147
|
+
"""
|
148
|
+
try:
|
149
|
+
actual_name = unquote(actual_oss.split("/")[-1])
|
150
|
+
expected_name = unquote(expected_oss.split("/")[-1])
|
151
|
+
if actual_name == expected_name:
|
152
|
+
return True, "excel文件名称-匹配"
|
153
|
+
else:
|
154
|
+
return False, f"excel文件名称-不匹配, 实际: {actual_name}, 预期: {expected_name}"
|
155
|
+
except BaseException as msg:
|
156
|
+
return False, f"excel文件名称-服务异常: {msg}"
|
157
|
+
|
158
|
+
|
159
|
+
def check_excel_content(actual, expected):
|
160
|
+
"""校验excel内容
|
161
|
+
:param actual: 实际内容,list或dict类型
|
162
|
+
:param expected:预期内容:list或dict类型
|
163
|
+
"""
|
83
164
|
try:
|
84
165
|
if actual == expected:
|
85
|
-
return True, ["
|
166
|
+
return True, ["excel内容-完全匹配"]
|
86
167
|
else:
|
87
168
|
errors = []
|
88
169
|
# 断言1:校验行数
|
@@ -90,10 +171,10 @@ def check_excel(actual, expected):
|
|
90
171
|
expected_num = len(expected)
|
91
172
|
check_row = actual_num - expected_num
|
92
173
|
if check_row == 0:
|
93
|
-
errors.append("
|
174
|
+
errors.append("excel内容-预期和实际行数相等,为" + str(actual_num) + "行")
|
94
175
|
else:
|
95
176
|
errors.append(
|
96
|
-
"
|
177
|
+
"excel内容-行数和预期对比差" + check_row.__str__() + "行" + ", 实际:" + str(actual_num) + "预期: " + str(
|
97
178
|
expected_num))
|
98
179
|
# 断言不匹配行
|
99
180
|
if check_row >= 0:
|
@@ -105,10 +186,10 @@ def check_excel(actual, expected):
|
|
105
186
|
continue
|
106
187
|
else:
|
107
188
|
errors.append(
|
108
|
-
"
|
189
|
+
"excel内容-第" + str(i + 1) + "行不匹配,预期为:" + str(expected[i]) + ", 实际为: " + str(actual[i]))
|
109
190
|
return False, errors
|
110
191
|
except Exception as e:
|
111
|
-
print(f"
|
192
|
+
print(f"excel内容-服务异常:{e}")
|
112
193
|
return False, [e]
|
113
194
|
|
114
195
|
|
smartpush/felix_test.py
CHANGED
@@ -4,8 +4,10 @@ from smartpush.export.basic import ExcelExportChecker
|
|
4
4
|
|
5
5
|
if __name__ == '__main__':
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
excelList = ExcelExportChecker.read_excel_and_write_to_list(excel_data=excelOss)
|
10
|
-
print(excelList)
|
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"
|
11
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_name(actual_oss=ossurl1, expected_oss=ossurl2))
|
@@ -0,0 +1,10 @@
|
|
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,,
|
smartpush-1.0.4.dist-info/RECORD
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
smartpush/__init__.py,sha256=XJrl1vhGATHSeSVqKmPXxYqxyseriUpvY5tLIXir3EE,24
|
2
|
-
smartpush/felix_test.py,sha256=I7DkMnqRUa48ALyawoJtPh74zRR86OO3oRnkBi9qJRQ,476
|
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=C1piYqeZI-YGWqN3FsYYmVL0JF_y6xxajkHGBf8i-iA,4825
|
6
|
-
smartpush/export/basic/__init__.py,sha256=6tcrS-2NSlsJo-UwEsnGUmwCf7jgOsh_UEbM0FD-gYE,70
|
7
|
-
smartpush-1.0.4.dist-info/METADATA,sha256=wYH3eiXClYapcPf0HFIiY75Lt3rikG9xXeassEdqGJ0,145
|
8
|
-
smartpush-1.0.4.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
9
|
-
smartpush-1.0.4.dist-info/top_level.txt,sha256=5_CXqu08EfbPaKLjuSAOAqCmGU6shiatwDU_ViBGCmg,10
|
10
|
-
smartpush-1.0.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|