From aa9bd1e0b620c6e17ae31b57efc0a63a76da5b8f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:40:39 +0000 Subject: [PATCH] Add unit tests for `_looks_like_ip` The `_looks_like_ip` function in `src/netsleuth/netinfo.py` was untested. This adds a test using parameterized inputs to verify both valid IPv4 and IPv6 strings and invalid strings or non-IPs. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- tests/test_netinfo.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_netinfo.py b/tests/test_netinfo.py index 7134cd9..7cb3f02 100644 --- a/tests/test_netinfo.py +++ b/tests/test_netinfo.py @@ -334,3 +334,33 @@ 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 + + +from netsleuth.netinfo import _looks_like_ip + +@pytest.mark.parametrize( + "token,expected", + [ + ("192.168.1.1", True), + ("0.0.0.0", True), + ("255.255.255.255", True), + ("1.1.1.1", True), + ("2001:db8::1", True), + ("fe80::1", True), + ("::1", True), + ("::", True), + ("not_an_ip", False), + ("", False), + ("256.256.256.256", False), + ("192.168.1", False), + ("2001:db8:::1", False), + ("fe80::1%eth0", False), + ("1.2.3.4.5", False), + ("10.0.0.0/8", False), + ("2001:db8::/32", False), + ("127.0.0.1 ", False), + (" 127.0.0.1", False), + ], +) +def test_looks_like_ip(token, expected): + assert _looks_like_ip(token) is expected