From 197b4df5bada8ebab72e19fceed6e6c316fe20af Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 4 Sep 2026 07:03:06 +0000 Subject: [PATCH] Add test to cover `_is_elevated` exception on Windows This adds a test `test_is_elevated_windows_exception` which successfully mocks the environment to mimic Windows and tests the `ctypes.windll.shell32.IsUserAnAdmin` raising an Exception, checking that it evaluates back to `False`. This addresses the coverage gap in `_is_elevated` logic in `src/netsleuth/netinfo.py`. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_netinfo.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_netinfo.py b/tests/test_netinfo.py index 7134cd9..776cbdc 100644 --- a/tests/test_netinfo.py +++ b/tests/test_netinfo.py @@ -334,3 +334,10 @@ def test_collect_local_net_no_network(mock_resolvers, mock_gw, mock_stats, mock_ assert result.default_gateway_v6 is None assert result.is_dual_stack is False assert result.cgnat is False + +@patch("netsleuth.netinfo.platform.system", return_value="Windows") +def test_is_elevated_windows_exception(mock_system): + from netsleuth.netinfo import _is_elevated + with patch("netsleuth.netinfo.ctypes.windll", create=True) as mock_windll: + mock_windll.shell32.IsUserAnAdmin.side_effect = Exception("Some error") + assert _is_elevated() is False