A powerful Python mock engine for API testing, template rendering, and code execution with debugging and assertion support.
Project description
Mock Engine
Mock Engine 是一个强大的 Python 模拟执行引擎,提供了模板渲染和代码执行功能,支持调试模式,帮助开发者更好地理解和调试代码执行过程。
功能特点
- 模板引擎:支持变量替换和自定义方法
- 代码引擎:支持 SQL 查询和上下文变量
- 调试模式:详细的执行日志和调试信息
- 数据库支持:内置 SQL 查询功能
- 上下文管理:支持变量传递和共享
安装
pip install mock-engine
快速开始
模板引擎示例
from mock_engine.core.template_engine import TemplateEngine
# 创建引擎实例
engine = TemplateEngine(debug=True)
# 创建模板
template = {
"name": "{{name}}",
"age": "{{age}}"
}
# 创建请求数据
request = {
"name": "张三",
"age": 25
}
# 生成数据
result, debug_output = engine.generate(template, request)
代码引擎示例
from mock_engine.core.code_engine import CodeEngine
# 创建引擎实例
engine = CodeEngine(debug=True)
# 数据库配置
db_config = {
'host': '127.0.0.1',
'user': 'root',
'password': '123456',
'port': 3306,
'database': 'webtest'
}
# 执行代码
code = f"""
result = sql("SELECT * FROM webtest.t_ui_user LIMIT 1", db_config={db_config})
print("查询结果:", result)
"""
result = engine.execute(code)
文档
开发
环境设置
- 克隆仓库:
git clone https://github.com/yourusername/mock-engine.git
cd mock-engine
- 创建虚拟环境:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
- 安装依赖:
pip install -r requirements.txt
运行测试
python -m unittest discover tests
贡献
欢迎提交 Pull Request 或创建 Issue。
许可证
MIT License
mock_engine
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mock_engine-1.0.0.tar.gz
(4.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mock_engine-1.0.0.tar.gz.
File metadata
- Download URL: mock_engine-1.0.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.0b2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2620efe5a3cae6fe54c3ae4ae9f30493cc65bfdb62f66ff3ce5d1e8f88b92660
|
|
| MD5 |
34b8587862ff9ce485f84eb88096f3c8
|
|
| BLAKE2b-256 |
1c9168f5806816a9953bea4fad6103c376858a3f5566e3e1cd776c9188d3011f
|
File details
Details for the file mock_engine-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mock_engine-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.0b2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d9a4b7ed653fdbb4a7f3574d3a09379d0f09358df3f72e72c7ac1e6684004dd
|
|
| MD5 |
2a67a3de2917c8bb8672b5fc0c359d64
|
|
| BLAKE2b-256 |
b9f5548c54be8d5f7bf139fc7e26eb4ac36291b8396987a36ea4a5ab7186887b
|