diff --git a/.gitignore b/.gitignore index 95c26c3a..e7b34592 100644 --- a/.gitignore +++ b/.gitignore @@ -74,6 +74,7 @@ htmlcov/ # ็”Ÿๆˆๆ–‡ไปถ zsim/data/APLData/custom/* +!zsim/data/APLData/custom/.gitkeep *out* !zsim/api_src/routes/ !zsim/api_src/routes/*.py diff --git a/tests/test_apl_archive_bootstrap.py b/tests/test_apl_archive_bootstrap.py new file mode 100644 index 00000000..314e588b --- /dev/null +++ b/tests/test_apl_archive_bootstrap.py @@ -0,0 +1,28 @@ +from zsim.lib_webui import process_apl_editor as apl_editor + + +def test_apl_archive_bootstraps_missing_custom_dir(tmp_path, monkeypatch): + default_apl_dir = tmp_path / "APLData" + custom_apl_dir = default_apl_dir / "custom" + default_apl_dir.mkdir() + (default_apl_dir / "sample.toml").write_text( + """ +[general] +title = "Test APL" + +[apl_logic] +logic = "1|action+=|wait" +""".strip(), + encoding="utf-8", + ) + + warnings: list[str] = [] + monkeypatch.setattr(apl_editor, "DEFAULT_APL_DIR", str(default_apl_dir)) + monkeypatch.setattr(apl_editor, "COSTOM_APL_DIR", str(custom_apl_dir)) + monkeypatch.setattr(apl_editor.st, "warning", warnings.append) + + archive = apl_editor.APLArchive() + + assert custom_apl_dir.is_dir() + assert warnings == [] + assert "Test APL" in archive.options diff --git a/zsim/data/APLData/custom/.gitkeep b/zsim/data/APLData/custom/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/zsim/data/APLData/custom/.gitkeep @@ -0,0 +1 @@ + diff --git a/zsim/lib_webui/process_apl_editor.py b/zsim/lib_webui/process_apl_editor.py index e9624d26..2e4eae87 100644 --- a/zsim/lib_webui/process_apl_editor.py +++ b/zsim/lib_webui/process_apl_editor.py @@ -30,6 +30,7 @@ def __init__(self): self.refresh() def refresh(self): + os.makedirs(COSTOM_APL_DIR, exist_ok=True) self.default_apl_map = self.__get_apl_toml(DEFAULT_APL_DIR) self.custom_apl_map = self.__get_apl_toml(COSTOM_APL_DIR) all_apl_list: list[dict] = list(self.default_apl_map.values()) + list(