コード例 #1
0
def test_extract_inputs():
    """Test extracting inputs from data."""
    assert extract_inputs(Input("hello")) == {"hello"}
    assert extract_inputs({"info": [1, Input("hello"), 2, Input("world")]}) == {
        "hello",
        "world",
    }
コード例 #2
0
def test_substitute():
    """Test we can substitute."""
    assert substitute(Input("hello"), {"hello": 5}) == 5

    with pytest.raises(UndefinedSubstitution):
        substitute(Input("hello"), {})

    assert (
        substitute(
            {"info": [1, Input("hello"), 2, Input("world")]},
            {"hello": 5, "world": 10},
        )
        == {"info": [1, 5, 2, 10]}
    )
コード例 #3
0
def test_blueprint_model_init():
    """Test constructor validation."""
    with pytest.raises(errors.InvalidBlueprint):
        models.Blueprint({})

    with pytest.raises(errors.InvalidBlueprint):
        models.Blueprint(
            {"blueprint": {
                "name": "Hello",
                "domain": "automation"
            }},
            expected_domain="not-automation",
        )

    with pytest.raises(errors.InvalidBlueprint):
        models.Blueprint({
            "blueprint": {
                "name": "Hello",
                "domain": "automation",
                "input": {
                    "something": None
                },
            },
            "trigger": {
                "platform": Input("non-existing")
            },
        })
コード例 #4
0
def blueprint_2():
    """Blueprint fixture with default inputs."""
    return models.Blueprint(
        {
            "blueprint": {
                "name": "Hello",
                "domain": "automation",
                "source_url": "https://github.com/balloob/home-assistant-config/blob/main/blueprints/automation/motion_light.yaml",
                "input": {
                    "test-input": {"name": "Name", "description": "Description"},
                    "test-input-default": {"default": "test"},
                },
            },
            "example": Input("test-input"),
            "example-default": Input("test-input-default"),
        }
    )