示例#1
0
async def test_service_call(hass):
    """Test calling a service using the entity_id as a property."""
    with patch(
        "custom_components.pyscript.state.async_get_all_descriptions",
        return_value={
            "test": {
                "test": {"description": None, "fields": {"entity_id": "blah", "other_service_data": "blah"}}
            }
        },
    ), patch.object(hass.states, "get", return_value=HassState("test.entity", "True")), patch.object(
        hass.services, "async_call"
    ) as call:
        State.init(hass)
        await State.get_service_params()

        func = State.get("test.entity.test")
        await func(context=Context(id="test"), blocking=True, limit=1, other_service_data="test")
        assert call.called
        assert call.call_args[0] == (
            "test",
            "test",
            {"other_service_data": "test", "entity_id": "test.entity"},
        )
        assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1}
        call.reset_mock()

        func = State.get("test.entity.test")
        await func(context=Context(id="test"), blocking=False, other_service_data="test")
        assert call.called
        assert call.call_args[0] == (
            "test",
            "test",
            {"other_service_data": "test", "entity_id": "test.entity"},
        )
        assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
示例#2
0
async def test_eval(hass):
    """Test interpreter."""
    hass.data[DOMAIN] = MockConfigEntry(domain=DOMAIN, data={CONF_ALLOW_ALL_IMPORTS: False})
    Function.init(hass)
    State.init(hass)
    State.register_functions()

    for test_data in evalTests:
        await run_one_test(test_data)
示例#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
async def test_misc_errors(hass, caplog):
    """Test miscellaneous errors."""

    await setup_script(hass, None, dt(2020, 7, 1, 11, 59, 59, 999999), "")

    Function()
    GlobalContextMgr()
    State()
    Event()
    Event.notify_del("not_in_notify_list", None)
    trigger.TrigTime()

    assert "Function class is not meant to be instantiated" in caplog.text
    assert "GlobalContextMgr class is not meant to be instantiated" in caplog.text
    assert "State class is not meant to be instantiated" in caplog.text
    assert "Event class is not meant to be instantiated" in caplog.text
    assert "TrigTime class is not meant to be instantiated" in caplog.text