style: ruff format 对本轮修改文件统一格式

This commit is contained in:
Jayway Liu
2026-09-26 01:42:37 +08:00
parent 649fec4121
commit 4a89c92313
7 changed files with 56 additions and 37 deletions
+28 -7
View File
@@ -54,10 +54,21 @@ def test_to_decimal_evaluator_golden_samples():
{"operator": "divide", "left": {"metric": "revenue"}, "right": {"metric": "customers"}}, values
) == Decimal("999999999999.99") / Decimal("7")
# 除零与缺失指标返回 None(对应 Excel #N/A)
assert to_decimal({"operator": "divide", "left": {"metric": "revenue"}, "right": {"number": 0}}, values) is None
assert to_decimal({"operator": "add", "left": {"metric": "cost"}, "right": {"metric": "customers"}}, {**values, "customers": None}) is None
assert (
to_decimal({"operator": "divide", "left": {"metric": "revenue"}, "right": {"number": 0}}, values)
is None
)
assert (
to_decimal(
{"operator": "add", "left": {"metric": "cost"}, "right": {"metric": "customers"}},
{**values, "customers": None},
)
is None
)
# 负数与常数组合
assert to_decimal({"operator": "subtract", "left": {"number": -2.5}, "right": {"metric": "cost"}}, values) == Decimal("-2.5") - Decimal("0.0000001")
assert to_decimal(
{"operator": "subtract", "left": {"number": -2.5}, "right": {"metric": "cost"}}, values
) == Decimal("-2.5") - Decimal("0.0000001")
def test_reconcile_uses_independent_tolerances_per_metric_kind(workspace):
@@ -72,7 +83,16 @@ def test_reconcile_uses_independent_tolerances_per_metric_kind(workspace):
workbook = load_workbook(BytesIO(output.getvalue()), data_only=False)
sheet = workbook["对账检查"]
rows = list(sheet.iter_rows(values_only=True))
assert list(rows[0]) == ["指标", "分组", "期间侧", "服务器 Decimal 参考", "公式结果", "差异", "容差", "状态"]
assert list(rows[0]) == [
"指标",
"分组",
"期间侧",
"服务器 Decimal 参考",
"公式结果",
"差异",
"容差",
"状态",
]
def find(metric, side="本期"):
return next(row for row in rows[1:] if row[0] == metric and row[2] == side)
@@ -84,7 +104,9 @@ def test_reconcile_uses_independent_tolerances_per_metric_kind(workspace):
assert find("ROI")[6] == pytest.approx(0.0001)
assert find("客单价")[6] == pytest.approx(0.0001)
# 状态公式按容差列比较(<=G),不再统一 <0.01
status = next(cell.value for cell in sheet[2] if isinstance(cell.value, str) and cell.value.startswith("=IF(D"))
status = next(
cell.value for cell in sheet[2] if isinstance(cell.value, str) and cell.value.startswith("=IF(D")
)
assert "<=G2" in status
# 参数页写明对账规则,容差调整需财务批准
parameters = {str(row[0]): row for row in workbook["参数与口径"].iter_rows(values_only=True) if row[0]}
@@ -208,8 +230,7 @@ def test_reconcile_passes_in_libreoffice_with_per_metric_tolerances(workspace, t
assert result.returncode == 0, result.stderr or result.stdout
values = load_workbook(output / workbook_path.name, data_only=True)
statuses = [
(row[0], row[1], row[2], row[7])
for row in values["对账检查"].iter_rows(min_row=2, values_only=True)
(row[0], row[1], row[2], row[7]) for row in values["对账检查"].iter_rows(min_row=2, values_only=True)
]
assert statuses
assert all(status in ("通过", "无参考") for *_head, status in statuses), statuses