示例#1
0
def test_timer_active_check(hass, spec, now, expected):
    """Run time active check tests."""

    Function.init(hass)
    TrigTime.init(hass)
    out = TrigTime.timer_active_check(spec, now)
    assert out == expected
示例#2
0
async def test_parse_date_time(hass, caplog):
    """Run time parse datetime tests."""

    #
    # Hardcode a location and timezone so we can check sunrise
    # and sunset.
    #
    hass.config.latitude = 38
    hass.config.longitude = -122
    hass.config.elevation = 0
    hass.config.time_zone = "America/Los_Angeles"

    Function.init(hass)
    TrigTime.init(hass)

    #
    # This set of tests assumes it's currently 13:00 on 2019/9/1
    #
    now = dt(2019, 9, 1, 13, 0, 0, 0)

    with patch("homeassistant.helpers.condition.dt_util.utcnow",
               return_value=now), patch("homeassistant.util.dt.utcnow",
                                        return_value=now):
        for test_data in parseDateTimeTests:
            spec, date_offset, expect = test_data
            out = TrigTime.parse_date_time(spec, date_offset, now)
            assert out == expect
示例#3
0
async def test_eval_exceptions(hass):
    """Test interpreter exceptions."""
    hass.data[DOMAIN] = {CONFIG_ENTRY: MockConfigEntry(domain=DOMAIN, data={CONF_ALLOW_ALL_IMPORTS: False})}
    Function.init(hass)
    State.init(hass)
    State.register_functions()
    TrigTime.init(hass)

    for test_data in evalTestsExceptions:
        await run_one_test_exception(test_data)
示例#4
0
def test_timer_trigger_next_month_rollover(hass):
    """Run month rollover tests."""

    Function.init(hass)
    TrigTime.init(hass)

    for test_data in timerTriggerNextTestsMonthRollover:
        now = dt(2020, 6, 30, 13, 0, 0, 100000)
        spec, expect_seq = test_data
        for expect in expect_seq:
            t_next = TrigTime.timer_trigger_next(spec, now)
            assert t_next == expect
            now = t_next
示例#5
0
def test_timer_active_check(hass, spec, now, expected):
    """Run time active check tests."""

    #
    # Hardcode a location and timezone so we can check sunrise
    # and sunset.
    #
    hass.config.latitude = 38
    hass.config.longitude = -122
    hass.config.elevation = 0
    hass.config.time_zone = "America/Los_Angeles"

    startup_time = dt(2019, 9, 1, 13, 0, 0, 0)
    Function.init(hass)
    TrigTime.init(hass)
    print(f"calling timer_active_check({spec}, {now}, {startup_time})")
    out = TrigTime.timer_active_check(spec, now, startup_time)
    assert out == expected
示例#6
0
def test_timer_trigger_next(hass):
    """Run trigger next tests."""
    #
    # Hardcode a location and timezone so we can check sunrise
    # and sunset.
    #
    hass.config.latitude = 38
    hass.config.longitude = -122
    hass.config.elevation = 0
    hass.config.time_zone = "America/Los_Angeles"

    Function.init(hass)
    TrigTime.init(hass)

    for test_data in timerTriggerNextTests:
        now = dt(2019, 9, 1, 13, 0, 0, 100000)
        spec, expect_seq = test_data
        for expect in expect_seq:
            t_next = TrigTime.timer_trigger_next(spec, now)
            assert t_next == expect
            now = t_next
示例#7
0
def test_timer_trigger_next(hass):
    """Run trigger next tests."""
    #
    # Hardcode a location and timezone so we can check sunrise
    # and sunset.
    #
    hass.config.latitude = 38
    hass.config.longitude = -122
    hass.config.elevation = 0
    hass.config.time_zone = "America/Los_Angeles"

    Function.init(hass)
    TrigTime.init(hass)

    for test_data in timerTriggerNextTests:
        startup_time = now = dt(2019, 9, 1, 13, 0, 0, 100000)
        spec, expect_seq = test_data
        for expect in expect_seq:
            print(f"calling timer_trigger_next({spec}, {now}, {startup_time})")
            t_next = TrigTime.timer_trigger_next(spec, now, startup_time)
            assert t_next == expect
            if t_next is None:
                break
            now = t_next + timedelta(microseconds=1)