mirror of
https://github.com/esphome/esphome.git
synced 2025-11-13 13:25:50 +00:00
Compare commits
2 Commits
ethernet_m
...
ci_test_om
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a84895774 | ||
|
|
b1166b916f |
@@ -90,16 +90,18 @@ def get_component_from_path(file_path: str) -> str | None:
|
|||||||
"""Extract component name from a file path.
|
"""Extract component name from a file path.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_path: Path to a file (e.g., "esphome/components/wifi/wifi.cpp")
|
file_path: Path to a file (e.g., "esphome/components/wifi/wifi.cpp"
|
||||||
|
or "tests/components/uart/test.esp32-idf.yaml")
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Component name if path is in components directory, None otherwise
|
Component name if path is in components or tests directory, None otherwise
|
||||||
"""
|
"""
|
||||||
if not file_path.startswith(ESPHOME_COMPONENTS_PATH):
|
if file_path.startswith(ESPHOME_COMPONENTS_PATH) or file_path.startswith(
|
||||||
return None
|
ESPHOME_TESTS_COMPONENTS_PATH
|
||||||
parts = file_path.split("/")
|
):
|
||||||
if len(parts) >= 3:
|
parts = file_path.split("/")
|
||||||
return parts[2]
|
if len(parts) >= 3 and parts[2]:
|
||||||
|
return parts[2]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# comment
|
||||||
|
|
||||||
modbus:
|
modbus:
|
||||||
id: mod_bus1
|
id: mod_bus1
|
||||||
flow_control_pin: ${flow_control_pin}
|
flow_control_pin: ${flow_control_pin}
|
||||||
|
|||||||
@@ -1065,3 +1065,39 @@ def test_parse_list_components_output(output: str, expected: list[str]) -> None:
|
|||||||
"""Test parse_list_components_output function."""
|
"""Test parse_list_components_output function."""
|
||||||
result = helpers.parse_list_components_output(output)
|
result = helpers.parse_list_components_output(output)
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("file_path", "expected_component"),
|
||||||
|
[
|
||||||
|
# Component files
|
||||||
|
("esphome/components/wifi/wifi.cpp", "wifi"),
|
||||||
|
("esphome/components/uart/uart.h", "uart"),
|
||||||
|
("esphome/components/api/api_server.cpp", "api"),
|
||||||
|
("esphome/components/sensor/sensor.cpp", "sensor"),
|
||||||
|
# Test files
|
||||||
|
("tests/components/uart/test.esp32-idf.yaml", "uart"),
|
||||||
|
("tests/components/wifi/test.esp8266-ard.yaml", "wifi"),
|
||||||
|
("tests/components/sensor/test.esp32-idf.yaml", "sensor"),
|
||||||
|
("tests/components/api/test_api.cpp", "api"),
|
||||||
|
("tests/components/uart/common.h", "uart"),
|
||||||
|
# Non-component files
|
||||||
|
("esphome/core/component.cpp", None),
|
||||||
|
("esphome/core/helpers.h", None),
|
||||||
|
("tests/integration/test_api.py", None),
|
||||||
|
("tests/unit_tests/test_helpers.py", None),
|
||||||
|
("README.md", None),
|
||||||
|
("script/helpers.py", None),
|
||||||
|
# Edge cases
|
||||||
|
("esphome/components/", None), # No component name
|
||||||
|
("tests/components/", None), # No component name
|
||||||
|
("esphome/components", None), # No trailing slash
|
||||||
|
("tests/components", None), # No trailing slash
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_get_component_from_path(
|
||||||
|
file_path: str, expected_component: str | None
|
||||||
|
) -> None:
|
||||||
|
"""Test extraction of component names from file paths."""
|
||||||
|
result = helpers.get_component_from_path(file_path)
|
||||||
|
assert result == expected_component
|
||||||
|
|||||||
Reference in New Issue
Block a user