test: add tests
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"""Tests for paperlib configuration."""
|
||||
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from paperlib.config import LibraryPaths
|
||||
|
||||
|
||||
class TestLibraryPaths:
|
||||
"""Test LibraryPaths configuration."""
|
||||
|
||||
def test_from_root(self):
|
||||
"""Test creating LibraryPaths from root directory."""
|
||||
root = Path("./.tmp/test_config")
|
||||
paths = LibraryPaths.from_root(root)
|
||||
|
||||
# Check root path
|
||||
assert paths.root == root.resolve()
|
||||
|
||||
# Check default subdirectories
|
||||
assert paths.config_dir == root.resolve() / "config"
|
||||
assert paths.papers_dir == root.resolve() / "papers"
|
||||
assert paths.inbox_dir == root.resolve() / "inbox"
|
||||
assert paths.db_dir == root.resolve() / "db"
|
||||
assert paths.cache_dir == root.resolve() / "cache"
|
||||
|
||||
# Check specific files
|
||||
assert paths.db_path == root.resolve() / "db" / "paperlib.sqlite3"
|
||||
assert paths.config_path == root.resolve() / "config" / "config.toml"
|
||||
|
||||
def test_create_directories(self):
|
||||
"""Test creating library directory structure."""
|
||||
root = Path("./.tmp/test_create_dirs")
|
||||
|
||||
try:
|
||||
paths = LibraryPaths.from_root(root)
|
||||
|
||||
# Directories shouldn't exist initially
|
||||
assert not paths.root.exists()
|
||||
|
||||
# Create directories
|
||||
paths.create_directories()
|
||||
|
||||
# All directories should now exist
|
||||
assert paths.root.exists()
|
||||
assert paths.config_dir.exists()
|
||||
assert paths.papers_dir.exists()
|
||||
assert paths.inbox_dir.exists()
|
||||
assert paths.db_dir.exists()
|
||||
assert paths.cache_dir.exists()
|
||||
|
||||
finally:
|
||||
# Cleanup
|
||||
if root.exists():
|
||||
shutil.rmtree(root)
|
||||
|
||||
def test_expanduser(self):
|
||||
"""Test that ~ is expanded in paths."""
|
||||
# Test with tilde path
|
||||
paths = LibraryPaths.from_root(Path("~/.tmp/test_tilde"))
|
||||
|
||||
# Root should be expanded
|
||||
assert "~" not in str(paths.root)
|
||||
assert paths.root.is_absolute()
|
||||
|
||||
def test_resolve_relative_paths(self):
|
||||
"""Test that relative paths are resolved."""
|
||||
# Use relative path
|
||||
paths = LibraryPaths.from_root(Path("./relative/path"))
|
||||
|
||||
# Should be absolute
|
||||
assert paths.root.is_absolute()
|
||||
assert "relative/path" in str(paths.root)
|
||||
Reference in New Issue
Block a user