Spaces:
Running on Zero
Running on Zero
File size: 1,851 Bytes
36fc86c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import importlib
import engine.prompt as prompt_module
def _reload_with_prompt_path(monkeypatch, tmp_path, initial_text):
prompt_path = tmp_path / "translation_prompt.txt"
prompt_path.write_text(initial_text, encoding="utf-8")
monkeypatch.setattr(prompt_module, "PROMPT_PATH", prompt_path)
monkeypatch.setattr(prompt_module, "_DEFAULT_PROMPT", initial_text)
return prompt_path
def test_read_prompt_returns_file_contents(monkeypatch, tmp_path):
_reload_with_prompt_path(monkeypatch, tmp_path, "default prompt text")
assert prompt_module.read_prompt() == "default prompt text"
def test_save_prompt_persists_to_file(monkeypatch, tmp_path):
path = _reload_with_prompt_path(monkeypatch, tmp_path, "default prompt text")
prompt_module.save_prompt("edited prompt text")
assert path.read_text(encoding="utf-8") == "edited prompt text"
assert prompt_module.read_prompt() == "edited prompt text"
def test_reset_prompt_restores_default_and_writes_file(monkeypatch, tmp_path):
path = _reload_with_prompt_path(monkeypatch, tmp_path, "default prompt text")
prompt_module.save_prompt("edited prompt text")
result = prompt_module.reset_prompt()
assert result == "default prompt text"
assert path.read_text(encoding="utf-8") == "default prompt text"
def test_read_prompt_falls_back_to_default_when_file_missing(monkeypatch, tmp_path):
path = _reload_with_prompt_path(monkeypatch, tmp_path, "default prompt text")
path.unlink()
assert prompt_module.read_prompt() == "default prompt text"
def test_default_prompt_file_exists_and_is_nonempty():
# sanity check on the real shipped translation_prompt.txt, independent of monkeypatching above
importlib.reload(prompt_module)
assert prompt_module.PROMPT_PATH.exists()
assert len(prompt_module.read_prompt().strip()) > 0
|