mirror of
https://github.com/esphome/esphome.git
synced 2026-05-10 22:19:21 +08:00
79b741b8dc
CI / Create common environment (push) Has been cancelled
CI / Check pylint (push) Has been cancelled
CI / Run script/ci-custom (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.11) (push) Has been cancelled
CI / Run pytest (macOS-latest, 3.14) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.11) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.13) (push) Has been cancelled
CI / Run pytest (ubuntu-latest, 3.14) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.11) (push) Has been cancelled
CI / Run pytest (windows-latest, 3.14) (push) Has been cancelled
CI / Determine which jobs to run (push) Has been cancelled
CI / Run integration tests (push) Has been cancelled
CI / Run C++ unit tests (push) Has been cancelled
CI / Run CodSpeed benchmarks (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 IDF (push) Has been cancelled
CI / Run script/clang-tidy for ESP8266 (push) Has been cancelled
CI / Run script/clang-tidy for ZEPHYR (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 1/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 2/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 3/4 (push) Has been cancelled
CI / Run script/clang-tidy for ESP32 Arduino 4/4 (push) Has been cancelled
CI / Test components batch (${{ matrix.components }}) (push) Has been cancelled
CI / pre-commit.ci lite (push) Has been cancelled
CI / Build target branch for memory impact (push) Has been cancelled
CI / Build PR branch for memory impact (push) Has been cancelled
CI / Comment memory impact (push) Has been cancelled
CI / CI Status (push) Has been cancelled
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Tests for the button component"""
|
|
|
|
from tests.component_tests.helpers import INTERNAL_BIT, extract_packed_value
|
|
|
|
|
|
def test_button_is_setup(generate_main):
|
|
"""
|
|
When the button is set in the yaml file if should be registered in main
|
|
"""
|
|
# Given
|
|
|
|
# When
|
|
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
|
|
|
|
# Then
|
|
assert "static wake_on_lan::WakeOnLanButton *const" in main_cpp
|
|
assert ") wake_on_lan::WakeOnLanButton();" in main_cpp
|
|
assert "App.register_button" in main_cpp
|
|
assert "App.register_component" in main_cpp
|
|
|
|
|
|
def test_button_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/button/test_button.yaml")
|
|
|
|
# Then
|
|
assert 'App.register_button(wol_1, "wol_test_1",' in main_cpp
|
|
assert "wol_2->set_macaddr(18, 52, 86, 120, 144, 171);" in main_cpp
|
|
|
|
|
|
def test_button_config_value_internal_set(generate_main):
|
|
"""
|
|
Test that the "internal" config value is correctly set
|
|
"""
|
|
# Given
|
|
|
|
# When
|
|
main_cpp = generate_main("tests/component_tests/button/test_button.yaml")
|
|
|
|
# Then: wol_1 has internal: true, wol_2 has internal: false
|
|
assert extract_packed_value(main_cpp, "wol_1") & INTERNAL_BIT != 0
|
|
assert extract_packed_value(main_cpp, "wol_2") & INTERNAL_BIT == 0
|