Загрузка данных
в редж для инпутов:
lambda parsed: parsed.replyContent.inputSignals,
)
with allure.step(f"Проверка результата отбраковки датчика {sensor.description} (id={sensor.id})"):
with SoftAssertions() as soft_failures:
StepCheck(
f"Проверка отбраковки датчика {sensor.description} (id={sensor.id})", "isRejected", soft_failures
).actual(target_signal.isRejected).expected(True).equal_to()
if rejection_case.expected_criteria_names:
raw_criteria = (
target_signal.rejection.get(TestConst.CRITERIA_NAMES_FIELD)
if isinstance(target_signal.rejection, dict)
else None
)
criteria = RejectionCriteria(raw_criteria) if raw_criteria is not None else None
StepCheck(
f"Проверка rejection.criteriaNames для {sensor.description} (id={sensor.id})",
TestConst.CRITERIA_NAMES_FIELD,
soft_failures,
).actual(criteria).expected(rejection_case.expected_criteria_names).equal_to()
для схема сигнал стейт
finally:
ws_client.suppress_recv_logging = False
parser.suppress_recv_logging = False
with allure.step(f"Проверка результата отбраковки датчика {sensor.description} (id={sensor.id})"):
with SoftAssertions() as soft_failures:
StepCheck(f"Проверка isRejected для {sensor.description} (id={sensor.id})", "isRejected", soft_failures).actual(
target_signal.isRejected
).expected(rejection_case.expected_is_rejected).equal_to()
StepCheck(f"Проверка isMasked для {sensor.description} (id={sensor.id})", "isMasked", soft_failures).actual(
target_signal.isMasked
).expected(False).equal_to()
StepCheck(f"Проверка isImitated для {sensor.description} (id={sensor.id})", "isImitated", soft_failures).actual(
target_signal.isImitated
).expected(False).equal_to()
if rejection_case.expected_criteria_names and target_signal.rejection is not None:
raw_criteria = (
target_signal.rejection.get(TestConst.CRITERIA_NAMES_FIELD)
if isinstance(target_signal.rejection, dict)
else None
)
criteria = RejectionCriteria(raw_criteria) if raw_criteria is not None else None
StepCheck(
f"Проверка rejection.criteriaNames для {sensor.description} (id={sensor.id})",
TestConst.CRITERIA_NAMES_FIELD,
soft_failures,
).actual(criteria).expected(rejection_case.expected_criteria_names).equal_to()
генератор
async def _receive_subscribed_messages(
ws_client: WebSocketClient,
ws_message_type: str,
ws_invoke_type: str,
ws_invoke_params: Any,
*,
attempts: int,
per_attempt_timeout: float,
) -> AsyncIterator[list]:
"""
Генератор сообщений подписки: подписывается и последовательно отдаёт сообщения
нужного типа. При таймауте или обрыве соединения переподключается и подписывается
заново, продолжая попытки до attempts. После исчерпания попыток генератор просто
завершается — итоговую ошибку формирует вызывающая функция.
"""
needs_subscribe = True
for attempt in range(1, attempts + 1):
try:
if needs_subscribe:
await connect(ws_client, ws_invoke_type, ws_invoke_params)
needs_subscribe = False
with allure.step(
f"Получение сообщения с контентом типа: {ws_message_type} - попытка {attempt} из {attempts}"
):
message = await ws_client.receive_by_type(ws_message_type, timeout=per_attempt_timeout)
except asyncio.TimeoutError:
await ws_client.reconnect()
needs_subscribe = True
continue
except Exception:
await ws_client.reconnect()
needs_subscribe = True
continue
yield message