Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ htmlcov/

# 生成文件
zsim/data/APLData/custom/*
!zsim/data/APLData/custom/.gitkeep
*out*
!zsim/api_src/routes/
!zsim/api_src/routes/*.py
Expand Down
28 changes: 28 additions & 0 deletions tests/test_apl_archive_bootstrap.py
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions zsim/data/APLData/custom/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions zsim/lib_webui/process_apl_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading