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"