普贤教程 › 包参考
testkit 包
断言与测试辅助
| 项 | 值 |
|---|---|
| 包名 | testkit |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | testkit.px |
| 分类 | 可观测与测试 |
| 文件数 / 行数 | 1 / 129 |
安装与引入
bash
pxpkg init # 首次 pxpkg add testkit@0.2.0 pxpkg install
px
import testkit所属分类教程:可观测与测试
公开接口
| 函数 | 参数 |
|---|---|
tk_true | cond, msg=null |
tk_equal | a, b, msg=null |
tk_summary | name, total, failed |
其余 17 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
tk_suffix | msg |
tk_fail | msg |
tk_false | cond, msg=null |
tk_not_equal | a, b, msg=null |
tk_contains | haystack, needle, msg=null |
tk_not_contains | haystack, needle, msg=null |
tk_approx | actual, expected, tol, msg=null |
tk_is_ok | r, msg=null |
tk_is_err | r, msg=null |
tk_type | v, t, msg=null |
tk_len | v, n, msg=null |
tk_tempdir | prefix="tk" |
tk_nil | v, msg=null |
tk_not_nil | v, msg=null |
tk_match | s, pattern, msg=null |
tk_greater | a, b, msg=null |
tk_less | a, b, msg=null |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/testkit —— 断言与测试辅助 ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 所有断言返回 Ok(null) | Err(msg),不直接终止进程(对齐 testing 的 失败继续语义);调用方累加失败数,最后 tk_summary 汇总。 var failed = 0, total = 0 var r = tk_equal(1, 2, "1==2") total += 1 if r.is_err(): failed += 1; print(r) tk_summary("my_test", total, failed) API:tk_true/false/equal/not_equal/contains/not_contains/approx/ is_ok/is_err/type/len/fail/tempdir/summary ============================================================