Skip to content

Commit

Permalink
Update exception handling for python3.13 for getpass.getuser() (#132449)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent 1a0a2eb commit 35438f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 4 additions & 1 deletion homeassistant/helpers/system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
9 changes: 4 additions & 5 deletions tests/helpers/test_system_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 35438f6

Please sign in to comment.