1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-26 04:28:17 +00:00

32 lines
783 B
Python
Raw Normal View History

"""Fixtures for component tests."""
2020-07-15 13:04:00 +01:00
2021-03-12 23:58:43 +01:00
from pathlib import Path
2025-03-20 09:51:23 -10:00
import sys
2021-03-12 23:58:43 +01:00
# Add package root to python path
here = Path(__file__).parent
package_root = here.parent.parent
sys.path.insert(0, package_root.as_posix())
2025-03-20 09:51:23 -10:00
import pytest # noqa: E402
2020-07-15 13:04:00 +01:00
2025-03-20 09:51:23 -10:00
from esphome.__main__ import generate_cpp_contents # noqa: E402
from esphome.config import read_config # noqa: E402
from esphome.core import CORE # noqa: E402
2020-07-15 13:04:00 +01:00
@pytest.fixture
def generate_main():
"""Generates the C++ main.cpp file and returns it in string form."""
2020-07-15 13:04:00 +01:00
def generator(path: str) -> str:
CORE.config_path = path
CORE.config = read_config({})
generate_cpp_contents(CORE.config)
print(CORE.cpp_main_section)
return CORE.cpp_main_section
yield generator
CORE.reset()