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.
This commit is contained in:
J. Nick Koston
2026-02-08 07:24:11 -06:00
parent 1b7efdd051
commit bf7ede1d43
+3 -1
View File
@@ -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