mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 03:12:20 +01:00
add-black (#1593)
* Add black Update pre commit Update pre commit add empty line * Format with black
This commit is contained in:
committed by
GitHub
parent
2b60b0f1fa
commit
69879920eb
@@ -1,4 +1,4 @@
|
||||
""" Tests for the wizard.py file """
|
||||
"""Tests for the wizard.py file."""
|
||||
|
||||
import esphome.wizard as wz
|
||||
import pytest
|
||||
@@ -14,7 +14,7 @@ def default_config():
|
||||
"board": "test_board",
|
||||
"ssid": "test_ssid",
|
||||
"psk": "test_psk",
|
||||
"password": ""
|
||||
"password": "",
|
||||
}
|
||||
|
||||
|
||||
@@ -35,13 +35,13 @@ def test_sanitize_quotes_replaces_with_escaped_char():
|
||||
The sanitize_quotes function should replace double quotes with their escaped equivalents
|
||||
"""
|
||||
# Given
|
||||
input_str = "\"key\": \"value\""
|
||||
input_str = '"key": "value"'
|
||||
|
||||
# When
|
||||
output_str = wz.sanitize_double_quotes(input_str)
|
||||
|
||||
# Then
|
||||
assert output_str == "\\\"key\\\": \\\"value\\\""
|
||||
assert output_str == '\\"key\\": \\"value\\"'
|
||||
|
||||
|
||||
def test_config_file_fallback_ap_includes_descriptive_name(default_config):
|
||||
@@ -55,7 +55,7 @@ def test_config_file_fallback_ap_includes_descriptive_name(default_config):
|
||||
config = wz.wizard_file(**default_config)
|
||||
|
||||
# Then
|
||||
assert f"ssid: \"Test Node Fallback Hotspot\"" in config
|
||||
assert 'ssid: "Test Node Fallback Hotspot"' in config
|
||||
|
||||
|
||||
def test_config_file_fallback_ap_name_less_than_32_chars(default_config):
|
||||
@@ -70,7 +70,7 @@ def test_config_file_fallback_ap_name_less_than_32_chars(default_config):
|
||||
config = wz.wizard_file(**default_config)
|
||||
|
||||
# Then
|
||||
assert f"ssid: \"A Very Long Name For This Node\"" in config
|
||||
assert 'ssid: "A Very Long Name For This Node"' in config
|
||||
|
||||
|
||||
def test_config_file_should_include_ota(default_config):
|
||||
@@ -115,7 +115,9 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||
assert f"platform: {default_config['platform']}" in generated_config
|
||||
|
||||
|
||||
def test_wizard_write_defaults_platform_from_board_esp8266(default_config, tmp_path, monkeypatch):
|
||||
def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||
default_config, tmp_path, monkeypatch
|
||||
):
|
||||
"""
|
||||
If the platform is not explicitly set, use "ESP8266" if the board is one of the ESP8266 boards
|
||||
"""
|
||||
@@ -133,7 +135,9 @@ def test_wizard_write_defaults_platform_from_board_esp8266(default_config, tmp_p
|
||||
assert "platform: ESP8266" in generated_config
|
||||
|
||||
|
||||
def test_wizard_write_defaults_platform_from_board_esp32(default_config, tmp_path, monkeypatch):
|
||||
def test_wizard_write_defaults_platform_from_board_esp32(
|
||||
default_config, tmp_path, monkeypatch
|
||||
):
|
||||
"""
|
||||
If the platform is not explicitly set, use "ESP32" if the board is not one of the ESP8266 boards
|
||||
"""
|
||||
@@ -167,7 +171,9 @@ def test_safe_print_step_prints_step_number_and_description(monkeypatch):
|
||||
|
||||
# Then
|
||||
# Collect arguments to all safe_print() calls (substituting "" for any empty ones)
|
||||
all_args = [call.args[0] if len(call.args) else "" for call in wz.safe_print.call_args_list]
|
||||
all_args = [
|
||||
call.args[0] if len(call.args) else "" for call in wz.safe_print.call_args_list
|
||||
]
|
||||
|
||||
assert any(step_desc == arg for arg in all_args)
|
||||
assert any(f"STEP {step_num}" in arg for arg in all_args)
|
||||
@@ -212,7 +218,7 @@ def test_strip_accents_removes_diacritics():
|
||||
"""
|
||||
|
||||
# Given
|
||||
input_str = u"Kühne"
|
||||
input_str = "Kühne"
|
||||
expected_str = "Kuhne"
|
||||
|
||||
# When
|
||||
@@ -264,7 +270,7 @@ def test_wizard_accepts_default_answers_esp8266(tmpdir, monkeypatch, wizard_answ
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
@@ -286,7 +292,7 @@ def test_wizard_accepts_default_answers_esp32(tmpdir, monkeypatch, wizard_answer
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
@@ -306,14 +312,16 @@ def test_wizard_offers_better_node_name(tmpdir, monkeypatch, wizard_answers):
|
||||
# Given
|
||||
wizard_answers[0] = "Küche #2"
|
||||
expected_name = "kuche_2"
|
||||
monkeypatch.setattr(wz, "default_input", MagicMock(side_effect=lambda _, default: default))
|
||||
monkeypatch.setattr(
|
||||
wz, "default_input", MagicMock(side_effect=lambda _, default: default)
|
||||
)
|
||||
|
||||
config_file = tmpdir.join("test.yaml")
|
||||
input_mock = MagicMock(side_effect=wizard_answers)
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
@@ -336,7 +344,7 @@ def test_wizard_requires_correct_platform(tmpdir, monkeypatch, wizard_answers):
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
@@ -358,7 +366,7 @@ def test_wizard_requires_correct_board(tmpdir, monkeypatch, wizard_answers):
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
@@ -380,7 +388,7 @@ def test_wizard_requires_valid_ssid(tmpdir, monkeypatch, wizard_answers):
|
||||
monkeypatch.setattr("builtins.input", input_mock)
|
||||
monkeypatch.setattr(wz, "safe_print", lambda t=None: 0)
|
||||
monkeypatch.setattr(wz, "sleep", lambda _: 0)
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
monkeypatch.setattr(wz, "wizard_write", MagicMock())
|
||||
|
||||
# When
|
||||
retval = wz.wizard(str(config_file))
|
||||
|
Reference in New Issue
Block a user