示例#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}
    }
示例#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())
示例#3
0
def test_invalid_base_schema(schema):
    """Test base schema validation."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector(schema)
示例#4
0
def test_valid_base_schema(schema):
    """Test base schema validation."""
    selector.validate_selector(schema)
示例#5
0
def test_device_selector_schema(schema):
    """Test device selector."""
    selector.validate_selector({"device": schema})
示例#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)
示例#7
0
def test_text_selector_schema(schema):
    """Test text selector."""
    selector.validate_selector({"text": schema})
示例#8
0
def test_object_selector_schema(schema):
    """Test object selector."""
    selector.validate_selector({"object": schema})
示例#9
0
def test_number_selector_schema_error(schema):
    """Test number selector."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector({"number": schema})
示例#10
0
def test_target_selector_schema(schema):
    """Test target selector."""
    selector.validate_selector({"target": schema})
示例#11
0
def test_time_selector_schema(schema):
    """Test time selector."""
    selector.validate_selector({"time": schema})
示例#12
0
def test_boolean_selector_schema(schema):
    """Test boolean selector."""
    selector.validate_selector({"boolean": schema})
示例#13
0
def test_number_selector_schema(schema):
    """Test number selector."""
    selector.validate_selector({"number": schema})
示例#14
0
def test_area_selector_schema(schema):
    """Test area selector."""
    selector.validate_selector({"area": schema})
示例#15
0
def test_entity_selector_schema(schema):
    """Test entity selector."""
    selector.validate_selector({"entity": schema})
示例#16
0
def test_select_selector_schema_error(schema):
    """Test select selector."""
    with pytest.raises(vol.Invalid):
        selector.validate_selector({"select": schema})
示例#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})