Test that the default handler of a dynamic generated var works as expected. Args: test_state: State Fixture. mock_base_state_event_processor: BaseStateEventProcessor Fixture. emitted_deltas: List to store emitted deltas. token: a Token. clean_registra
(
test_state: type[ATestState],
mock_base_state_event_processor: BaseStateEventProcessor,
emitted_deltas: list[tuple[str, dict[str, dict[str, Any]]]],
token: str,
clean_registration_context: RegistrationContext,
)
| 526 | |
| 527 | @pytest.mark.asyncio |
| 528 | async def test_dynamic_var_event( |
| 529 | test_state: type[ATestState], |
| 530 | mock_base_state_event_processor: BaseStateEventProcessor, |
| 531 | emitted_deltas: list[tuple[str, dict[str, dict[str, Any]]]], |
| 532 | token: str, |
| 533 | clean_registration_context: RegistrationContext, |
| 534 | ): |
| 535 | """Test that the default handler of a dynamic generated var |
| 536 | works as expected. |
| 537 | |
| 538 | Args: |
| 539 | test_state: State Fixture. |
| 540 | mock_base_state_event_processor: BaseStateEventProcessor Fixture. |
| 541 | emitted_deltas: List to store emitted deltas. |
| 542 | token: a Token. |
| 543 | clean_registration_context: The registration context fixture, which is cleared before each test. |
| 544 | """ |
| 545 | clean_registration_context.register_base_state(test_state) |
| 546 | state = test_state() # pyright: ignore [reportCallIssue] |
| 547 | state.add_var("int_val", int, 0) |
| 548 | |
| 549 | def set_int_val(self, value: int): |
| 550 | self.int_val = value |
| 551 | |
| 552 | state._add_event_handler("set_int_val", set_int_val) |
| 553 | async with mock_base_state_event_processor as processor: |
| 554 | await processor.enqueue( |
| 555 | token, |
| 556 | Event( |
| 557 | name=f"{test_state.get_name()}.set_int_val", |
| 558 | payload={"value": 50}, |
| 559 | ), |
| 560 | ) |
| 561 | assert emitted_deltas == [ |
| 562 | (token, {test_state.get_name(): {"int_val" + FIELD_MARKER: 50}}) |
| 563 | ] |
| 564 | |
| 565 | |
| 566 | @pytest.fixture |
nothing calls this directly
no test coverage detected