Beispiel #1
0
def _test_selector(
    selector_type, schema, valid_selections, invalid_selections, converter=None
):
    """Help test a selector."""

    def default_converter(x):
        return x

    if converter is None:
        converter = default_converter

    # Validate selector configuration
    selector.validate_selector({selector_type: schema})

    # Use selector in schema and validate
    vol_schema = vol.Schema({"selection": selector.selector({selector_type: schema})})
    for selection in valid_selections:
        assert vol_schema({"selection": selection}) == {
            "selection": converter(selection)
        }
    for selection in invalid_selections:
        with pytest.raises(vol.Invalid):
            vol_schema({"selection": selection})

    # Serialize selector
    selector_instance = selector.selector({selector_type: schema})
    assert cv.custom_serializer(selector_instance) == {
        "selector": {selector_type: selector_instance.config}
    }
Beispiel #2
0
def _test_selector(
    selector_type, schema, valid_selections, invalid_selections, converter=None
):
    """Help test a selector."""

    def default_converter(x):
        return x

    if converter is None:
        converter = default_converter

    # Validate selector configuration
    config = {selector_type: schema}
    selector.validate_selector(config)
    selector_instance = selector.selector(config)
    # We do not allow enums in the config, as they cannot serialize
    assert not any(isinstance(val, Enum) for val in selector_instance.config.values())

    # Use selector in schema and validate
    vol_schema = vol.Schema({"selection": selector_instance})
    for selection in valid_selections:
        assert vol_schema({"selection": selection}) == {
            "selection": converter(selection)
        }
    for selection in invalid_selections:
        with pytest.raises(vol.Invalid):
            vol_schema({"selection": selection})

    # Serialize selector
    selector_instance = selector.selector({selector_type: schema})
    assert (
        selector.selector(selector_instance.serialize()["selector"]).config
        == selector_instance.config
    )
    # Test serialized selector can be dumped to YAML
    yaml.dump(selector_instance.serialize())
Beispiel #3
0
def test_invalid_base_schema(schema):
    """Test base schema validation."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector(schema)
Beispiel #4
0
def test_valid_base_schema(schema):
    """Test base schema validation."""
    selector.validate_selector(schema)
Beispiel #5
0
def test_device_selector_schema(schema):
    """Test device selector."""
    selector.validate_selector({"device": schema})
Beispiel #6
0
def test_validate_selector():
    """Test return is the same as input."""
    schema = {"device": {"manufacturer": "mock-manuf", "model": "mock-model"}}
    assert schema == selector.validate_selector(schema)
Beispiel #7
0
def test_text_selector_schema(schema):
    """Test text selector."""
    selector.validate_selector({"text": schema})
Beispiel #8
0
def test_object_selector_schema(schema):
    """Test object selector."""
    selector.validate_selector({"object": schema})
Beispiel #9
0
def test_number_selector_schema_error(schema):
    """Test number selector."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector({"number": schema})
Beispiel #10
0
def test_target_selector_schema(schema):
    """Test target selector."""
    selector.validate_selector({"target": schema})
Beispiel #11
0
def test_time_selector_schema(schema):
    """Test time selector."""
    selector.validate_selector({"time": schema})
Beispiel #12
0
def test_boolean_selector_schema(schema):
    """Test boolean selector."""
    selector.validate_selector({"boolean": schema})
Beispiel #13
0
def test_number_selector_schema(schema):
    """Test number selector."""
    selector.validate_selector({"number": schema})
Beispiel #14
0
def test_area_selector_schema(schema):
    """Test area selector."""
    selector.validate_selector({"area": schema})
Beispiel #15
0
def test_entity_selector_schema(schema):
    """Test entity selector."""
    selector.validate_selector({"entity": schema})
Beispiel #16
0
def test_select_selector_schema_error(schema):
    """Test select selector."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector({"select": schema})
Beispiel #17
0
def test_action_selector_schema(schema):
    """Test action sequence selector."""
    selector.validate_selector({"action": schema})
def test_addon_selector_schema(schema):
    """Test add-on selector."""
    selector.validate_selector({"addon": schema})