示例#1
0
async def test_event_update(u: UpdatedTime):
    m = MagicMock()
    u.set(pd_now(UTC))
    list = HABApp.core.EventBusListener(
        'test', HABApp.core.WrappedFunction(m, name='MockFunc'))
    HABApp.core.EventBus.add_listener(list)

    u.set(pd_now(UTC))
    await asyncio.sleep(1)
    m.assert_not_called()

    await asyncio.sleep(0.1)
    m.assert_called_once()

    c = m.call_args[0][0]
    assert isinstance(c, HABApp.core.events.ItemNoUpdateEvent)
    assert c.name == 'test'
    assert c.seconds == 1

    await asyncio.sleep(2)
    assert m.call_count == 2

    c = m.call_args[0][0]
    assert isinstance(c, HABApp.core.events.ItemNoUpdateEvent)
    assert c.name == 'test'
    assert c.seconds == 3

    list.cancel()
示例#2
0
async def test_cancel_running(u: UpdatedTime):
    u.set(datetime.now(tz=pytz.utc))

    w1 = u.tasks[0]
    w2 = u.tasks[1]

    await asyncio.sleep(1.1)
    assert w1._task.done()
    assert not w2._task.done()

    assert w2 in u.tasks
    w2.cancel()
    u.set(datetime.now(tz=pytz.utc))
    await asyncio.sleep(0.05)
    assert w2 not in u.tasks
示例#3
0
async def test_cancel_running(u: UpdatedTime):
    u.set(pd_now(UTC))

    w1 = u.tasks[0]
    w2 = u.tasks[1]

    await asyncio.sleep(1.1)
    assert w1.fut.task.done()
    assert not w2.fut.task.done()

    assert w2 in u.tasks
    w2.cancel()
    await asyncio.sleep(0.05)
    u.set(pd_now(UTC))
    await asyncio.sleep(0.05)
    assert w2 not in u.tasks