Files
nifodea/tests/test_repositories.py
T
oqyude cdda703b37 T9: Excel as the model authoring surface
- ExcelRepository: canonical columns with ru/en aliases, date/number normalization
  (Excel dates, DD.MM.YYYY, '1 234,56', currency symbols, parentheses), account
  name->UUID resolution, per-row errors with sheet!row, warnings for formulas
  without cached values, duplicate names and default exchange rates
- ExcelTemplate: skeleton generator (number/date formats, dropdowns for currency,
  frequency en/ru and account, 'Инструкция' sheet); ship data/model_template.xlsx
- CLI: cf template-xlsx [--force]; cf import-xlsx --dry-run with rich error table,
  import writes nothing when the file has errors
- RecurringCashflow.account (empty = all accounts) + name/UUID matching in forecast;
  cf config recurring-add --account, account column in info/recurring-list
- Forecast: runs are idempotent, 'Итог: Баланс' sums all accounts of the last month
- README: 'Сборка модели в Excel' section
- ruff check . clean (9 pre-existing import/line-length findings fixed)
- MetaAgent: T9 archived, req-T9 approved, manifest/checkpoints/state synced

118 tests pass
2026-11-11 15:40:37 +03:00

57 lines
2.0 KiB
Python

from decimal import Decimal
from pathlib import Path
from application.repositories import ModelRepository
from domain import Account, Asset, FinancialModel, Transaction
from infrastructure.repositories import JsonFileRepository
class TestJsonFileRepository:
def test_save_load_roundtrip(self, tmp_path: Path):
repo = JsonFileRepository()
model = FinancialModel(
accounts=[Account(name="Test", balance=Decimal("100.50"))],
transactions=[Transaction(amount=Decimal("33.33"), category="income")],
)
p = tmp_path / "model.json"
repo.save(model, p)
assert p.exists()
loaded = repo.load(p)
assert len(loaded.accounts) == 1
assert loaded.accounts[0].name == "Test"
assert loaded.accounts[0].balance == Decimal("100.50")
assert loaded.transactions[0].amount == Decimal("33.33")
def test_version_field_persisted(self, tmp_path: Path):
repo = JsonFileRepository()
model = FinancialModel()
p = tmp_path / "v.json"
repo.save(model, p)
import json
with open(p) as f:
data = json.load(f)
assert data["version"] == 1
def test_creates_parent_dirs(self, tmp_path: Path):
repo = JsonFileRepository()
model = FinancialModel()
p = tmp_path / "nested" / "dir" / "model.json"
repo.save(model, p)
assert p.exists()
def test_implements_protocol(self):
repo = JsonFileRepository()
assert isinstance(repo, ModelRepository)
def test_decimal_preserved(self, tmp_path: Path):
repo = JsonFileRepository()
model = FinancialModel(
assets=[Asset(name="Stocks", value=Decimal("12345.67"), growth_rate=Decimal("8.5"))]
)
p = tmp_path / "decimal.json"
repo.save(model, p)
loaded = repo.load(p)
assert loaded.assets[0].value == Decimal("12345.67")
assert loaded.assets[0].growth_rate == Decimal("8.5")