From 98f6ab54ee15685b34380c70993609afd95c2759 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 19 Aug 2026 11:24:50 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20for=20'detect=5Fca?= =?UTF-8?q?pabilities'=20in=20netinfo.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added tests for the `detect_capabilities` function in `src/netsleuth/netinfo.py` to cover both Linux and Windows OS flows, improving test coverage and reliability. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_netinfo.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_netinfo.py b/tests/test_netinfo.py index 21969b6..e52a039 100644 --- a/tests/test_netinfo.py +++ b/tests/test_netinfo.py @@ -27,6 +27,44 @@ def test_unix_falls_back_to_raw_icmp_when_datagram_is_unavailable(): assert choose_latency_backend(caps(icmp_raw=True, is_elevated=True)) == "icmp_raw" +from netsleuth.netinfo import detect_capabilities +from unittest.mock import patch + +def test_detect_capabilities_linux_happy_path(): + with patch("netsleuth.netinfo.platform.system", return_value="Linux"), \ + patch("netsleuth.netinfo._is_elevated", return_value=True), \ + patch("netsleuth.netinfo._socket_works", side_effect=[True, True]), \ + patch("netsleuth.netinfo._win_icmp_available", return_value=False), \ + patch("netsleuth.netinfo.shutil.which", side_effect=lambda x: "/usr/bin/" + x): + + c = detect_capabilities() + + assert c.os_name == "Linux" + assert c.is_elevated is True + assert c.icmp_dgram is True + assert c.icmp_raw is True + assert c.icmp_win_api is False + assert c.mtr_binary == "/usr/bin/mtr" + assert c.traceroute_binary == "/usr/bin/traceroute" + + +def test_detect_capabilities_windows_happy_path(): + with patch("netsleuth.netinfo.platform.system", return_value="Windows"), \ + patch("netsleuth.netinfo._is_elevated", return_value=False), \ + patch("netsleuth.netinfo._socket_works", return_value=False), \ + patch("netsleuth.netinfo._win_icmp_available", return_value=True), \ + patch("netsleuth.netinfo.shutil.which", side_effect=lambda x: "C:\\Windows\\System32\\" + x + ".exe"): + + c = detect_capabilities() + + assert c.os_name == "Windows" + assert c.is_elevated is False + assert c.icmp_dgram is False + assert c.icmp_raw is False + assert c.icmp_win_api is True + assert c.mtr_binary == "C:\\Windows\\System32\\mtr.exe" + assert c.traceroute_binary == "C:\\Windows\\System32\\tracert.exe" + def test_latency_falls_back_to_tcp_when_no_icmp_is_possible(): assert choose_latency_backend(caps()) == "tcp"