testsolar-testtool-sdk 0.0.1__tar.gz
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.
- testsolar-testtool-sdk-0.0.1/LICENSE +201 -0
- testsolar-testtool-sdk-0.0.1/PKG-INFO +15 -0
- testsolar-testtool-sdk-0.0.1/README.md +2 -0
- testsolar-testtool-sdk-0.0.1/pyproject.toml +21 -0
- testsolar-testtool-sdk-0.0.1/setup.cfg +4 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/__init__.py +0 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/model/__init__.py +0 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/model/load.py +15 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/model/param.py +12 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/model/test.py +10 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/model/testresult.py +82 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk/reporter.py +91 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk.egg-info/PKG-INFO +15 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk.egg-info/SOURCES.txt +16 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk.egg-info/dependency_links.txt +1 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk.egg-info/requires.txt +3 -0
- testsolar-testtool-sdk-0.0.1/src/testsolar_testtool_sdk.egg-info/top_level.txt +1 -0
- testsolar-testtool-sdk-0.0.1/tests/test_report.py +187 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: testsolar-testtool-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: TestSolar测试工具SDK
|
|
5
|
+
Author-email: asiazhang <asiazhang2002@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pydantic>=2.5.3
|
|
11
|
+
Requires-Dist: loguru>=0.7.2
|
|
12
|
+
Requires-Dist: portalocker>=2.8.2
|
|
13
|
+
|
|
14
|
+
# testtool-sdk-python
|
|
15
|
+
Python TestTool SDK for TestSolara
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "testsolar-testtool-sdk"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "TestSolar测试工具SDK"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "asiazhang", email = "asiazhang2002@gmail.com"},
|
|
7
|
+
]
|
|
8
|
+
dependencies = [
|
|
9
|
+
"pydantic>=2.5.3",
|
|
10
|
+
"loguru>=0.7.2",
|
|
11
|
+
"portalocker>=2.8.2",
|
|
12
|
+
]
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
license = {text = "MIT"}
|
|
16
|
+
[tool.pdm.dev-dependencies]
|
|
17
|
+
dev = [
|
|
18
|
+
"setuptools==67.8.0",
|
|
19
|
+
"pytest-cov>=5.0.0",
|
|
20
|
+
"ruff>=0.3.5",
|
|
21
|
+
]
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from .test import TestCase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LoadError(BaseModel):
|
|
9
|
+
name: str
|
|
10
|
+
message: str
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LoadResult(BaseModel):
|
|
14
|
+
tests: List[TestCase] = Field(alias="Tests")
|
|
15
|
+
load_errors: List[LoadError] = Field(alias="LoadErrors")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class EntryParam(BaseModel):
|
|
7
|
+
context: Dict[str, str] = Field(alias="Context")
|
|
8
|
+
task_id: str = Field(alias="TaskId")
|
|
9
|
+
project_path: str = Field(alias="ProjectPath")
|
|
10
|
+
test_selectors: List[str] = Field(alias="TestSelectors")
|
|
11
|
+
collectors: List[str] = Field(alias="Collectors")
|
|
12
|
+
fileReportPath: str = Field(alias="FileReportPath")
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import List, Optional
|
|
3
|
+
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
|
+
|
|
6
|
+
from .test import TestCase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ResultType(str, Enum):
|
|
10
|
+
UNKNOWN = "UNKNOWN"
|
|
11
|
+
SUCCEED = "SUCCEED"
|
|
12
|
+
FAILED = "FAILED"
|
|
13
|
+
LOAD_FAILED = "LOAD_FAILED"
|
|
14
|
+
IGNORED = "IGNORED"
|
|
15
|
+
RUNNING = "RUNNING"
|
|
16
|
+
WAITING = "WAITING"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class LogLevel(str, Enum):
|
|
20
|
+
TRACE = "VERBOSE"
|
|
21
|
+
DEBUG = "DEBUG"
|
|
22
|
+
INFO = "INFO"
|
|
23
|
+
WARN = "WARNNING"
|
|
24
|
+
ERROR = "ERROR"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AttachmentType(str, Enum):
|
|
28
|
+
FILE = "FILE"
|
|
29
|
+
URL = "URL"
|
|
30
|
+
IFRAME = "IFRAME"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class TestCaseAssertError(BaseModel):
|
|
34
|
+
__test__ = False
|
|
35
|
+
|
|
36
|
+
expect: str = Field(alias="Expect")
|
|
37
|
+
actual: str = Field(alias="Actual")
|
|
38
|
+
message: str = Field(alias="Message")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class TestCaseRuntimeError(BaseModel):
|
|
42
|
+
__test__ = False
|
|
43
|
+
|
|
44
|
+
summary: str = Field(alias="Summary")
|
|
45
|
+
detail: str = Field(alias="Detail")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Attachment(BaseModel):
|
|
49
|
+
name: str = Field(alias="Name")
|
|
50
|
+
url: str = Field(alias="Url")
|
|
51
|
+
type: AttachmentType = Field(alias="AttachmentType")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class TestCaseLog(BaseModel):
|
|
55
|
+
__test__ = False
|
|
56
|
+
|
|
57
|
+
time: str = Field(alias="Time")
|
|
58
|
+
level: LogLevel = Field(alias="Level")
|
|
59
|
+
content: str = Field(alias="Content")
|
|
60
|
+
attachments: List[Attachment] = Field(alias="Attachments")
|
|
61
|
+
assert_error: TestCaseAssertError = Field(alias="AssertError")
|
|
62
|
+
runtime_error: Optional[TestCaseRuntimeError] = Field(None, alias="RuntimeError")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class TestCaseStep(BaseModel):
|
|
66
|
+
__test__ = False
|
|
67
|
+
|
|
68
|
+
start_time: str = Field(alias="StartTime")
|
|
69
|
+
end_time: Optional[str] = Field(alias="EndTime")
|
|
70
|
+
title: str = Field(alias="Title")
|
|
71
|
+
logs: List[TestCaseLog] = Field(alias="Logs")
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class TestResult(BaseModel):
|
|
75
|
+
__test__ = False
|
|
76
|
+
|
|
77
|
+
test: TestCase = Field(alias="Test")
|
|
78
|
+
start_time: str = Field(alias="StartTime")
|
|
79
|
+
end_time: Optional[str] = Field(alias="EndTime")
|
|
80
|
+
result_type: ResultType = Field(alias="ResultType")
|
|
81
|
+
message: str = Field(alias="Message")
|
|
82
|
+
steps: List[TestCaseStep] = Field(alias="Steps")
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import os
|
|
3
|
+
import struct
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Optional, BinaryIO
|
|
6
|
+
|
|
7
|
+
import portalocker
|
|
8
|
+
from loguru import logger
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
|
|
11
|
+
from .model.load import LoadResult
|
|
12
|
+
from .model.testresult import TestResult
|
|
13
|
+
|
|
14
|
+
# 跟TestSolar uniSDK约定的管道上报魔数,避免乱序导致后续数据全部无法上报
|
|
15
|
+
MAGIC_NUMBER = 0x1234ABCD
|
|
16
|
+
|
|
17
|
+
# 跟TestSolar uniSDK约定的管道上报文件描述符号
|
|
18
|
+
PIPE_WRITER = 3
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ReportType(str, Enum):
|
|
22
|
+
Pipeline = 'pipeline'
|
|
23
|
+
File = 'file'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Reporter:
|
|
27
|
+
def __init__(self, reporter_type: ReportType, pipe_io: Optional[BinaryIO] = None, report_path: str = '') -> None:
|
|
28
|
+
"""
|
|
29
|
+
初始化报告工具类
|
|
30
|
+
:param reporter_type: 报告类型,支持管道类型和文件类型
|
|
31
|
+
:param pipe_io: 可选的管道,用于测试
|
|
32
|
+
:param report_path: 上报文件路径
|
|
33
|
+
"""
|
|
34
|
+
self.lock_file = "/tmp/testsolar_reporter.lock"
|
|
35
|
+
self.reporter_type = reporter_type
|
|
36
|
+
if reporter_type == ReportType.Pipeline:
|
|
37
|
+
if pipe_io:
|
|
38
|
+
self.pipe_io = pipe_io
|
|
39
|
+
else:
|
|
40
|
+
self.pipe_io = os.fdopen(PIPE_WRITER, "wb")
|
|
41
|
+
elif reporter_type == ReportType.File:
|
|
42
|
+
if not report_path:
|
|
43
|
+
raise RuntimeError('report_path is required')
|
|
44
|
+
self.report_path = report_path
|
|
45
|
+
|
|
46
|
+
def report_load_result(self, load_result: LoadResult) -> None:
|
|
47
|
+
if self.reporter_type == ReportType.Pipeline:
|
|
48
|
+
with portalocker.Lock(self.lock_file, timeout=60):
|
|
49
|
+
self._send_json(load_result)
|
|
50
|
+
elif self.reporter_type == ReportType.File:
|
|
51
|
+
self._write_load_file(load_result)
|
|
52
|
+
|
|
53
|
+
def report_run_case_result(self, run_case_result: TestResult) -> None:
|
|
54
|
+
if self.reporter_type == ReportType.Pipeline:
|
|
55
|
+
with portalocker.Lock(self.lock_file, timeout=60):
|
|
56
|
+
self._send_json(run_case_result)
|
|
57
|
+
elif self.reporter_type == ReportType.File:
|
|
58
|
+
self._write_case_result(run_case_result)
|
|
59
|
+
|
|
60
|
+
def close(self) -> None:
|
|
61
|
+
if self.pipe_io:
|
|
62
|
+
self.pipe_io.close()
|
|
63
|
+
|
|
64
|
+
def _send_json(self, result: BaseModel) -> None:
|
|
65
|
+
data = result.model_dump_json(by_alias=True).encode("utf-8")
|
|
66
|
+
length = len(data)
|
|
67
|
+
|
|
68
|
+
# 将魔数写入管道
|
|
69
|
+
self.pipe_io.write(struct.pack("<I", MAGIC_NUMBER))
|
|
70
|
+
|
|
71
|
+
# 将 JSON 数据的长度写入管道
|
|
72
|
+
self.pipe_io.write(struct.pack("<I", length))
|
|
73
|
+
|
|
74
|
+
# 将 JSON 数据本身写入管道
|
|
75
|
+
self.pipe_io.write(data)
|
|
76
|
+
|
|
77
|
+
logger.debug(f"Sending {length} bytes to pipe {PIPE_WRITER}")
|
|
78
|
+
|
|
79
|
+
self.pipe_io.flush()
|
|
80
|
+
|
|
81
|
+
def _write_load_file(self, load_result: LoadResult) -> None:
|
|
82
|
+
with open(os.path.join(self.report_path, 'result.json'), "wb") as f:
|
|
83
|
+
logger.debug(f"Writing load results to {self.report_path}")
|
|
84
|
+
f.write(load_result.model_dump_json(by_alias=True, indent=2).encode('utf-8'))
|
|
85
|
+
|
|
86
|
+
def _write_case_result(self, case_result: TestResult) -> None:
|
|
87
|
+
retry_id = case_result.test.attrs.get('retry', '0')
|
|
88
|
+
filename = hashlib.md5(f"{case_result.test.name}.{retry_id}".encode('utf-8')).hexdigest() + ".json"
|
|
89
|
+
with open(os.path.join(self.report_path, filename), "wb") as f:
|
|
90
|
+
logger.debug(f"Writing case results to {self.report_path}")
|
|
91
|
+
f.write(case_result.model_dump_json(by_alias=True, indent=2).encode('utf-8'))
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: testsolar-testtool-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: TestSolar测试工具SDK
|
|
5
|
+
Author-email: asiazhang <asiazhang2002@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: pydantic>=2.5.3
|
|
11
|
+
Requires-Dist: loguru>=0.7.2
|
|
12
|
+
Requires-Dist: portalocker>=2.8.2
|
|
13
|
+
|
|
14
|
+
# testtool-sdk-python
|
|
15
|
+
Python TestTool SDK for TestSolara
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/testsolar_testtool_sdk/__init__.py
|
|
5
|
+
src/testsolar_testtool_sdk/reporter.py
|
|
6
|
+
src/testsolar_testtool_sdk.egg-info/PKG-INFO
|
|
7
|
+
src/testsolar_testtool_sdk.egg-info/SOURCES.txt
|
|
8
|
+
src/testsolar_testtool_sdk.egg-info/dependency_links.txt
|
|
9
|
+
src/testsolar_testtool_sdk.egg-info/requires.txt
|
|
10
|
+
src/testsolar_testtool_sdk.egg-info/top_level.txt
|
|
11
|
+
src/testsolar_testtool_sdk/model/__init__.py
|
|
12
|
+
src/testsolar_testtool_sdk/model/load.py
|
|
13
|
+
src/testsolar_testtool_sdk/model/param.py
|
|
14
|
+
src/testsolar_testtool_sdk/model/test.py
|
|
15
|
+
src/testsolar_testtool_sdk/model/testresult.py
|
|
16
|
+
tests/test_report.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
testsolar_testtool_sdk
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import io
|
|
2
|
+
import random
|
|
3
|
+
import struct
|
|
4
|
+
import time
|
|
5
|
+
from datetime import datetime, timedelta
|
|
6
|
+
|
|
7
|
+
from src.testsolar_testtool_sdk.model.load import LoadResult, LoadError
|
|
8
|
+
from src.testsolar_testtool_sdk.model.test import TestCase
|
|
9
|
+
from src.testsolar_testtool_sdk.model.testresult import ResultType, LogLevel
|
|
10
|
+
from src.testsolar_testtool_sdk.model.testresult import (
|
|
11
|
+
TestResult,
|
|
12
|
+
TestCaseStep,
|
|
13
|
+
TestCaseAssertError,
|
|
14
|
+
TestCaseLog,
|
|
15
|
+
)
|
|
16
|
+
from src.testsolar_testtool_sdk.reporter import Reporter, MAGIC_NUMBER, ReportType
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _format_datetime(t: datetime) -> str:
|
|
20
|
+
return t.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def generate_demo_load_result() -> LoadResult:
|
|
24
|
+
r: LoadResult = LoadResult(Tests=[], LoadErrors=[])
|
|
25
|
+
|
|
26
|
+
for x in range(40):
|
|
27
|
+
r.tests.append(
|
|
28
|
+
TestCase(
|
|
29
|
+
Name=f"mumu/mu.py/test_case_name_{x}_p1", Attributes={"tag": "P1"}
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
for x in range(20):
|
|
34
|
+
r.load_errors.append(
|
|
35
|
+
LoadError(
|
|
36
|
+
name=f"load error {x}",
|
|
37
|
+
message=f"""
|
|
38
|
+
文件读取失败。可能的原因包括:文件不存在、文件损坏、
|
|
39
|
+
不正确的编码方式或其他未知错误。请检查文件路径和内容的正确性,
|
|
40
|
+
确保文件具有正确的编码格式。如果问题仍然存在,可能需要尝试其他解决方法
|
|
41
|
+
|
|
42
|
+
"en": "File not found. Please check the file path and try again.",
|
|
43
|
+
"zh": "文件未找到。请检查文件路径,然后重试。",
|
|
44
|
+
"ja": "ファイルが見つかりません。ファイルパスを確認して、もう一度試してください。",
|
|
45
|
+
"ko": "파일을 찾을 수 없습니다. 파일 경로를 확인하고 다시 시도하십시오.",
|
|
46
|
+
"it": "File non trovato. Controlla il percorso del file e riprova.",
|
|
47
|
+
"ar": "الملف غير موجود. يرجى التحقق من مسار الملف والمحاولة مرة أخرى.",
|
|
48
|
+
"th": "ไม่พบไฟล์ โปรดตรวจสอบเส้นทางไฟล์และลองอีกครั้ง",
|
|
49
|
+
""",
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
return r
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def generate_test_result(index: int) -> TestResult:
|
|
56
|
+
start: datetime = datetime.utcnow() - timedelta(seconds=40)
|
|
57
|
+
_tr = TestResult(
|
|
58
|
+
Test=TestCase(Name=f"mumu/mu.py/test_case_name_{index}_p1", Attributes={}),
|
|
59
|
+
StartTime=_format_datetime(start),
|
|
60
|
+
EndTime=_format_datetime(datetime.utcnow()),
|
|
61
|
+
ResultType=ResultType.SUCCEED,
|
|
62
|
+
Message="ファイルが見つかりません。ファイルパスを確認して、もう一度試してください。",
|
|
63
|
+
Steps=[generate_testcase_step(f"{index}_{x}") for x in range(40)],
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
return _tr
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def generate_testcase_log(index: str) -> TestCaseLog:
|
|
70
|
+
start: datetime = datetime.utcnow() - timedelta(seconds=15)
|
|
71
|
+
|
|
72
|
+
return TestCaseLog(
|
|
73
|
+
Time=_format_datetime(start),
|
|
74
|
+
Level=LogLevel.INFO,
|
|
75
|
+
Attachments=[
|
|
76
|
+
# Attachment(
|
|
77
|
+
# Name=f"access.log_{index}",
|
|
78
|
+
# Url=str(Path(__file__).parent.resolve().joinpath("test_access.log")),
|
|
79
|
+
# AttachmentType=AttachmentType.FILE,
|
|
80
|
+
# ),
|
|
81
|
+
],
|
|
82
|
+
AssertError=TestCaseAssertError(
|
|
83
|
+
Expect="AAA", Actual="BBB", Message="AAA is not BBB"
|
|
84
|
+
),
|
|
85
|
+
Content=f"采集器:coll-imrv6szb当前状态为0,预期状态为1,状态不一致(0:处理中,1:正常) -> {get_random_unicode(20)}",
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def generate_testcase_step(index: str) -> TestCaseStep:
|
|
90
|
+
start: datetime = datetime.utcnow() - timedelta(seconds=10)
|
|
91
|
+
return TestCaseStep(
|
|
92
|
+
StartTime=_format_datetime(start),
|
|
93
|
+
EndTime=_format_datetime(datetime.utcnow()),
|
|
94
|
+
Title=get_random_unicode(100),
|
|
95
|
+
Logs=[generate_testcase_log(f"{index}_{x}") for x in range(1000)],
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def get_random_unicode(length) -> str:
|
|
100
|
+
get_char = chr
|
|
101
|
+
|
|
102
|
+
# Update this to include code point ranges to be sampled
|
|
103
|
+
include_ranges = [
|
|
104
|
+
(0x0021, 0x0021),
|
|
105
|
+
(0x0023, 0x0026),
|
|
106
|
+
(0x0028, 0x007E),
|
|
107
|
+
(0x00A1, 0x00AC),
|
|
108
|
+
(0x00AE, 0x00FF),
|
|
109
|
+
(0x0100, 0x017F),
|
|
110
|
+
(0x0180, 0x024F),
|
|
111
|
+
(0x2C60, 0x2C7F),
|
|
112
|
+
(0x16A0, 0x16F0),
|
|
113
|
+
(0x0370, 0x0377),
|
|
114
|
+
(0x037A, 0x037E),
|
|
115
|
+
(0x0384, 0x038A),
|
|
116
|
+
(0x038C, 0x038C),
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
alphabet = [
|
|
120
|
+
get_char(code_point)
|
|
121
|
+
for current_range in include_ranges
|
|
122
|
+
for code_point in range(current_range[0], current_range[1] + 1)
|
|
123
|
+
]
|
|
124
|
+
return "".join(random.choice(alphabet) for i in range(length))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_report_load_result() -> None:
|
|
128
|
+
# 创建一个Reporter实例
|
|
129
|
+
pipe_io = io.BytesIO()
|
|
130
|
+
reporter = Reporter(reporter_type=ReportType.Pipeline, pipe_io=pipe_io)
|
|
131
|
+
|
|
132
|
+
# 创建一个LoadResult实例
|
|
133
|
+
load_result = generate_demo_load_result()
|
|
134
|
+
|
|
135
|
+
# 调用report_load_result方法
|
|
136
|
+
reporter.report_load_result(load_result)
|
|
137
|
+
|
|
138
|
+
# 检查管道中的魔数
|
|
139
|
+
pipe_io.seek(0)
|
|
140
|
+
magic_number = struct.unpack("<I", pipe_io.read(4))[0]
|
|
141
|
+
assert magic_number == MAGIC_NUMBER, "Magic number does not match"
|
|
142
|
+
|
|
143
|
+
# 检查管道中的数据长度
|
|
144
|
+
real_load_result = load_result.model_dump_json(by_alias=True).encode("utf-8")
|
|
145
|
+
length = struct.unpack("<I", pipe_io.read(4))[0]
|
|
146
|
+
assert length == len(real_load_result), "Data length does not match"
|
|
147
|
+
|
|
148
|
+
# 检查管道中的数据
|
|
149
|
+
expected_load_result = pipe_io.read(length)
|
|
150
|
+
assert real_load_result == expected_load_result, "Data load result does not much"
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def test_report_run_case_result():
|
|
154
|
+
# 创建一个Reporter实例
|
|
155
|
+
pipe_io = io.BytesIO()
|
|
156
|
+
reporter = Reporter(reporter_type=ReportType.Pipeline, pipe_io=pipe_io)
|
|
157
|
+
|
|
158
|
+
test_results = []
|
|
159
|
+
|
|
160
|
+
# 创建五个LoadResult实例并调用report_run_case_result方法
|
|
161
|
+
for i in range(5):
|
|
162
|
+
run_case_result = generate_test_result(i)
|
|
163
|
+
test_results.append(run_case_result)
|
|
164
|
+
reporter.report_run_case_result(run_case_result)
|
|
165
|
+
time.sleep(1)
|
|
166
|
+
|
|
167
|
+
# 检查管道中的数据,确保每个用例的魔数和数据长度还有数据正确
|
|
168
|
+
pipe_io.seek(0)
|
|
169
|
+
for test_result in test_results:
|
|
170
|
+
index = test_results.index(test_result)
|
|
171
|
+
magic_number = struct.unpack("<I", pipe_io.read(4))[0]
|
|
172
|
+
assert (
|
|
173
|
+
magic_number == MAGIC_NUMBER
|
|
174
|
+
), f"Magic number does not match for case {index}"
|
|
175
|
+
|
|
176
|
+
length = struct.unpack("<I", pipe_io.read(4))[0]
|
|
177
|
+
|
|
178
|
+
expected_result_data = test_result.model_dump_json(by_alias=True).encode(
|
|
179
|
+
"utf-8"
|
|
180
|
+
)
|
|
181
|
+
expected_length = len(expected_result_data)
|
|
182
|
+
assert length == expected_length, f"Data length does not match for case {index}"
|
|
183
|
+
|
|
184
|
+
result_data = pipe_io.read(length)
|
|
185
|
+
assert (
|
|
186
|
+
result_data == expected_result_data
|
|
187
|
+
), f"Result data does not match for case {index}"
|