Test that an error is thrown when a state yields an invalid value. Args: token: A token. mock_base_state_event_processor: The event processor.
(
token: str,
mock_base_state_event_processor: BaseStateEventProcessor,
)
| 1772 | |
| 1773 | @pytest.mark.asyncio |
| 1774 | async def test_state_with_invalid_yield( |
| 1775 | token: str, |
| 1776 | mock_base_state_event_processor: BaseStateEventProcessor, |
| 1777 | ): |
| 1778 | """Test that an error is thrown when a state yields an invalid value. |
| 1779 | |
| 1780 | Args: |
| 1781 | token: A token. |
| 1782 | mock_base_state_event_processor: The event processor. |
| 1783 | """ |
| 1784 | |
| 1785 | class StateWithInvalidYield(BaseState): |
| 1786 | """A state that yields an invalid value.""" |
| 1787 | |
| 1788 | def invalid_handler(self): |
| 1789 | """Invalid handler. |
| 1790 | |
| 1791 | Yields: |
| 1792 | an invalid value. |
| 1793 | """ |
| 1794 | yield 1 |
| 1795 | |
| 1796 | captured_exceptions: list[Exception] = [] |
| 1797 | |
| 1798 | def capture_exception(ex: Exception) -> None: |
| 1799 | captured_exceptions.append(ex) |
| 1800 | |
| 1801 | mock_base_state_event_processor.backend_exception_handler = capture_exception |
| 1802 | |
| 1803 | event = Event( |
| 1804 | name=f"{StateWithInvalidYield.get_full_name()}.invalid_handler", |
| 1805 | payload={}, |
| 1806 | ) |
| 1807 | async with mock_base_state_event_processor as processor: |
| 1808 | await processor.enqueue(token, event) |
| 1809 | |
| 1810 | assert len(captured_exceptions) == 1 |
| 1811 | assert isinstance(captured_exceptions[0], TypeError) |
| 1812 | assert "must only return/yield: None, Events or other EventHandlers" in str( |
| 1813 | captured_exceptions[0] |
| 1814 | ) |
| 1815 | |
| 1816 | |
| 1817 | @pytest.fixture |
nothing calls this directly
no test coverage detected