WebsocketTest 1.0.3__py3-none-any.whl → 1.0.4__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.
- WebsocketTest/caseScript/Aqua.py +3 -3
- WebsocketTest/caseScript/Gateway.py +3 -3
- WebsocketTest/cli.py +20 -50
- WebsocketTest/commands/startproject.py +28 -0
- WebsocketTest/commands/test.py +19 -0
- WebsocketTest/common/Assertion.py +1 -1
- WebsocketTest/common/WSBaseApi.py +3 -3
- WebsocketTest/common/WebSocketApi.py +1 -1
- WebsocketTest/common/assertUtils.py +1 -1
- WebsocketTest/common/utils.py +1 -1
- WebsocketTest/run_tests.py +12 -12
- {WebsocketTest-1.0.3.dist-info → websockettest-1.0.4.dist-info}/METADATA +7 -5
- websockettest-1.0.4.dist-info/RECORD +22 -0
- {WebsocketTest-1.0.3.dist-info → websockettest-1.0.4.dist-info}/WHEEL +1 -1
- websockettest-1.0.4.dist-info/entry_points.txt +2 -0
- WebsocketTest/testcase/test_all.py +0 -10
- WebsocketTest-1.0.3.dist-info/RECORD +0 -21
- WebsocketTest-1.0.3.dist-info/entry_points.txt +0 -2
- /WebsocketTest/{testcase → commands}/__init__.py +0 -0
- {WebsocketTest-1.0.3.dist-info → websockettest-1.0.4.dist-info}/top_level.txt +0 -0
WebsocketTest/caseScript/Aqua.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
|
2
|
-
from common.utils import *
|
2
|
+
from WebsocketTest.common.utils import *
|
3
3
|
from urllib.parse import quote_plus
|
4
|
-
from common import WSBaseApi
|
5
|
-
from common.WSBaseApi import WSBaseApi
|
4
|
+
from WebsocketTest.common import WSBaseApi
|
5
|
+
from WebsocketTest.common.WSBaseApi import WSBaseApi
|
6
6
|
|
7
7
|
|
8
8
|
|
@@ -6,8 +6,8 @@ import hashlib
|
|
6
6
|
import hmac,time
|
7
7
|
from urllib.parse import urlencode, urlparse
|
8
8
|
import uuid
|
9
|
-
from common.utils import *
|
10
|
-
from common.WSBaseApi import WSBaseApi
|
9
|
+
from WebsocketTest.common.utils import *
|
10
|
+
from WebsocketTest.common.WSBaseApi import WSBaseApi
|
11
11
|
from pathlib import Path
|
12
12
|
|
13
13
|
class ApiTestRunner(WSBaseApi):
|
@@ -66,7 +66,7 @@ class ApiTestRunner(WSBaseApi):
|
|
66
66
|
while True:
|
67
67
|
try:
|
68
68
|
msg = await ws.recv()
|
69
|
-
|
69
|
+
print(msg)
|
70
70
|
response_data = json.loads(msg)
|
71
71
|
# code 返回码,0表示成功,其它表示异常
|
72
72
|
if response_data["header"]["code"] == 0:
|
WebsocketTest/cli.py
CHANGED
@@ -1,56 +1,26 @@
|
|
1
1
|
import argparse
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import pytest
|
5
|
-
|
6
|
-
def main_run(pytest_args: list) -> enum.IntEnum:
|
7
|
-
"""Run pytest with given arguments
|
8
|
-
|
9
|
-
Args:
|
10
|
-
pytest_args: List of arguments to pass to pytest
|
11
|
-
|
12
|
-
Returns:
|
13
|
-
pytest.ExitCode enum value
|
14
|
-
"""
|
15
|
-
print("Running pytest with args:", pytest_args)
|
16
|
-
return pytest.main(pytest_args)
|
2
|
+
from pathlib import Path
|
3
|
+
from importlib import import_module
|
17
4
|
|
18
5
|
def main():
|
19
|
-
|
20
|
-
|
21
|
-
parser = argparse.ArgumentParser(description="Run tests with Allure reporting")
|
22
|
-
|
23
|
-
# 添加必选参数
|
24
|
-
parser.add_argument("--env", required=True, help="Test environment")
|
25
|
-
parser.add_argument("--app", required=True, help="Application ID")
|
26
|
-
parser.add_argument("--service", required=True, help="Service name")
|
27
|
-
parser.add_argument("--project", required=True, help="Project name")
|
28
|
-
|
29
|
-
# 解析参数,分离已知参数和要传递给pytest的参数
|
30
|
-
args, pytest_args = parser.parse_known_args()
|
6
|
+
parser = argparse.ArgumentParser(description="ws CLI")
|
7
|
+
subparsers = parser.add_subparsers(dest='command', required=True)
|
31
8
|
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
#
|
46
|
-
|
47
|
-
|
48
|
-
# 返回退出码
|
49
|
-
sys.exit(return_code)
|
50
|
-
def main_run_alias():
|
51
|
-
""" command alias
|
52
|
-
prun = pastor run
|
53
|
-
"""
|
54
|
-
main()
|
9
|
+
# 动态加载子命令
|
10
|
+
commands_dir = Path(__file__).parent / "commands"
|
11
|
+
for cmd_file in commands_dir.glob("*.py"):
|
12
|
+
if cmd_file.stem != "__init__":
|
13
|
+
cmd_name = cmd_file.stem
|
14
|
+
module = import_module(f"WebsocketTest.commands.{cmd_name}")
|
15
|
+
cmd_parser = subparsers.add_parser(cmd_name, help=module.__doc__)
|
16
|
+
if hasattr(module, 'configure_parser'):
|
17
|
+
module.configure_parser(cmd_parser)
|
18
|
+
# 关键:绑定执行函数
|
19
|
+
if hasattr(module, 'func'):
|
20
|
+
cmd_parser.set_defaults(func=module.func)
|
21
|
+
args = parser.parse_args()
|
22
|
+
args.func(args) # 调用子命令的执行函数
|
23
|
+
|
24
|
+
|
55
25
|
if __name__ == "__main__":
|
56
26
|
main()
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import shutil
|
2
|
+
from pathlib import Path
|
3
|
+
|
4
|
+
|
5
|
+
def configure_parser(parser):
|
6
|
+
"""配置子命令参数"""
|
7
|
+
parser.add_argument("project_name", help="项目名称")
|
8
|
+
parser.add_argument("-t", "--template",
|
9
|
+
choices=["basic", "advanced"],
|
10
|
+
default="basic")
|
11
|
+
parser.add_argument("--force", action="store_true",
|
12
|
+
help="覆盖已存在目录")
|
13
|
+
|
14
|
+
def execute(args):
|
15
|
+
"""执行项目创建"""
|
16
|
+
template_dir = Path(__file__).parent.parent / "templates" / args.template
|
17
|
+
target_dir = Path.cwd() / args.project_name
|
18
|
+
|
19
|
+
if target_dir.exists():
|
20
|
+
if not args.force:
|
21
|
+
raise FileExistsError(f"目录已存在: {target_dir}")
|
22
|
+
shutil.rmtree(target_dir)
|
23
|
+
|
24
|
+
shutil.copytree(template_dir, target_dir)
|
25
|
+
print(f"项目创建成功: {target_dir}")
|
26
|
+
|
27
|
+
# 注册到主CLI
|
28
|
+
func = execute
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
from WebsocketTest.run_tests import TestRunner
|
3
|
+
|
4
|
+
|
5
|
+
def configure_parser(parser):
|
6
|
+
"""配置子命令参数"""
|
7
|
+
parser.add_argument("--env", required=True, help="Test environment")
|
8
|
+
parser.add_argument("--app", required=True, help="Application ID")
|
9
|
+
parser.add_argument("--service", required=True, help="Service name")
|
10
|
+
parser.add_argument("--project", required=True, help="Project name")
|
11
|
+
parser.add_argument("--port", type=int, default=8883, help="Allure report port")
|
12
|
+
parser.add_argument("--report-dir", default="allure_report", help="Allure report directory")
|
13
|
+
|
14
|
+
def execute(args):
|
15
|
+
"""执行test"""
|
16
|
+
test_runner = TestRunner(args)
|
17
|
+
exit(test_runner.run())
|
18
|
+
# 注册到主CLI
|
19
|
+
func = execute
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import websockets
|
2
2
|
from functools import cached_property
|
3
3
|
import asyncio
|
4
|
-
from common.utils import *
|
4
|
+
from WebsocketTest.common.utils import *
|
5
5
|
import allure
|
6
6
|
from pathlib import Path
|
7
|
-
from common.Assertion import Assert
|
7
|
+
from WebsocketTest.common.Assertion import Assert
|
8
8
|
import pytest
|
9
9
|
import traceback
|
10
10
|
class WSBaseApi:
|
@@ -39,7 +39,7 @@ class BaseApiTest:
|
|
39
39
|
def API_TEST_RUNNER_CLASS(self):
|
40
40
|
"""动态加载对应的测试运行器类(自动缓存)"""
|
41
41
|
class_prefix = self.__class__.__name__[4:] # TestGateway -> Gateway
|
42
|
-
module_path = f"caseScript.{class_prefix}"
|
42
|
+
module_path = f"WebsocketTest.caseScript.{class_prefix}"
|
43
43
|
|
44
44
|
try:
|
45
45
|
module = __import__(module_path, fromlist=['ApiTestRunner'])
|
WebsocketTest/common/utils.py
CHANGED
@@ -6,7 +6,7 @@ import string
|
|
6
6
|
from datetime import datetime
|
7
7
|
import email.utils
|
8
8
|
from functools import wraps
|
9
|
-
from common.logger import *
|
9
|
+
from WebsocketTest.common.logger import *
|
10
10
|
from typing import Optional, Union, Literal
|
11
11
|
import numpy as np
|
12
12
|
def get_rfc1123_time():
|
WebsocketTest/run_tests.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import subprocess
|
1
|
+
import subprocess
|
2
2
|
import argparse
|
3
3
|
import shutil
|
4
|
-
from common.logger import *
|
4
|
+
from WebsocketTest.common.logger import *
|
5
5
|
import time
|
6
6
|
import webbrowser
|
7
7
|
from urllib.request import urlopen
|
8
8
|
from urllib.error import URLError
|
9
|
-
|
10
9
|
logger = logging.getLogger('run_tests')
|
10
|
+
from pathlib import Path
|
11
11
|
|
12
12
|
class AllureManager:
|
13
13
|
def __init__(self, port: int = 8883):
|
@@ -69,18 +69,20 @@ class TestRunner:
|
|
69
69
|
"""直接存储args对象"""
|
70
70
|
self.args = args
|
71
71
|
self.allure_manager = AllureManager(self.args.port)
|
72
|
-
|
72
|
+
self.allure_results = str(Path.cwd().joinpath("allure_results"))
|
73
|
+
|
73
74
|
def run_pytest_tests(self) -> bool:
|
74
75
|
"""执行pytest测试"""
|
75
76
|
case = self.args.service.split('_')[0]
|
77
|
+
|
76
78
|
cmd = [
|
77
|
-
"pytest",
|
79
|
+
"pytest", str(Path.cwd().joinpath("testcase","test_all.py")),
|
78
80
|
"-m", case,
|
79
81
|
"--env", self.args.env,
|
80
82
|
"--app", self.args.app,
|
81
83
|
"--service", self.args.service,
|
82
84
|
"--project", self.args.project,
|
83
|
-
"--alluredir",
|
85
|
+
"--alluredir", self.allure_results
|
84
86
|
]
|
85
87
|
try:
|
86
88
|
logger.info(f"run_pytest_tests Executing: {' '.join(cmd)}")
|
@@ -93,7 +95,7 @@ class TestRunner:
|
|
93
95
|
def generate_allure_report(self) -> bool:
|
94
96
|
"""生成Allure报告"""
|
95
97
|
try:
|
96
|
-
cmd = [self.allure_manager.allure_path, "generate",
|
98
|
+
cmd = [self.allure_manager.allure_path, "generate", self.allure_results, "-o", self.args.report_dir, "--clean"]
|
97
99
|
subprocess.run(
|
98
100
|
cmd,
|
99
101
|
check=True,
|
@@ -113,7 +115,6 @@ class TestRunner:
|
|
113
115
|
logger.info("Starting new Allure server...")
|
114
116
|
if self.allure_manager.start_server(self.args.report_dir):
|
115
117
|
webbrowser.open(f"http://localhost:{self.args.port}")
|
116
|
-
|
117
118
|
def run(self):
|
118
119
|
# 1. 运行测试
|
119
120
|
self.run_pytest_tests()
|
@@ -125,7 +126,8 @@ class TestRunner:
|
|
125
126
|
self._handle_allure_report()
|
126
127
|
logger.info(f"http://localhost:{self.args.port}")
|
127
128
|
return 0
|
128
|
-
|
129
|
+
|
130
|
+
if __name__ == "__main__":
|
129
131
|
try:
|
130
132
|
parser = argparse.ArgumentParser(description="Run tests with Allure reporting")
|
131
133
|
parser.add_argument("--env", required=True, help="Test environment")
|
@@ -142,6 +144,4 @@ def main():
|
|
142
144
|
exit(1)
|
143
145
|
except Exception as e:
|
144
146
|
logger.error(f"Unexpected error: {e}", exc_info=True)
|
145
|
-
exit(1)
|
146
|
-
if __name__ == "__main__":
|
147
|
-
main()
|
147
|
+
exit(1)
|
@@ -1,14 +1,16 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: WebsocketTest
|
3
|
-
Version: 1.0.
|
3
|
+
Version: 1.0.4
|
4
4
|
Summary: websocket api autotest
|
5
5
|
Author: chencheng
|
6
6
|
Requires-Python: >=3.10
|
7
|
-
|
8
|
-
Requires-Dist: allure-python-commons==2.13.5
|
7
|
+
Requires-Dist: allure_python_commons==2.13.5
|
9
8
|
Requires-Dist: numpy==2.2.4
|
10
9
|
Requires-Dist: pandas==2.2.3
|
11
10
|
Requires-Dist: pytest==8.2.2
|
12
11
|
Requires-Dist: PyYAML==6.0.2
|
13
12
|
Requires-Dist: websockets==12.0
|
14
|
-
|
13
|
+
Dynamic: author
|
14
|
+
Dynamic: requires-dist
|
15
|
+
Dynamic: requires-python
|
16
|
+
Dynamic: summary
|
@@ -0,0 +1,22 @@
|
|
1
|
+
WebsocketTest/__init__.py,sha256=u71SAVmbgsyp0K21kilo7pIDgeyxsaHAi93clC0OIPQ,556
|
2
|
+
WebsocketTest/cli.py,sha256=-33enBQWpq6S7eniXI1E-QHg2aoTEFfR7ZjksU-RYpI,975
|
3
|
+
WebsocketTest/conftest.py,sha256=y2_2961mhCYSRMp5X9xLq3nOmRzaTSgD3GDdrlTqxn4,1885
|
4
|
+
WebsocketTest/run_tests.py,sha256=y3Mwe1_LAKlBOzu_A-rOiRTAfVWY6vuyqrVD1XExY9M,5909
|
5
|
+
WebsocketTest/caseScript/Aqua.py,sha256=N5ZroovGHAC0DqpXC1RTJNgHhRRmL-2WoJn7M4edOVo,7447
|
6
|
+
WebsocketTest/caseScript/Gateway.py,sha256=8CydLZ8zTPwoYlPvp0NUTZWhX-8Y6--oDNKnvKDK20g,11749
|
7
|
+
WebsocketTest/caseScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
WebsocketTest/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
WebsocketTest/commands/startproject.py,sha256=xTL6Tct8J8Ks6QD2VrQkNAWGhyv1UEMBuh2gmKCi3d0,909
|
10
|
+
WebsocketTest/commands/test.py,sha256=T_yB_enbLdtiTlDgJ78BdbIxjddw_5RqnBUrwBYtpkg,738
|
11
|
+
WebsocketTest/common/Assertion.py,sha256=Kd86Dr6CkPGHN4747T4doyZjklhEFaQ14WCJxuN59IU,5229
|
12
|
+
WebsocketTest/common/WSBaseApi.py,sha256=H9l7xys_OIZ7Kzh9PQU-721zXgKdgrlQRvfSyPPSPiw,4024
|
13
|
+
WebsocketTest/common/WebSocketApi.py,sha256=Oa0DmTm7k8J8IF28pA9HcmunR2Qz4pQKH_O4zjedw4c,2757
|
14
|
+
WebsocketTest/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
+
WebsocketTest/common/assertUtils.py,sha256=poyL6J_WXb2BJvaABCILfiWHN7gHSTRcMWvpjk224yU,4713
|
16
|
+
WebsocketTest/common/logger.py,sha256=B7jjPd5miAYorveHUEGW8xKxUNlJzKlVug0rKWRK3p0,783
|
17
|
+
WebsocketTest/common/utils.py,sha256=jaNxKQjQCtIdN6VuFJQ22TWjMuMqN2CHrweE0GspQT8,8720
|
18
|
+
websockettest-1.0.4.dist-info/METADATA,sha256=9WbRF8pnKr04t1wwd3jcUp4nIsdSUhIPEgeyDLZXf4g,420
|
19
|
+
websockettest-1.0.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
20
|
+
websockettest-1.0.4.dist-info/entry_points.txt,sha256=9-0RmZ0nVgfDKaDFyk5xv8arp_us-7w5Negvis1CvYc,46
|
21
|
+
websockettest-1.0.4.dist-info/top_level.txt,sha256=2iF1gZSbXLjVFOe5ZKQiCLC1FzAwhcQUM88yGi-vrCU,14
|
22
|
+
websockettest-1.0.4.dist-info/RECORD,,
|
@@ -1,21 +0,0 @@
|
|
1
|
-
WebsocketTest/__init__.py,sha256=u71SAVmbgsyp0K21kilo7pIDgeyxsaHAi93clC0OIPQ,556
|
2
|
-
WebsocketTest/cli.py,sha256=Y8lQ_V5blKxNg-Q9PeuPu7zasMNDPmry9g4KXnliDfk,1636
|
3
|
-
WebsocketTest/conftest.py,sha256=y2_2961mhCYSRMp5X9xLq3nOmRzaTSgD3GDdrlTqxn4,1885
|
4
|
-
WebsocketTest/run_tests.py,sha256=cRKvcQGBZG-1XkeoSMeCU8TI76FunrS2jkx6COx91_o,5776
|
5
|
-
WebsocketTest/caseScript/Aqua.py,sha256=zr1mURYGikzzJDsx2lwdH9m_ENlJzH3vDvepsfwhfdg,7405
|
6
|
-
WebsocketTest/caseScript/Gateway.py,sha256=D_oVhhKGFA3FdFblg_YmUj2HhlPNI3kht9LqHnSuNZA,11723
|
7
|
-
WebsocketTest/caseScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
WebsocketTest/common/Assertion.py,sha256=xMesYiZY6FSf7_Zf6BIXGl9a2Prx-blRYGK2zKQy81M,5215
|
9
|
-
WebsocketTest/common/WSBaseApi.py,sha256=-zDpMsaF4ugVKUpzDwbs6l9DBvlh2uw1oJGY64fk6fY,3982
|
10
|
-
WebsocketTest/common/WebSocketApi.py,sha256=JpgX1qAA8skh_t9hLDmgEx6KugewF284u2cjrQkbLnI,2743
|
11
|
-
WebsocketTest/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
WebsocketTest/common/assertUtils.py,sha256=xJvjm0QDIxUHIZm96-2sKkDUWzPQHaOJB9x9eSLlIoU,4699
|
13
|
-
WebsocketTest/common/logger.py,sha256=B7jjPd5miAYorveHUEGW8xKxUNlJzKlVug0rKWRK3p0,783
|
14
|
-
WebsocketTest/common/utils.py,sha256=5NrU_cXzpzTYSI38LZe4IjJe3HxNB64rtrXZcf3Vixs,8706
|
15
|
-
WebsocketTest/testcase/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
-
WebsocketTest/testcase/test_all.py,sha256=mdfivt5vmfcn_4LZVcQ1KTH0n69gKxd_Id-DCapGlu4,198
|
17
|
-
WebsocketTest-1.0.3.dist-info/METADATA,sha256=TOfnxrmuLy4hqPkXk_9d5w-94RuyYqC4r3ecSH0X-Sg,378
|
18
|
-
WebsocketTest-1.0.3.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
19
|
-
WebsocketTest-1.0.3.dist-info/entry_points.txt,sha256=7ppZml2d-BVAurDYhw301dOBU8wDgQrtTNlkJNGSc_Q,59
|
20
|
-
WebsocketTest-1.0.3.dist-info/top_level.txt,sha256=2iF1gZSbXLjVFOe5ZKQiCLC1FzAwhcQUM88yGi-vrCU,14
|
21
|
-
WebsocketTest-1.0.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|