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} }
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())
def test_invalid_base_schema(schema): """Test base schema validation.""" with pytest.raises(vol.Invalid): selector.validate_selector(schema)
def test_valid_base_schema(schema): """Test base schema validation.""" selector.validate_selector(schema)
def test_device_selector_schema(schema): """Test device selector.""" selector.validate_selector({"device": schema})
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)
def test_text_selector_schema(schema): """Test text selector.""" selector.validate_selector({"text": schema})
def test_object_selector_schema(schema): """Test object selector.""" selector.validate_selector({"object": schema})
def test_number_selector_schema_error(schema): """Test number selector.""" with pytest.raises(vol.Invalid): selector.validate_selector({"number": schema})
def test_target_selector_schema(schema): """Test target selector.""" selector.validate_selector({"target": schema})
def test_time_selector_schema(schema): """Test time selector.""" selector.validate_selector({"time": schema})
def test_boolean_selector_schema(schema): """Test boolean selector.""" selector.validate_selector({"boolean": schema})
def test_number_selector_schema(schema): """Test number selector.""" selector.validate_selector({"number": schema})
def test_area_selector_schema(schema): """Test area selector.""" selector.validate_selector({"area": schema})
def test_entity_selector_schema(schema): """Test entity selector.""" selector.validate_selector({"entity": schema})
def test_select_selector_schema_error(schema): """Test select selector.""" with pytest.raises(vol.Invalid): selector.validate_selector({"select": schema})
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})