T4: Repository pattern — ModelRepository, JsonFileRepository, ExcelRepository

- application/repositories/model_repository.py: ModelRepository Protocol
  with load(path) and save(model, path)
- infrastructure/repositories/json_file_repository.py: JsonFileRepository
  (вынесен из FinancialModel.save/load)
- infrastructure/repositories/excel_repository.py: ExcelRepository
  (бывший ExcelSync, переименован)
- FinancialModel.save/load удалены — теперь только данные
- infrastructure/sync/ удалён (ExcelSync перенесён в repositories/)
- infrastructure/cli/main.py и config.py используют JsonFileRepository +
  ExcelRepository через локальные singletons
- test_excel_sync.py переименован в test для ExcelRepository
- Новый test_repositories.py: 5 тестов для JsonFileRepository + протокол
- test_model.py: использован JsonFileRepository

Tests: 68/68 pass (было 63 + 5 новых).
This commit is contained in:
2026-10-08 16:50:06 +03:00
parent 363d440d53
commit 3f7268d14c
12 changed files with 190 additions and 92 deletions
+3
View File
@@ -0,0 +1,3 @@
from application.repositories.model_repository import ModelRepository
__all__ = ["ModelRepository"]
@@ -0,0 +1,20 @@
"""Repository protocol для хранения FinancialModel.
Определяет контракт: load(path) -> FinancialModel, save(model, path) -> None.
Реализации: JsonFileRepository, ExcelRepository.
"""
from __future__ import annotations
from pathlib import Path
from typing import Protocol, runtime_checkable
from domain import FinancialModel
@runtime_checkable
class ModelRepository(Protocol):
"""Любой storage, способный прочитать и записать FinancialModel."""
def load(self, path: str | Path) -> FinancialModel: ...
def save(self, model: FinancialModel, path: str | Path) -> None: ...