Files
rk35xx-android14/external/python/pyee/tests/test_executor.py
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

62 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
from time import sleep
from mock import Mock
from pyee import ExecutorEventEmitter
class PyeeTestError(Exception):
pass
def test_executor_emit():
"""Test that ExecutorEventEmitters can emit events."""
with ExecutorEventEmitter() as ee:
should_call = Mock()
@ee.on("event")
def event_handler():
should_call(True)
ee.emit("event")
sleep(0.1)
should_call.assert_called_once()
def test_executor_once():
"""Test that ExecutorEventEmitters also emit events for once."""
with ExecutorEventEmitter() as ee:
should_call = Mock()
@ee.once("event")
def event_handler():
should_call(True)
ee.emit("event")
sleep(0.1)
should_call.assert_called_once()
def test_executor_error():
"""Test that ExecutorEventEmitters handle errors."""
with ExecutorEventEmitter() as ee:
should_call = Mock()
@ee.on("event")
def event_handler():
raise PyeeTestError()
@ee.on("error")
def handle_error(e):
should_call(e)
ee.emit("event")
sleep(0.1)
should_call.assert_called_once()