mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Allow substitutions to be valid names (#4726)
This commit is contained in:
		| @@ -6,7 +6,7 @@ from hypothesis.strategies import one_of, text, integers, builds | ||||
|  | ||||
| from esphome import config_validation | ||||
| from esphome.config_validation import Invalid | ||||
| from esphome.core import Lambda, HexInt | ||||
| from esphome.core import CORE, Lambda, HexInt | ||||
|  | ||||
|  | ||||
| def test_check_not_templatable__invalid(): | ||||
| @@ -40,6 +40,47 @@ def test_valid_name__invalid(value): | ||||
|         config_validation.valid_name(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("${name}", "${NAME}", "$NAME", "${name}_name")) | ||||
| def test_valid_name__substitution_valid(value): | ||||
|     CORE.vscode = True | ||||
|     actual = config_validation.valid_name(value) | ||||
|     assert actual == value | ||||
|  | ||||
|     CORE.vscode = False | ||||
|     with pytest.raises(Invalid): | ||||
|         actual = config_validation.valid_name(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("{NAME}", "${A NAME}")) | ||||
| def test_valid_name__substitution_like_invalid(value): | ||||
|     with pytest.raises(Invalid): | ||||
|         config_validation.valid_name(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("myid", "anID", "SOME_ID_test", "MYID_99")) | ||||
| def test_validate_id_name__valid(value): | ||||
|     actual = config_validation.validate_id_name(value) | ||||
|  | ||||
|     assert actual == value | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("id of mine", "id-4", "{name_id}", "id::name")) | ||||
| def test_validate_id_name__invalid(value): | ||||
|     with pytest.raises(Invalid): | ||||
|         config_validation.validate_id_name(value) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize("value", ("${id}", "${ID}", "${ID}_test_1", "$MYID")) | ||||
| def test_validate_id_name__substitution_valid(value): | ||||
|     CORE.vscode = True | ||||
|     actual = config_validation.validate_id_name(value) | ||||
|     assert actual == value | ||||
|  | ||||
|     CORE.vscode = False | ||||
|     with pytest.raises(Invalid): | ||||
|         config_validation.validate_id_name(value) | ||||
|  | ||||
|  | ||||
| @given(one_of(integers(), text())) | ||||
| def test_string__valid(value): | ||||
|     actual = config_validation.string(value) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user