mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Update exception handling for python3.13 for getpass.getuser() (#132449)
* Update exception handling for python3.13 for getpass.getuser() * Add comment Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Cleanup trailing space --------- Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
1dfd4e80b9
commit
d091936ac6
@ -71,7 +71,10 @@ async def async_get_system_info(hass: HomeAssistant) -> dict[str, Any]:
|
||||
|
||||
try:
|
||||
info_object["user"] = cached_get_user()
|
||||
except KeyError:
|
||||
except (KeyError, OSError):
|
||||
# OSError on python >= 3.13, KeyError on python < 3.13
|
||||
# KeyError can be removed when 3.12 support is dropped
|
||||
# see https://docs.python.org/3/whatsnew/3.13.html
|
||||
info_object["user"] = None
|
||||
|
||||
if platform.system() == "Darwin":
|
||||
|
@ -93,10 +93,9 @@ async def test_container_installationtype(hass: HomeAssistant) -> None:
|
||||
assert info["installation_type"] == "Unsupported Third Party Container"
|
||||
|
||||
|
||||
async def test_getuser_keyerror(hass: HomeAssistant) -> None:
|
||||
"""Test getuser keyerror."""
|
||||
with patch(
|
||||
"homeassistant.helpers.system_info.cached_get_user", side_effect=KeyError
|
||||
):
|
||||
@pytest.mark.parametrize("error", [KeyError, OSError])
|
||||
async def test_getuser_oserror(hass: HomeAssistant, error: Exception) -> None:
|
||||
"""Test getuser oserror."""
|
||||
with patch("homeassistant.helpers.system_info.cached_get_user", side_effect=error):
|
||||
info = await async_get_system_info(hass)
|
||||
assert info["user"] is None
|
||||
|
Loading…
x
Reference in New Issue
Block a user