"""Offline Python verification lab for PyCharm Chapter 06 (start-intro)."""
import json
import xml.etree.ElementTree as ET
VERSION = "CPython 3.12.14 offline PyCharm workflow verifier (desktop IDE not launched)"
def case_ide_layout_and_tool_windows():
workspace_xml = """<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ToolWindowManager">
<layout>
<window_info id="Project" anchor="left" />
<window_info id="Structure" anchor="left" />
<window_info id="Python Console" anchor="left" />
<window_info id="Terminal" anchor="left" />
<window_info id="AI Assistant" anchor="right" />
<window_info id="Database" anchor="right" />
<window_info id="Run" anchor="bottom" />
<window_info id="Problems" anchor="bottom" />
<window_info id="TODO" anchor="bottom" />
<window_info id="Version Control" anchor="bottom" />
</layout>
</component>
</project>"""
root = ET.fromstring(workspace_xml)
by_anchor = {"left": [], "right": [], "bottom": []}
for wi in root.findall(".//window_info"):
by_anchor[wi.attrib["anchor"]].append(wi.attrib["id"])
top_menus = [
"File", "Edit", "View", "Navigate", "Code",
"Refactor", "Run", "Tools", "VCS", "Window", "Help",
]
status_bar_items = ["Interpreter", "Encoding", "LineSeparator", "CaretPosition", "MemoryIndicator"]
expected = {
"top_menu_count": 11,
"left_windows": ["Project", "Structure", "Python Console", "Terminal"],
"right_windows": ["AI Assistant", "Database"],
"bottom_windows": ["Run", "Problems", "TODO", "Version Control"],
"status_bar_count": 5,
}
actual = {
"top_menu_count": len(top_menus),
"left_windows": by_anchor["left"],
"right_windows": by_anchor["right"],
"bottom_windows": by_anchor["bottom"],
"status_bar_count": len(status_bar_items),
}
return {
"name": "ide_layout_and_tool_windows",
"summary": "解析 .idea/workspace.xml 工具窗口停靠布局并核对顶部 11 项菜单与底部 5 项状态栏指示器",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_chinese_ui_and_encoding_settings():
encodings_xml = """<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8" native2AsciiForPropertiesFiles="true">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>"""
root = ET.fromstring(encodings_xml)
enc = root.find("./component[@name='Encoding']")
proj_file = enc.find("./file[@url='PROJECT']") if enc is not None else None
terms = {
"Refactor": "重构",
"Inspect Code": "检查代码",
"Run Configuration": "运行配置",
}
expected = {
"project_charset": "UTF-8",
"transparent_conversion": True,
"term_mapping": {"Refactor": "重构", "Inspect Code": "检查代码", "Run Configuration": "运行配置"},
}
actual = {
"project_charset": proj_file.attrib.get("charset") if proj_file is not None else "",
"transparent_conversion": enc.attrib.get("native2AsciiForPropertiesFiles") == "true" if enc is not None else False,
"term_mapping": terms,
}
return {
"name": "chinese_ui_and_encoding_settings",
"summary": "解析 .idea/encodings.xml UTF-8 与透明转换设置并核对中英文界面高频术语对照",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def case_view_modes_and_editor_split():
view_modes = {
"full_screen": {"menu": "View -> Enter Full Screen", "shortcut": "Ctrl+Shift+F12"},
"distraction_free": {"menu": "View -> Distraction Free Mode", "hides_tool_windows": True},
"presentation": {"menu": "View -> Presentation Mode", "enlarges_font": True},
"project_view": {"search_everywhere": "Shift+Shift", "query": "Project View"},
}
split_orientations = ("vertical", "horizontal")
expected = {
"mode_count": 4,
"full_screen_shortcut": "Ctrl+Shift+F12",
"split_modes": ["vertical", "horizontal"],
}
actual = {
"mode_count": len(view_modes),
"full_screen_shortcut": view_modes["full_screen"]["shortcut"],
"split_modes": list(split_orientations),
}
return {
"name": "view_modes_and_editor_split",
"summary": "验证全屏、专注、演示、全项目视图模式与垂直/水平分屏配置规范",
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = [
case_ide_layout_and_tool_windows(),
case_chinese_ui_and_encoding_settings(),
case_view_modes_and_editor_split(),
]
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。
入口文件:projects/pycharm-start-intro-lab/explore-start-intro.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-start-intro.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14 离线 PyCharm 工程语义与配置验证器(未启动桌面端 PyCharm IDE)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联17章) · 含当前章节或实例 · mbskycom202612a2240.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2254.zip