蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Eclipse 项目关闭/重开状态与 Clean All Projects 作用域离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-close-project.py
explore-close-project.py116 行
"""Offline Eclipse workspace project close/open & clean-build verifier for Ch18 (close-project)."""
import json
import tempfile
from pathlib import Path

VERSION = "CPython 3.12.14 offline Eclipse workspace/project lifecycle verifier (desktop SWT IDE absent)"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = []

    # Case 1: Close project state transition, editability lock, and memory impact
    workspace = {
        "order-service": {"open": True, "mem_mb": 48, "icon": "open_project"},
        "legacy-report": {"open": True, "mem_mb": 64, "icon": "open_project"},
        "billing-api": {"open": True, "mem_mb": 36, "icon": "open_project"},
    }
    mem_before = sum(p["mem_mb"] for p in workspace.values() if p["open"])
    # Action: Project > Close Project on legacy-report
    workspace["legacy-report"]["open"] = False
    workspace["legacy-report"]["icon"] = "closed_project"
    mem_after = sum(p["mem_mb"] for p in workspace.values() if p["open"])
    can_edit_closed = workspace["legacy-report"]["open"]

    cases.append(
        check(
            "workspace_project_lifecycle",
            "Verify Project > Close Project updates icon state, blocks editing, and reduces active workspace memory",
            {
                "mem_before_mb": 148,
                "mem_after_mb": 84,
                "closed_icon": "closed_project",
                "can_edit_closed": False,
            },
            {
                "mem_before_mb": mem_before,
                "mem_after_mb": mem_after,
                "closed_icon": workspace["legacy-report"]["icon"],
                "can_edit_closed": can_edit_closed,
            },
        )
    )

    # Case 2: Project > Clean > Clean all projects skips closed projects
    with tempfile.TemporaryDirectory() as tmp:
        ws_root = Path(tmp) / "workspace"
        rebuilt = []
        skipped = []
        for proj_name, meta in workspace.items():
            bin_dir = ws_root / proj_name / "bin"
            bin_dir.mkdir(parents=True, exist_ok=True)
            cls_file = bin_dir / "Main.class"
            cls_file.write_bytes(b"\xca\xfe\xba\xbe")
            if meta["open"]:
                cls_file.unlink()
                cls_file.write_bytes(b"\xca\xfe\xba\xbe\x00\x01")
                rebuilt.append(proj_name)
            else:
                skipped.append(proj_name)
        closed_untouched = (ws_root / "legacy-report" / "bin" / "Main.class").read_bytes() == b"\xca\xfe\xba\xbe"

    cases.append(
        check(
            "clean_all_projects_scope",
            "Verify Clean All Projects removes and rebuilds .class files only for open projects",
            {
                "rebuilt": ["billing-api", "order-service"],
                "skipped": ["legacy-report"],
                "closed_class_untouched": True,
            },
            {
                "rebuilt": sorted(rebuilt),
                "skipped": sorted(skipped),
                "closed_class_untouched": closed_untouched,
            },
        )
    )

    # Case 3: Project > Open Project restores editability and workspace participation
    workspace["legacy-report"]["open"] = True
    workspace["legacy-report"]["icon"] = "open_project"
    open_projects = sorted(name for name, meta in workspace.items() if meta["open"])

    cases.append(
        check(
            "reopen_project_restores_edit",
            "Verify Project > Open Project restores open icon, editability, and build participation",
            {
                "open_projects": ["billing-api", "legacy-report", "order-service"],
                "can_edit_reopened": True,
                "reopened_icon": "open_project",
            },
            {
                "open_projects": open_projects,
                "can_edit_reopened": workspace["legacy-report"]["open"],
                "reopened_icon": workspace["legacy-report"]["icon"],
            },
        )
    )

    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/eclipse-close-project-lab/explore-close-project.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-close-project.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Eclipse

课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip

下载课程关联工程包:Eclipse

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2262.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习