40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from pathlib import Path
|
|
|
|
from cashflow_model import FinancialModel
|
|
from sync.excel_sync import ExcelSync, SyncError
|
|
|
|
|
|
class TestExcelSync:
|
|
def test_export_creates_file(self, sample_model, tmp_path: Path):
|
|
sync = ExcelSync()
|
|
p = tmp_path / "test.xlsx"
|
|
sync.export_model(sample_model, p)
|
|
assert p.exists()
|
|
|
|
def test_export_import_roundtrip(self, sample_model, tmp_path: Path):
|
|
sync = ExcelSync()
|
|
p = tmp_path / "roundtrip.xlsx"
|
|
sync.export_model(sample_model, p)
|
|
|
|
loaded = sync.import_model(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)
|
|
|
|
def test_import_missing_file(self):
|
|
sync = ExcelSync()
|
|
try:
|
|
sync.import_model("nonexistent.xlsx")
|
|
assert False, "Expected SyncError"
|
|
except SyncError:
|
|
pass
|
|
|
|
def test_export_empty_model(self, tmp_path: Path):
|
|
sync = ExcelSync()
|
|
model = FinancialModel()
|
|
p = tmp_path / "empty.xlsx"
|
|
sync.export_model(model, p)
|
|
assert p.exists()
|