From bf7ede1d43c73d83aeed85dd9a107410059e3c63 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 8 Feb 2026 07:24:11 -0600 Subject: [PATCH] Make mock_token_hex strict on unexpected nbytes Raise ValueError for unexpected nbytes values so tests fail clearly if production code starts calling token_hex with an incorrect size. --- tests/unit_tests/test_espota2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/test_espota2.py b/tests/unit_tests/test_espota2.py index 57e33e083e..20ba4b1f76 100644 --- a/tests/unit_tests/test_espota2.py +++ b/tests/unit_tests/test_espota2.py @@ -61,7 +61,9 @@ def mock_token_hex() -> Generator[Mock]: def _token_hex(nbytes: int) -> str: if nbytes == 16: return MOCK_MD5_CNONCE - return MOCK_SHA256_CNONCE + if nbytes == 32: + return MOCK_SHA256_CNONCE + raise ValueError(f"Unexpected nbytes for token_hex mock: {nbytes}") with patch("esphome.espota2.secrets.token_hex", side_effect=_token_hex) as mock: yield mock