from pathlib import Path from domain import FinancialModel from infrastructure.repositories import ExcelRepository, ExcelRepositoryError class TestExcelRepository: def test_export_creates_file(self, sample_model, tmp_path: Path): repo = ExcelRepository() p = tmp_path / "test.xlsx" repo.save(sample_model, p) assert p.exists() def test_export_import_roundtrip(self, sample_model, tmp_path: Path): repo = ExcelRepository() p = tmp_path / "roundtrip.xlsx" repo.save(sample_model, p) loaded = repo.load(p) assert len(loaded.accounts) == len(sample_model.accounts) assert len(loaded.transactions) == len(sample_model.transactions) assert len(loaded.recurring) == len(sample_model.recurring) assert len(loaded.assets) == len(sample_model.assets) assert len(loaded.liabilities) == len(sample_model.liabilities) assert len(loaded.exchange_rates) == len(sample_model.exchange_rates) def test_roundtrip_preserves_base_currency(self, tmp_path: Path): repo = ExcelRepository() model = FinancialModel(base_currency="EUR") p = tmp_path / "eur_model.xlsx" repo.save(model, p) loaded = repo.load(p) assert loaded.base_currency == "EUR" def test_import_missing_file(self): repo = ExcelRepository() try: repo.load("nonexistent.xlsx") assert False, "Expected ExcelRepositoryError" except ExcelRepositoryError: pass def test_export_empty_model(self, tmp_path: Path): repo = ExcelRepository() model = FinancialModel() p = tmp_path / "empty.xlsx" repo.save(model, p) assert p.exists()