Example #1
0
async def test_event_change(c: ChangedTime):
    m = MagicMock()
    c.set(pd_now(UTC))
    list = HABApp.core.EventBusListener(
        'test', HABApp.core.WrappedFunction(m, name='MockFunc'))
    HABApp.core.EventBus.add_listener(list)

    c.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.ItemNoChangeEvent)
    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.ItemNoChangeEvent)
    assert c.name == 'test'
    assert c.seconds == 3

    list.cancel()
Example #2
0
def c():
    a = ChangedTime('test', pd_now(UTC))
    w1 = a.add_watch(1)
    w2 = a.add_watch(3)

    yield a

    # cancel the rest of the running tasks
    w1.cancel()
    w2.cancel()
Example #3
0
def c():
    a = ChangedTime('test', datetime.now(tz=pytz.utc))
    w1 = a.add_watch(1)
    w2 = a.add_watch(3)

    yield a

    # cancel the rest of the running tasks
    w1.cancel()
    w2.cancel()