"""核算落库辅助纯函数测试。 守的是:金额两位固化的舍入模式 —— quantize 缺省是上下文 ROUND_HALF_EVEN (银行家舍入),x.xx5 会舍成偶数尾数,与业务四舍五入口径差 1 分 (docstring 声称 HALF_UP,必须用测试锁死实际行为)。 """ from decimal import Decimal from app.services.calc_service import _q2 class TestQ2: """金额两位小数(HALF_UP)。""" def test_半进位一律入(self) -> None: # 缺省 ROUND_HALF_EVEN 会舍成 2.34(4 是偶数) assert _q2(Decimal("2.345")) == Decimal("2.35") def test_负数半进位远离零(self) -> None: assert _q2(Decimal("-2.345")) == Decimal("-2.35") def test_普通进位不变(self) -> None: assert _q2(Decimal("39.111111")) == Decimal("39.11") assert _q2(Decimal("39.115000")) == Decimal("39.12") def test_None直通(self) -> None: assert _q2(None) is None