chore: 初始化版本控制,添加 .gitignore 纳入撮合自动化测试工程
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""资金类字段断言工具:全部走 Decimal,杜绝 float 精度误差。"""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from formula.contract_formula import to_decimal
|
||||
|
||||
|
||||
def assert_decimal_equal(actual, expected, places=8):
|
||||
"""断言两个金额/数量在指定精度下相等。
|
||||
|
||||
金额字段统一按 ``places`` 位小数(默认 8 位,撮合系统常用精度)量化后
|
||||
比较,既避免逐位浮点比较的脆弱性,又不放过真实精度丢失。
|
||||
|
||||
:param actual: 实际值(HTTP 响应/落库/缓存中的值,可为字符串)
|
||||
:param expected: 期望值(公式层计算结果)
|
||||
:param places: 比较小数位数
|
||||
"""
|
||||
quantum = Decimal(1).scaleb(-places)
|
||||
actual_q = to_decimal(actual).quantize(quantum)
|
||||
expected_q = to_decimal(expected).quantize(quantum)
|
||||
assert actual_q == expected_q, (
|
||||
"金额不一致: actual=%s, expected=%s (精度 %d 位)" % (actual, expected, places)
|
||||
)
|
||||
|
||||
|
||||
def assert_decimal_ge(actual, expected):
|
||||
"""断言 actual >= expected(Decimal 口径)。"""
|
||||
assert to_decimal(actual) >= to_decimal(expected), (
|
||||
"断言失败: %s 应大于等于 %s" % (actual, expected)
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
"""HTTP 客户端封装:统一请求头、统一入口,供接口封装层(api/)复用。"""
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
class Adapter:
|
||||
"""对 requests 的薄封装,统一 JSON 请求头与异常口径。"""
|
||||
|
||||
HEADERS = {"Content-Type": "application/json"}
|
||||
|
||||
def request(self, method, url, **kwargs):
|
||||
kwargs.setdefault("headers", self.HEADERS)
|
||||
kwargs.setdefault("timeout", 10)
|
||||
with requests.sessions.Session() as session:
|
||||
return session.request(method=method, url=url, **kwargs)
|
||||
|
||||
def get(self, url, params=None, **kwargs):
|
||||
return self.request("get", url, params=params, **kwargs)
|
||||
|
||||
def post(self, url, json=None, **kwargs):
|
||||
return self.request("post", url, json=json, **kwargs)
|
||||
|
||||
def put(self, url, json=None, **kwargs):
|
||||
return self.request("put", url, json=json, **kwargs)
|
||||
|
||||
def delete(self, url, json=None, **kwargs):
|
||||
return self.request("delete", url, json=json, **kwargs)
|
||||
@@ -0,0 +1,18 @@
|
||||
"""YAML 测试数据读取器(数据驱动的数据面)。"""
|
||||
|
||||
import os
|
||||
|
||||
import yaml
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
|
||||
def read_yaml(filepath):
|
||||
"""读取 YAML 文件并返回解析后的 dict。
|
||||
|
||||
:param filepath: YAML 文件路径(绝对路径,或相对工程根目录的路径)
|
||||
"""
|
||||
if not os.path.isabs(filepath):
|
||||
filepath = os.path.join(ROOT_DIR, filepath)
|
||||
with open(filepath, encoding="utf-8") as f:
|
||||
return yaml.safe_load(f.read())
|
||||
Reference in New Issue
Block a user