mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-11 01:02:10 +03:00
add tests for finalize_hop
This commit is contained in:
parent
8aa806881e
commit
2473822b93
1 changed files with 39 additions and 1 deletions
|
|
@ -2,7 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from netsleuth.traceparse import parse_linux
|
from netsleuth.models import TraceHop
|
||||||
|
from netsleuth.traceparse import parse_linux, finalize_hop
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
@ -253,3 +254,40 @@ def test_build_trace_result_on_empty_output_is_a_well_formed_empty_result():
|
||||||
assert result.hops == []
|
assert result.hops == []
|
||||||
assert result.completed is False
|
assert result.completed is False
|
||||||
assert result.max_hops_reached is False
|
assert result.max_hops_reached is False
|
||||||
|
|
||||||
|
def test_finalize_hop_computes_stats_for_probes():
|
||||||
|
hop = TraceHop(ttl=1, probes=[10.0, 20.0, 30.0])
|
||||||
|
finalized = finalize_hop(hop)
|
||||||
|
assert finalized is hop
|
||||||
|
assert finalized.loss_pct == 0.0
|
||||||
|
assert finalized.min_ms == 10.0
|
||||||
|
assert finalized.avg_ms == 20.0
|
||||||
|
assert finalized.max_ms == 30.0
|
||||||
|
assert finalized.jitter_ms == 10.0
|
||||||
|
|
||||||
|
def test_finalize_hop_handles_empty_probes():
|
||||||
|
hop = TraceHop(ttl=1, probes=[])
|
||||||
|
finalized = finalize_hop(hop)
|
||||||
|
assert finalized.loss_pct == 0.0
|
||||||
|
assert finalized.min_ms is None
|
||||||
|
assert finalized.avg_ms is None
|
||||||
|
assert finalized.max_ms is None
|
||||||
|
assert finalized.jitter_ms is None
|
||||||
|
|
||||||
|
def test_finalize_hop_handles_all_lost_probes():
|
||||||
|
hop = TraceHop(ttl=1, probes=[None, None, None])
|
||||||
|
finalized = finalize_hop(hop)
|
||||||
|
assert finalized.loss_pct == 100.0
|
||||||
|
assert finalized.min_ms is None
|
||||||
|
assert finalized.avg_ms is None
|
||||||
|
assert finalized.max_ms is None
|
||||||
|
assert finalized.jitter_ms is None
|
||||||
|
|
||||||
|
def test_finalize_hop_handles_partial_lost_probes():
|
||||||
|
hop = TraceHop(ttl=1, probes=[10.0, None, 20.0])
|
||||||
|
finalized = finalize_hop(hop)
|
||||||
|
assert finalized.loss_pct == pytest.approx(33.333, abs=0.01)
|
||||||
|
assert finalized.min_ms == 10.0
|
||||||
|
assert finalized.avg_ms == 15.0
|
||||||
|
assert finalized.max_ms == 20.0
|
||||||
|
assert finalized.jitter_ms == 0.0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue