"""Tests for I2Ping — TDD: tests before implementation.""" import pytest from i2p_apps.i2ptunnel.ping import PingResult class TestPingResult: def test_reachable(self): r = PingResult(destination="test.i2p", reachable=True, rtt_ms=150.5) assert r.reachable is True assert r.rtt_ms == 150.5 assert r.error is None def test_unreachable(self): r = PingResult(destination="test.i2p", reachable=False, error="timeout") assert r.reachable is False assert r.rtt_ms is None assert r.error == "timeout" def test_str_reachable(self): r = PingResult(destination="test.i2p", reachable=True, rtt_ms=100.0) s = str(r) assert "test.i2p" in s assert "100.0" in s def test_str_unreachable(self): r = PingResult(destination="test.i2p", reachable=False, error="timeout") s = str(r) assert "unreachable" in s.lower() or "timeout" in s.lower() class TestPingFunction: @pytest.mark.asyncio async def test_ping_returns_result(self): """i2p_ping should return a PingResult.""" from i2p_apps.i2ptunnel.ping import i2p_ping class MockSession: async def connect(self, dest): import asyncio r = asyncio.StreamReader() r.feed_eof() class W: def close(self): pass async def wait_closed(self): pass return r, W() result = await i2p_ping(MockSession(), "test.i2p", timeout=5.0) assert isinstance(result, PingResult) assert result.reachable is True assert result.rtt_ms is not None