Coverage for src / server_list / spec / db_config.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-31 11:45 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-31 11:45 +0000
1#!/usr/bin/env python3
2"""
3Database path management module.
5Provides centralized management of database paths with getter/setter pattern
6for testability. Each module can import the specific getter/setter it needs.
8Example usage:
9 from server_list.spec.db_config import (
10 get_server_data_db_path,
11 set_server_data_db_path,
12 )
14 # In test
15 set_server_data_db_path(temp_path / "test.db")
16"""
18from dataclasses import dataclass, field
19from pathlib import Path
21from server_list.spec.db import CACHE_DB, CONFIG_PATH, CPU_SPEC_DB, SERVER_DATA_DB
24@dataclass
25class _DbPaths:
26 """Internal container for database paths.
28 This class is not exported; use the getter/setter functions instead.
29 """
31 server_data: Path = field(default_factory=lambda: SERVER_DATA_DB)
32 cpu_spec: Path = field(default_factory=lambda: CPU_SPEC_DB)
33 cache: Path = field(default_factory=lambda: CACHE_DB)
34 config: Path = field(default_factory=lambda: CONFIG_PATH)
37_paths = _DbPaths()
40# Server data database (VM info, host info, etc.)
41def get_server_data_db_path() -> Path:
42 """Get the server data database path."""
43 return _paths.server_data
46def set_server_data_db_path(path: Path) -> None:
47 """Set the server data database path (for testing)."""
48 _paths.server_data = path
51# CPU spec database (benchmark scores)
52def get_cpu_spec_db_path() -> Path:
53 """Get the CPU spec database path."""
54 return _paths.cpu_spec
57def set_cpu_spec_db_path(path: Path) -> None:
58 """Set the CPU spec database path (for testing)."""
59 _paths.cpu_spec = path
62# Cache database (config cache)
63def get_cache_db_path() -> Path:
64 """Get the cache database path."""
65 return _paths.cache
68def set_cache_db_path(path: Path) -> None:
69 """Set the cache database path (for testing)."""
70 _paths.cache = path
73# Config file path
74def get_config_path() -> Path:
75 """Get the config file path."""
76 return _paths.config
79def set_config_path(path: Path) -> None:
80 """Set the config file path (for testing)."""
81 _paths.config = path
84def reset_all_paths() -> None:
85 """Reset all paths to defaults (for testing cleanup)."""
86 global _paths
87 _paths = _DbPaths()