Test infrastructure with conftest fixtures mocking run_shell_args/run_adb for device-free testing across all 8 mixins. Fixed: UI parser regex couldn't match hyphenated XML attributes (content-desc, resource-id). Notification parser captured trailing parenthesis in package names.
79 lines
2.8 KiB
Python
79 lines
2.8 KiB
Python
"""Tests for configuration management."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from src.config import get_config, is_developer_mode
|
|
|
|
|
|
def _fresh_config(monkeypatch, config_dir):
|
|
"""Reset singleton and point Config at a specific directory."""
|
|
config_path = Path(config_dir)
|
|
monkeypatch.setattr("src.config.Config._instance", None)
|
|
monkeypatch.setattr("src.config.CONFIG_DIR", config_path)
|
|
monkeypatch.setattr("src.config.CONFIG_FILE", config_path / "config.json")
|
|
|
|
|
|
class TestConfig:
|
|
def test_defaults(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
assert config.developer_mode is False
|
|
assert config.auto_select_single_device is True
|
|
assert config.default_screenshot_dir is None
|
|
|
|
def test_developer_mode_toggle(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
assert config.developer_mode is False
|
|
config.developer_mode = True
|
|
assert config.developer_mode is True
|
|
|
|
def test_persistence(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
config.developer_mode = True
|
|
|
|
config_file = tmp_path / "config.json"
|
|
assert config_file.exists()
|
|
data = json.loads(config_file.read_text())
|
|
assert data["developer_mode"] is True
|
|
|
|
def test_screenshot_dir(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
config.default_screenshot_dir = "/tmp/shots"
|
|
assert config.default_screenshot_dir == "/tmp/shots"
|
|
|
|
def test_get_set(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
config.set("custom_key", "custom_value")
|
|
assert config.get("custom_key") == "custom_value"
|
|
|
|
def test_to_dict(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
config = get_config()
|
|
d = config.to_dict()
|
|
assert "developer_mode" in d
|
|
assert "auto_select_single_device" in d
|
|
|
|
def test_load_corrupt_file(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
(tmp_path / "config.json").write_text("{invalid json")
|
|
# Need a fresh singleton to trigger _load with corrupt file
|
|
monkeypatch.setattr("src.config.Config._instance", None)
|
|
config = get_config()
|
|
assert config.developer_mode is False
|
|
|
|
|
|
class TestIsDeveloperMode:
|
|
def test_off_by_default(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
assert is_developer_mode() is False
|
|
|
|
def test_on_when_enabled(self, tmp_path, monkeypatch):
|
|
_fresh_config(monkeypatch, tmp_path)
|
|
get_config().developer_mode = True
|
|
assert is_developer_mode() is True
|