generated from john/python-template
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import errno
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -132,3 +133,18 @@ def test_save_runtime_settings_surfaces_unwritable_target(tmp_path: Path, monkey
|
||||
with pytest.raises(AppError) as exc:
|
||||
save_runtime_settings(settings=settings, updates={"port": "9001"}, env_file_path=env_path)
|
||||
assert exc.value.message == "Runtime settings file is not writable."
|
||||
|
||||
|
||||
def test_save_runtime_settings_falls_back_when_atomic_replace_is_unavailable(tmp_path: Path, monkeypatch):
|
||||
settings = _settings_for_runtime_editing(tmp_path)
|
||||
env_path = tmp_path / ".env.production"
|
||||
env_path.write_text("OPENROUTER_API_KEY=test-key\nPORT=8000\n", encoding="utf-8")
|
||||
|
||||
def _replace_cross_device(_self: Path, _target: Path) -> Path:
|
||||
raise OSError(errno.EXDEV, "Invalid cross-device link")
|
||||
|
||||
monkeypatch.setattr(Path, "replace", _replace_cross_device)
|
||||
snapshot = save_runtime_settings(settings=settings, updates={"port": "9001"}, env_file_path=env_path)
|
||||
|
||||
assert snapshot.env_file_path == env_path
|
||||
assert "PORT=9001" in env_path.read_text(encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user