"""Offline VS Code Activity Bar views, search filter & layout settings verifier for Ch07."""
import fnmatch
import json
VERSION = "CPython 3.12.14 offline VS Code Activity Bar & search filter verifier"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: 5 core Activity Bar views & Search include/exclude glob filter
views = ["Explorer", "Search", "Source Control", "Debug", "Extensions"]
files = [
"src/app.js",
"src/utils.js",
"node_modules/pkg/index.js",
"dist/bundle.js",
"README.md",
]
matched = [
f for f in files
if fnmatch.fnmatch(f, "*.js")
and not fnmatch.fnmatch(f, "node_modules/*")
and not fnmatch.fnmatch(f, "dist/*")
]
cases.append(
check(
"activity_bar_views_and_search_filter",
"Verify 5 core Activity Bar viewlets and Search panel include/exclude glob filtering",
{
"view_count": 5,
"first_view": "Explorer",
"filtered_js_files": ["src/app.js", "src/utils.js"],
},
{
"view_count": len(views),
"first_view": views[0],
"filtered_js_files": matched,
},
)
)
# Case 2: Activity Bar visibility toggles & Side Bar left/right relocation
visibility = {v: True for v in views}
visibility["Debug"] = False
layout_settings = {"workbench.sideBar.location": "left"}
layout_settings["workbench.sideBar.location"] = "right"
moved_right = layout_settings["workbench.sideBar.location"]
layout_settings["workbench.sideBar.location"] = "left"
restored_left = layout_settings["workbench.sideBar.location"]
cases.append(
check(
"activity_bar_customization_settings",
"Verify Activity Bar icon visibility toggling and Side Bar left/right position switching",
{
"visible_count_after_hide": 4,
"hidden_views": ["Debug"],
"moved_side": "right",
"restored_side": "left",
},
{
"visible_count_after_hide": sum(1 for v in visibility.values() if v),
"hidden_views": [k for k, v in visibility.items() if not v],
"moved_side": moved_right,
"restored_side": restored_left,
},
)
)
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
入口文件:projects/vscode-activity-bar-lab/explore-activity-bar.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-activity-bar.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2201.zip
课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2203.zip