Files
nifodea/tests/conftest.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

84 lines
2.4 KiB
Python

from uuid import uuid4
import pytest
from domain import (
Account,
Asset,
CurrencyConverter,
ExchangeRate,
FinancialModel,
Liability,
RecurringCashflow,
Transaction,
)
@pytest.fixture(scope="session", autouse=True)
def _preserve_stored_model():
"""CLI-тесты пишут в настоящий data/model.json — вернуть его после прогона."""
from pathlib import Path
path = Path("data/model.json")
backup = path.read_bytes() if path.exists() else None
yield
if backup is None:
if path.exists():
path.unlink()
else:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(backup)
@pytest.fixture
def sample_model() -> FinancialModel:
acc_id = uuid4()
return FinancialModel(
base_currency="RUB",
accounts=[
Account(id=acc_id, name="Основной счёт", currency="RUB", balance=5000.0),
Account(name="Сбережения", currency="RUB", balance=10000.0),
],
transactions=[
Transaction(
date="2026-01-01", account=str(acc_id),
category="income", amount=3000.0,
description="Зарплата",
),
Transaction(
date="2026-01-05", account=str(acc_id),
category="rent", amount=-1200.0,
description="Аренда",
),
],
recurring=[
RecurringCashflow(
start_date="2026-01-01", frequency="monthly",
amount=500.0, category="income",
),
RecurringCashflow(
start_date="2026-01-01", frequency="monthly",
amount=-200.0, category="subscription",
),
],
assets=[
Asset(name="Акции", value=50000.0, growth_rate=8.0),
],
liabilities=[
Liability(name="Кредит", balance=20000.0, interest=5.0, payment=500.0),
],
exchange_rates=[
ExchangeRate(from_currency="USD", to_currency="RUB", rate=80.0),
],
)
@pytest.fixture
def empty_model() -> FinancialModel:
return FinancialModel()
@pytest.fixture
def sample_converter() -> CurrencyConverter:
return CurrencyConverter([ExchangeRate(from_currency="USD", to_currency="RUB", rate=80.0)])