mirror of
https://github.com/esphome/esphome.git
synced 2025-08-13 17:49:40 +01:00
.devcontainer
.github
.vscode
docker
esphome
script
tests
component_tests
components
dashboard
test_build_components
test_packages
unit_tests
fixtures
conftest.py
strategies.py
test_codegen.py
test_config_validation.py
test_core.py
test_cpp_generator.py
test_cpp_helpers.py
test_helpers.py
test_wizard.py
test_yaml_util.py
.gitignore
README.md
custom.h
dummy_main.cpp
pnglogo.png
.clang-format
.clang-tidy
.coveragerc
.dockerignore
.editorconfig
.flake8
.gitattributes
.gitignore
.pre-commit-config.yaml
.yamllint
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
MANIFEST.in
README.md
platformio.ini
pyproject.toml
requirements.txt
requirements_dev.txt
requirements_optional.txt
requirements_test.txt
sdkconfig.defaults
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
import pytest
|
|
from unittest.mock import Mock
|
|
|
|
from esphome import cpp_helpers as ch
|
|
from esphome import const
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_gpio_pin_expression__conf_is_none(monkeypatch):
|
|
actual = await ch.gpio_pin_expression(None)
|
|
|
|
assert actual is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_register_component(monkeypatch):
|
|
var = Mock(base="foo.bar")
|
|
|
|
app_mock = Mock(register_component=Mock(return_value=var))
|
|
monkeypatch.setattr(ch, "App", app_mock)
|
|
|
|
core_mock = Mock(component_ids=["foo.bar"])
|
|
monkeypatch.setattr(ch, "CORE", core_mock)
|
|
|
|
add_mock = Mock()
|
|
monkeypatch.setattr(ch, "add", add_mock)
|
|
|
|
actual = await ch.register_component(var, {})
|
|
|
|
assert actual is var
|
|
assert add_mock.call_count == 2
|
|
app_mock.register_component.assert_called_with(var)
|
|
assert core_mock.component_ids == []
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_register_component__no_component_id(monkeypatch):
|
|
var = Mock(base="foo.eek")
|
|
|
|
core_mock = Mock(component_ids=["foo.bar"])
|
|
monkeypatch.setattr(ch, "CORE", core_mock)
|
|
|
|
with pytest.raises(ValueError, match="Component ID foo.eek was not declared to"):
|
|
await ch.register_component(var, {})
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_register_component__with_setup_priority(monkeypatch):
|
|
var = Mock(base="foo.bar")
|
|
|
|
app_mock = Mock(register_component=Mock(return_value=var))
|
|
monkeypatch.setattr(ch, "App", app_mock)
|
|
|
|
core_mock = Mock(component_ids=["foo.bar"])
|
|
monkeypatch.setattr(ch, "CORE", core_mock)
|
|
|
|
add_mock = Mock()
|
|
monkeypatch.setattr(ch, "add", add_mock)
|
|
|
|
actual = await ch.register_component(
|
|
var,
|
|
{
|
|
const.CONF_SETUP_PRIORITY: "123",
|
|
const.CONF_UPDATE_INTERVAL: "456",
|
|
},
|
|
)
|
|
|
|
assert actual is var
|
|
add_mock.assert_called()
|
|
assert add_mock.call_count == 4
|
|
app_mock.register_component.assert_called_with(var)
|
|
assert core_mock.component_ids == []
|