mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user