Skip to content

Commit 8303e7b

Browse files
docs: improve test scripts with dependency checks and usage guide
- Add dependency checks in test scripts with helpful error messages - Update TESTING_GUIDE.md with detailed installation instructions - Clarify async installation requirements (aiohttp needed) - Add troubleshooting section for common issues - Improve user experience for testing
1 parent 1ab1227 commit 8303e7b

File tree

2 files changed

+163
-1
lines changed

2 files changed

+163
-1
lines changed

TESTING_GUIDE.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# 测试指南
2+
3+
本目录包含测试脚本,用于验证 Easysearch Python 客户端的功能。
4+
5+
## 前置要求
6+
7+
1. **运行的 Easysearch 服务器**
8+
- 地址: https://localhost:9200
9+
- 认证: admin 用户及密码
10+
- SSL: 启用(测试中禁用证书验证)
11+
12+
2. **安装客户端**
13+
14+
### 基础安装(同步客户端)
15+
16+
```bash
17+
pip install git+https://github.com/infinilabs/[email protected]
18+
```
19+
20+
### 带异步支持的安装
21+
22+
```bash
23+
# 方式 1: 使用 [async] extra
24+
pip install "git+https://github.com/infinilabs/[email protected]#egg=easysearch[async]"
25+
26+
# 方式 2: 手动安装依赖
27+
pip install git+https://github.com/infinilabs/[email protected]
28+
pip install aiohttp
29+
```
30+
31+
## 运行测试
32+
33+
### 1. 测试同步客户端
34+
35+
```bash
36+
python test_connection.py
37+
```
38+
39+
**预期输出:**
40+
```
41+
正在连接到 Easysearch...
42+
✅ 连接成功!
43+
集群: easysearch
44+
版本: 2.0.3
45+
...
46+
🎉 所有测试通过!
47+
```
48+
49+
### 2. 测试异步客户端
50+
51+
```bash
52+
python test_async.py
53+
```
54+
55+
**预期输出:**
56+
```
57+
正在测试异步客户端...
58+
✅ 异步连接成功!
59+
集群: easysearch
60+
版本: 2.0.3
61+
...
62+
🎉 所有异步测试通过!
63+
```
64+
65+
## 常见问题
66+
67+
### 问题 1: ModuleNotFoundError: No module named 'urllib3'
68+
69+
**原因:** 基础依赖未安装
70+
71+
**解决:**
72+
```bash
73+
pip install urllib3 certifi
74+
# 或者重新安装客户端
75+
pip install git+https://github.com/infinilabs/[email protected]
76+
```
77+
78+
### 问题 2: ImportError: cannot import name 'AsyncEasysearch'
79+
80+
**原因:** 缺少异步依赖 aiohttp
81+
82+
**解决:**
83+
```bash
84+
pip install aiohttp
85+
# 或者使用 async extra 重新安装
86+
pip install "git+https://github.com/infinilabs/[email protected]#egg=easysearch[async]"
87+
```
88+
89+
### 问题 3: ConnectionError: Connection refused
90+
91+
**原因:** Easysearch 服务器未运行或地址不正确
92+
93+
**解决:**
94+
1. 确保 Easysearch 正在运行
95+
2. 验证地址:`curl -k https://localhost:9200`
96+
3. 检查认证信息是否正确
97+
98+
### 问题 4: SSLError: certificate verify failed
99+
100+
**原因:** SSL 证书验证失败
101+
102+
**解决:**
103+
- 测试脚本已禁用证书验证 (`verify_certs=False`)
104+
- 生产环境请使用有效证书或配置 CA 证书
105+
106+
## 修改测试配置
107+
108+
如果你的 Easysearch 服务器配置不同,请修改测试脚本中的连接参数:
109+
110+
```python
111+
es = Easysearch(
112+
['https://your-host:9200'], # 修改地址
113+
http_auth=('your-user', 'your-password'), # 修改认证
114+
use_ssl=True,
115+
verify_certs=False, # 生产环境建议改为 True
116+
ssl_show_warn=False
117+
)
118+
```
119+
120+
## 完整测试套件
121+
122+
要运行完整的测试套件(需要 pytest):
123+
124+
```bash
125+
# 安装测试依赖
126+
pip install -e .
127+
pip install pytest pytest-cov numpy pandas
128+
129+
# 运行所有测试
130+
pytest test_easysearch/ -v
131+
132+
# 运行特定测试
133+
pytest test_easysearch/test_serializer.py -v
134+
pytest test_easysearch/test_connection_pool.py -v
135+
```
136+
137+
## 更多信息
138+
139+
- [安装指南](INSTALL.md)
140+
- [GitHub 仓库](https://github.com/infinilabs/easysearch-py)
141+
- [Easysearch 官网](https://easysearch.cn)

test_async.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""异步客户端测试"""
3+
"""异步客户端测试
4+
5+
要运行此测试,需要先安装异步依赖:
6+
pip install git+https://github.com/infinilabs/[email protected]
7+
pip install aiohttp
8+
9+
或者直接安装带异步支持的版本:
10+
pip install "git+https://github.com/infinilabs/[email protected]#egg=easysearch[async]"
11+
"""
412

513
import asyncio
14+
import sys
15+
16+
# 检查依赖
17+
try:
18+
import aiohttp
19+
except ImportError:
20+
print("❌ 错误: 缺少 aiohttp 依赖")
21+
print("\n请安装异步依赖:")
22+
print(" pip install aiohttp")
23+
print("\n或者重新安装带异步支持的版本:")
24+
print(' pip install "git+https://github.com/infinilabs/[email protected]#egg=easysearch[async]"')
25+
sys.exit(1)
26+
627
from easysearch import AsyncEasysearch
728

829
async def test_async_client():

0 commit comments

Comments
 (0)