tools/ci_check.py 统一本地与流水线检查:全量 Python 语法编译(py_compile 不落 __pycache__)+ tests/unit 纯逻辑单测,可选 --frontend 追加壳前端构建;.gitlab-ci.yml 在 Windows runner 上复用同一脚本;requirements-dev.txt / pytest.ini 固化测试依赖与用例路径。单测覆盖 XQ0033/0034/0035/0037/0045/0048 的纯逻辑部分。
101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""XQ0034 续签期限复算与文本归一单测。
|
||
|
||
核心口径(2026-11-10 用户给出 AI 表公式):
|
||
新合同期限 = ROUND(DATEDIF(旧合同到期日, 续签截止日+1, "M"), 0),
|
||
DATEDIF 与 Excel 一致:day(end) < day(start) 少算一个月。
|
||
此前「取最近整月」口径会多算 1 个月,这些用例用于锁死回归。
|
||
"""
|
||
from datetime import date
|
||
|
||
import pytest
|
||
|
||
|
||
@pytest.fixture(scope="module")
|
||
def mod(plugins):
|
||
return plugins.module("xq0034", "data.renewal_esign")
|
||
|
||
|
||
# ---------------- DATEDIF 语义 ----------------
|
||
|
||
def test_datedif_full_months(mod):
|
||
assert mod._datedif_months(date(2026, 1, 1), date(2026, 2, 1)) == 1
|
||
assert mod._datedif_months(date(2026, 1, 1), date(2027, 1, 1)) == 12
|
||
|
||
|
||
def test_datedif_month_end_short_month(mod):
|
||
"""2026-01-31 → 2026-02-28:日不足,不足一个完整月(Excel 语义为 0)。"""
|
||
assert mod._datedif_months(date(2026, 1, 31), date(2026, 2, 28)) == 0
|
||
|
||
|
||
def test_datedif_missing_input(mod):
|
||
assert mod._datedif_months(None, date(2026, 1, 1)) is None
|
||
assert mod._datedif_months(date(2026, 1, 1), None) is None
|
||
|
||
|
||
# ---------------- 新合同期限复算 ----------------
|
||
|
||
def test_renew_months_uses_old_expire_as_base(mod):
|
||
"""刘瑶案例:旧合同到期 2026-10-31、续签截止 2027-10-31 → 12 个月。"""
|
||
n, why = mod._renew_months(date(2026, 11, 1), date(2027, 10, 31), date(2026, 10, 31))
|
||
assert n == 12
|
||
assert "DATEDIF(2026-10-31, 2027-11-01)=12" in why
|
||
|
||
|
||
def test_renew_months_falls_back_to_start_minus_one(mod):
|
||
n, _ = mod._renew_months(date(2026, 11, 1), date(2027, 10, 31), None)
|
||
assert n == 12
|
||
|
||
|
||
def test_renew_months_rejects_end_not_after_base(mod):
|
||
n, why = mod._renew_months(date(2026, 11, 1), date(2026, 10, 1), date(2026, 10, 31))
|
||
assert n is None
|
||
assert "不晚于旧合同到期日" in why
|
||
|
||
|
||
def test_renew_months_requires_dates(mod):
|
||
n, why = mod._renew_months(None, date(2027, 10, 31), None)
|
||
assert n is None
|
||
assert why == "续签开始/截止日期为空"
|
||
|
||
|
||
# ---------------- 字段归一 ----------------
|
||
|
||
@pytest.mark.parametrize("raw, expect", [
|
||
("12.00", "12"), ("12", "12"), (12.0, "12"), ("12.5", "12.5"),
|
||
("", ""), (None, ""), ("abc", ""),
|
||
])
|
||
def test_deadline_code(mod, raw, expect):
|
||
assert mod._deadline_code(raw) == expect
|
||
|
||
|
||
@pytest.mark.parametrize("raw, expect", [
|
||
(123, "123"), ("123.0", "123"), ("00123", "123"), (" 37037921 ", "37037921"),
|
||
("A001", "A001"), (None, ""),
|
||
])
|
||
def test_norm_code(mod, raw, expect):
|
||
assert mod._norm_code(raw) == expect
|
||
|
||
|
||
@pytest.mark.parametrize("raw, expect", [
|
||
("+86 138-0000-0000", "13800000000"),
|
||
("13800000000", "13800000000"), # 全角数字
|
||
("138 0000 0000", "13800000000"),
|
||
("", ""), (None, ""),
|
||
])
|
||
def test_norm_phone(mod, raw, expect):
|
||
assert mod._norm_phone(raw) == expect
|
||
|
||
|
||
@pytest.mark.parametrize("raw, ok", [
|
||
("13800000000", True), ("138-0000-0000", False), # 未归一 -> 交给 _norm_phone 后再校验
|
||
("12800000000", False), ("1380000000", False), ("", False),
|
||
])
|
||
def test_valid_phone(mod, raw, ok):
|
||
assert mod._valid_phone(raw) is ok
|
||
|
||
|
||
def test_norm_name_folds_width_and_spaces(mod):
|
||
assert mod._norm_name("重庆 金色印象(有限公司)") == "重庆金色印象(有限公司)"
|
||
assert mod._norm_name(None) == ""
|