Files
gart/code/tests/test_project_config.py
T

84 lines
3.5 KiB
Python

"""Tests for the last-project settings — the folder/file the app reopens with.
The config file (~/.fcp-mcp-server/config.json) is redirected to a tmp_path
so these never touch the developer's real settings.
"""
import json
import pytest
from fcpxml import model_manager
@pytest.fixture(autouse=True)
def isolated_config(tmp_path, monkeypatch):
"""Point model_manager's config file at a throwaway directory."""
monkeypatch.setattr(model_manager, "_CONFIG_DIR", tmp_path)
monkeypatch.setattr(model_manager, "_CONFIG_FILE", tmp_path / "config.json")
return tmp_path / "config.json"
class TestLoadProjectConfig:
def test_defaults_when_nothing_stored(self):
assert model_manager.load_project_config() == model_manager.DEFAULT_PROJECT_CONFIG
def test_non_dict_stored_value_falls_back(self, isolated_config):
isolated_config.write_text(json.dumps({"project": "nonsense"}))
assert model_manager.load_project_config() == model_manager.DEFAULT_PROJECT_CONFIG
def test_reads_back_what_was_stored(self, tmp_path):
folder = tmp_path / "03 - Mastopexia"
folder.mkdir()
model_manager.save_project_config(folder=str(folder))
assert model_manager.load_project_config()["folder"] == str(folder)
def test_path_that_no_longer_exists_comes_back_empty(self, isolated_config, tmp_path):
"""An unmounted volume must degrade to "nothing selected", not a dead path."""
isolated_config.write_text(json.dumps({"project": {"folder": str(tmp_path / "gone")}}))
assert model_manager.load_project_config()["folder"] == ""
def test_non_string_stored_value_is_ignored(self, isolated_config):
isolated_config.write_text(json.dumps({"project": {"folder": 42}}))
assert model_manager.load_project_config()["folder"] == ""
class TestSaveProjectConfig:
def test_omitted_field_keeps_its_current_value(self, tmp_path):
folder = tmp_path / "projeto"
folder.mkdir()
project = tmp_path / "projeto" / "Mastopexia.fcpxml"
project.write_text("<fcpxml/>")
model_manager.save_project_config(folder=str(folder), file=str(project))
model_manager.save_project_config(file=str(project))
assert model_manager.load_project_config()["folder"] == str(folder)
def test_empty_string_clears_a_field(self, tmp_path):
folder = tmp_path / "projeto"
folder.mkdir()
model_manager.save_project_config(folder=str(folder))
model_manager.save_project_config(folder="")
assert model_manager.load_project_config()["folder"] == ""
def test_home_relative_path_is_expanded(self, isolated_config):
model_manager.save_project_config(folder="~/Movies")
stored = json.loads(isolated_config.read_text())["project"]["folder"]
assert not stored.startswith("~")
def test_does_not_disturb_other_config_sections(self, isolated_config, tmp_path):
isolated_config.write_text(json.dumps({"language": "pt", "selected_model": "large-v3"}))
folder = tmp_path / "projeto"
folder.mkdir()
model_manager.save_project_config(folder=str(folder))
data = json.loads(isolated_config.read_text())
assert data["language"] == "pt"
assert data["selected_model"] == "large-v3"
def test_returns_the_merged_config(self, tmp_path):
folder = tmp_path / "projeto"
folder.mkdir()
assert model_manager.save_project_config(folder=str(folder)) == {
"folder": str(folder),
"file": "",
}