- 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 новых).
21 lines
659 B
Python
21 lines
659 B
Python
"""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: ...
|