"""Tests for ip_lookup module.""" from unittest.mock import MagicMock, patch from ip_lookup import get_ipv4, get_ipv6 class TestGetIpv4: def test_returns_stripped_ip(self) -> None: mock_result = MagicMock() mock_result.stdout = " 1.2.3.4 \n" with patch("ip_lookup.subprocess.run", return_value=mock_result) as mock_run: ip = get_ipv4() assert ip == "1.2.3.4" mock_run.assert_called_once_with(["curl", "-4", "ifconfig.me"], capture_output=True, text=True, check=False) def test_empty_response(self) -> None: mock_result = MagicMock() mock_result.stdout = "" with patch("ip_lookup.subprocess.run", return_value=mock_result): ip = get_ipv4() assert ip == "" class TestGetIpv6: def test_returns_stripped_ip(self) -> None: mock_result = MagicMock() mock_result.stdout = " 2001:db8::1 \n" with patch("ip_lookup.subprocess.run", return_value=mock_result) as mock_run: ip = get_ipv6() assert ip == "2001:db8::1" mock_run.assert_called_once_with(["curl", "-6", "ifconfig.me"], capture_output=True, text=True, check=False) def test_empty_response(self) -> None: mock_result = MagicMock() mock_result.stdout = "" with patch("ip_lookup.subprocess.run", return_value=mock_result): ip = get_ipv6() assert ip == ""