Test Strategy
April 12, 2026 · View on GitHub
当前真实覆盖
| 层 | 文件 | 范围 | 默认运行 |
|---|---|---|---|
| Unit | tests/test_units.py, tests/test_errors.py, tests/test_doctor.py | 纯函数、错误层级、doctor env report | ✓ |
| Integration | tests/test_deck.py, tests/test_slide.py, tests/test_shape.py | Deck / Slide / Shape 的 open-edit-save-reopen roundtrip | ✓ |
| CLI | tests/test_cli.py | 通过 main(argv=...) 调用已实现子命令,不走 subprocess | ✓ |
| Render | tests/test_render.py | render_slide_png() smoke test | 默认 skip,-m libreoffice 时运行 |
Fixture 设计
测试不依赖外部 .pptx 文件。tests/conftest.py 用 python-pptx 在每个 test run 里动态生成一个最小 deck:
- 2 张 slide
- slide 0: 一个多 run / 多 paragraph 的 text box、一个副标题 text box、一个 rectangle、speaker notes
- slide 1: 一个 text box、一个 rectangle、speaker notes
- shape 名称固定,方便按
name、id、text三种方式查找
这样每个写操作都可以做真正的 roundtrip:打开、修改、保存、重新打开、验证结果。
已实现并已测试的内容
Library
units.py:parse_unit,format_emu,parse_colorerrors.py: 全部 domain error 的继承关系deck.py:Deck.open,save,slides,slide,add_slide,delete_slide,to_dict,to_markdownslide.py:shape,shape_by_text,notes,set_notes,to_dict,to_markdown,add_text_box,add_rectangle,delete_shapeshape.py:id,name,type,position,size,text,has_text,set_text,set_position,set_size,set_fill,set_fontdoctor.py:DoctorReport,run_doctor()的无 deck env check
CLI
tests/test_cli.py 只覆盖当前真正实现并接到 handler 的命令:
doctorlist-slideslist-shapesget-textget-notesdump-slidedump-deckset-textset-notes
同时覆盖:
--dry-run不写回文件set-text/set-notes的 before / after stderr 输出- error passthrough:missing file、bad slide index、bad shape id、non-pptx file
明确未覆盖,因为当前项目还没实现或 CLI 还没接线
下面这些能力不应在当前测试文档里写成已覆盖,因为它们现在并没有全部实现到可执行状态:
- CLI:
set-position,set-size,set-fill,set-font,add-slide,delete-slide,move-slide,add-picture,replace-picture,normalize-fonts,check-overflow,raw-xml-patch - library / module level:
overflow.py,dump.py这种文档里曾提到但当前源码中并不存在的模块 - 依赖真实 Office / PowerPoint 打开的视觉一致性验证
Render 测试策略
tests/test_render.py 用 @pytest.mark.libreoffice 标记,并在默认 pytest 下跳过。运行方式:
.venv/bin/python -m pytest -v -m libreoffice
如果本机没装 LibreOffice 或 poppler,这个测试会 skip;默认测试结果不依赖它。
验收标准
.venv/bin/python -m pytest -v全 pass.venv/bin/python -m pytest -v -m libreoffice中 render tests 被正确选中;若缺少依赖则 skip,若依赖存在则 pass
仍然存在的风险边界
- LibreOffice 渲染和 PowerPoint 真机显示仍可能因为字体 fallback 出现差异
- 测试 deck 很小,不覆盖大 deck 的性能和内存行为
- 测试验证的是
python-pptx写出的 OOXML roundtrip,不是人工视觉审阅