6bb7c77692
56 new tests covering previously untested modules: - test_cli.py: memory write/read/append/list + plugin enable/disable + daemon stubs (via CliRunner) - test_chat_history.py: ConversationHistory build_for_api, add_*/clear, _trim_to_budget - test_chat_renderer.py: render_text_response return values, void render_* functions - test_config_dirs.py: bootstrap idempotency, directory/template/vault/db creation - test_plugin_install.py: list_bundled_plugins, read_manifest, install_bundled_plugin - test_utils_paths.py: ensure_dir (nested, idempotent), safe_chmod Total: 171 → 227 passing tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import os
|
|
|
|
|
|
def test_ensure_dir_creates_directory(tmp_path):
|
|
from pyra.utils.paths import ensure_dir
|
|
target = tmp_path / "new_dir"
|
|
result = ensure_dir(target, 0o700)
|
|
assert target.exists()
|
|
assert target.is_dir()
|
|
|
|
|
|
def test_ensure_dir_returns_path(tmp_path):
|
|
from pyra.utils.paths import ensure_dir
|
|
target = tmp_path / "new_dir"
|
|
result = ensure_dir(target)
|
|
assert result == target
|
|
|
|
|
|
def test_ensure_dir_idempotent(tmp_path):
|
|
from pyra.utils.paths import ensure_dir
|
|
target = tmp_path / "existing_dir"
|
|
ensure_dir(target, 0o700)
|
|
ensure_dir(target, 0o700) # should not raise
|
|
assert target.is_dir()
|
|
|
|
|
|
def test_ensure_dir_creates_nested(tmp_path):
|
|
from pyra.utils.paths import ensure_dir
|
|
target = tmp_path / "a" / "b" / "c"
|
|
ensure_dir(target, 0o700)
|
|
assert target.exists()
|
|
|
|
|
|
def test_safe_chmod_sets_permissions(tmp_path):
|
|
from pyra.utils.paths import safe_chmod
|
|
f = tmp_path / "test.txt"
|
|
f.write_text("content")
|
|
safe_chmod(f, 0o600)
|
|
if os.name != "nt":
|
|
assert oct(f.stat().st_mode)[-3:] == "600"
|
|
|
|
|
|
def test_safe_chmod_different_modes(tmp_path):
|
|
from pyra.utils.paths import safe_chmod
|
|
f = tmp_path / "test.txt"
|
|
f.write_text("content")
|
|
safe_chmod(f, 0o644)
|
|
if os.name != "nt":
|
|
assert oct(f.stat().st_mode)[-3:] == "644"
|