mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Feature/component test fixture (#1142)
This commit is contained in:
		| @@ -1,24 +1,43 @@ | ||||
| """ Tests for the binary sensor component """ | ||||
|  | ||||
| from esphome.core import CORE | ||||
| from esphome.config import read_config | ||||
| from esphome.__main__ import generate_cpp_contents | ||||
|  | ||||
| def test_binary_sensor_is_setup(generate_main): | ||||
|     """ | ||||
|     When the binary sensor is set in the yaml file, it should be registered in main | ||||
|     """ | ||||
|     # Given | ||||
|  | ||||
|     # When | ||||
|     main_cpp = generate_main("tests/component_tests/binary_sensor/test_binary_sensor.yaml") | ||||
|  | ||||
|     # Then | ||||
|     assert "new gpio::GPIOBinarySensor();" in main_cpp | ||||
|     assert "App.register_binary_sensor" in main_cpp | ||||
|  | ||||
|  | ||||
| def test_binary_sensor_config_value_internal_set(): | ||||
| def test_binary_sensor_sets_mandatory_fields(generate_main): | ||||
|     """ | ||||
|     When the mandatory fields are set in the yaml, they should be set in main | ||||
|     """ | ||||
|     # Given | ||||
|  | ||||
|     # When | ||||
|     main_cpp = generate_main("tests/component_tests/binary_sensor/test_binary_sensor.yaml") | ||||
|  | ||||
|     # Then | ||||
|     assert "bs_1->set_name(\"test bs1\");" in main_cpp | ||||
|     assert "bs_1->set_pin(new GPIOPin" in main_cpp | ||||
|  | ||||
|  | ||||
| def test_binary_sensor_config_value_internal_set(generate_main): | ||||
|     """ | ||||
|     Test that the "internal" config value is correctly set | ||||
|     """ | ||||
|     # Given | ||||
|     CORE.config_path = "tests/component_tests/binary_sensor/test_binary_sensor.yaml" | ||||
|     CORE.config = read_config({}) | ||||
|  | ||||
|     # When | ||||
|     generate_cpp_contents(CORE.config) | ||||
|     # print(CORE.cpp_main_section) | ||||
|     main_cpp = generate_main("tests/component_tests/binary_sensor/test_binary_sensor.yaml") | ||||
|  | ||||
|     # Then | ||||
|     assert "bs_1->set_internal(true);" in CORE.cpp_main_section | ||||
|     assert "bs_2->set_internal(false);" in CORE.cpp_main_section | ||||
|  | ||||
|     CORE.reset() | ||||
|     assert "bs_1->set_internal(true);" in main_cpp | ||||
|     assert "bs_2->set_internal(false);" in main_cpp | ||||
|   | ||||
		Reference in New Issue
	
	Block a user