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>
This commit is contained in:
google-labs-jules[bot] 2026-09-04 07:03:06 +00:00
parent 8c99ac78b7
commit 197b4df5ba

View file

@ -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