Ai features - #8
Merged
Merged
Conversation
新增 tests/editor/ (125 个测试) 覆盖 CodeEditor 全栈 — 不再只测模块
I/O,而是跑通实际的 UI 行为:
- test_lifecycle.py (18): 构造、组件装配、Python/JSON/YAML/XML/LOG
语言切换、hooks 派发
- test_file_operations.py (18): 文件加载(按扩展名识别语言)、保存、
autosave、错误处理、save → reload round-trip
- test_tabs.py (18): 新建/关闭/切换/关闭其它/关闭全部/循环、dirty
跟踪、document 生命周期
- test_buffer.py (36): undo/redo、indent/outdent、toggle_comment、
goto-line、find/replace、高亮、行闪烁、字体/制表宽、ghost-text、
suggestion 弹窗、goto-definition、find_references、lookup_documentation
- test_settings.py (16): 字体/制表宽/主题/高亮/自动保存/补全开关
的全局变更传播到 UI
- test_runner.py (13): Python 静态检查、runner 生命周期
- test_i18n.py (6): 语言切换重建菜单
测试用会话级 CodeEditor fixture,避开了 Python 3.14 + Tk 在
Windows 上多次创建/销毁时的 Tcl 库路径丢失问题。
settings 路径被 monkey-patch 指向私有 tmpdir,不会污染用户的
%APPDATA%/PythonEditor/settings.json。
顺带修 4 个 latent bug:
1. buffer.switch_language() — JSON/YAML/XML/LOG 的 suggestion 配置为
None,旧代码直接 None() 会崩溃。改为优先 *_factory,回退时检查
callable。
2. buffer.outdent() — 用绝对列号删除,越过行尾会吞掉换行符把两行
拼在一起。改为每次从行首删除。
3. buffer._show_find_dialog() — 引用 dlg.window(不存在)而不是
dlg._window,打开"查找"对话框崩溃。
4. tabs.init_first_document() — _next_seq 硬编码为 2,关闭最后一个
tab 后 new_file() 会覆盖当前文档。改为按当前 seq 推进。
外加 3 个 core 修复:
- helpers.format_autosave_path — 默认格式 "{unix.seconds}" 触发
str.format_map 的属性访问语义而 KeyError,改用 "{unix_seconds}"。
- app.CodeEditor 补齐 TabHost/RunnerHost 协议要求的 text_widget /
editor_text / apply_highlight 属性(之前点"新建文件"或
"Run check" 会因 AttributeError 崩溃)。
测试结果:521 passed(原 396 + 新增 125),ruff check /
ruff format --check 全通过。
新增的 tests/editor/ 需要创建 Tk 窗口,Ubuntu runner 没有现成的
DISPLAY,``tk.Tk()`` 会抛 TclError,导致整个 editor 测试套件崩溃。
两处改动:
1. ``.github/workflows/pytest.yml``:
- apt 依赖里加上 ``xvfb``(除了 ``python3-tk``)
- 在 Ubuntu runner 上用 ``xvfb-run -a`` 包住 pytest 调用;
Windows runner 不变(Windows 的 Tk 用本地显示子系统,不需要 X11)
2. ``tests/editor/conftest.py``:
- 加了 session-scope + autouse 的 ``_verify_tk_available`` fixture,
启动时尝试 ``tk.Tk()`` 一次。如果环境完全没有 Tk(比如 macOS
上的某些 CI 配置),整个 editor 测试会干净地 skip 而不会
留下满屏 TclError。
``python -m pytest tests/`` 在 Windows 上仍 521 passed,行为不变。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Add Ai features.
Type of Change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.
Test Configuration:
Checklist:
With issue: #7