89 lines
3.0 KiB
Python
89 lines
3.0 KiB
Python
"""`FakeEngine` для модульных тестов ядра: возвращает заданные ответы и запоминает вход (часть Б, B1)."""
|
|
|
|
import datetime
|
|
from collections.abc import Mapping, Sequence
|
|
from decimal import Decimal
|
|
from typing import Any
|
|
|
|
from arm_statements import (
|
|
DocStatus,
|
|
DocumentType,
|
|
Edition,
|
|
FormVariant,
|
|
PeriodKind,
|
|
RecomputeResult,
|
|
StatementChecks,
|
|
StoredForm,
|
|
)
|
|
|
|
|
|
def empty_result(status: DocStatus = DocStatus.DONE) -> RecomputeResult:
|
|
"""`RecomputeResult` без нарушений и признаков."""
|
|
return RecomputeResult(
|
|
form_variant=FormVariant.FULL,
|
|
edition=Edition.FSBU4,
|
|
checks=StatementChecks((), ()),
|
|
line_needs_review={},
|
|
value_needs_review={},
|
|
detail_parents={},
|
|
status=status,
|
|
)
|
|
|
|
|
|
class FakeEngine:
|
|
"""Подмена `StatementsEngine`: ответы задаются в конструкторе, вызовы запоминаются."""
|
|
|
|
def __init__( # noqa: PLR0913
|
|
self,
|
|
result: RecomputeResult | None = None,
|
|
*,
|
|
document_status: DocStatus = DocStatus.DONE,
|
|
edition: Edition | None = Edition.FSBU4,
|
|
version: str | None = "fake",
|
|
code_orders: Mapping[tuple[Edition, DocumentType, FormVariant], tuple[str, ...]] | None = None,
|
|
tolerance: Decimal = Decimal(1),
|
|
) -> None:
|
|
self.result = result if result is not None else empty_result()
|
|
self.document_status = document_status
|
|
self.edition_value = edition
|
|
self._version = version
|
|
self.orders = dict(code_orders or {})
|
|
self._tolerance = tolerance
|
|
self.forms: list[StoredForm] = []
|
|
self.edition_calls: list[
|
|
tuple[DocumentType, list[tuple[str, bool]], datetime.date | None, FormVariant | None]
|
|
] = []
|
|
|
|
@property
|
|
def version(self) -> str | None:
|
|
return self._version
|
|
|
|
def recompute(self, form: StoredForm) -> RecomputeResult:
|
|
self.forms.append(form)
|
|
return self.result
|
|
|
|
def contract_document_status(self, document: Mapping[str, Any]) -> DocStatus:
|
|
return self.document_status
|
|
|
|
def edition(
|
|
self,
|
|
document_type: DocumentType,
|
|
codes: Sequence[tuple[str, bool]],
|
|
effective_date: datetime.date | None,
|
|
form_variant: FormVariant | None,
|
|
) -> Edition | None:
|
|
self.edition_calls.append((document_type, list(codes), effective_date, form_variant))
|
|
return self.edition_value
|
|
|
|
def code_order(self, edition: Edition, document_type: DocumentType, form_variant: FormVariant) -> tuple[str, ...]:
|
|
return self.orders.get((edition, document_type, form_variant), ())
|
|
|
|
def editions(self) -> tuple[Edition, ...]:
|
|
return (Edition.RAS_66N, Edition.FSBU4)
|
|
|
|
def resolve_relative(self, kind: PeriodKind, effective_date: datetime.date | None) -> datetime.date | None:
|
|
return None
|
|
|
|
def tolerance(self) -> Decimal:
|
|
return self._tolerance
|