All checks were successful
tests / pytest (push) Successful in 1m24s
Two related changes to make sender/receiver logs analyzable:
1. MeshCoreRadio.send no longer returns until the radio firmware
reports the packet was actually transmitted. send_chan_msg only
waits for EventType.OK (firmware accepted bytes) — no
tx-complete event is pushed for channel messages, so we poll
commands.get_stats_packets() and wait for nb_sent to strictly
increment past a pre-send baseline. Times out after 30s.
2. Each test packet now embeds a random 8-hex-char token as the
4th comma-separated field of the prefix, distinct from any
radio-assigned packet id. Receivers extract it from the text
and write it on every TSV row, so a sender's queued/sent rows
tie 1:1 to each receiver's record without depending on
whatever packet id the radio surfaces on each side.
TSV gains a new column (3rd, after packet_id):
queued: ts queued <id> <token> <freq,bw,sf,cr,pow>
sent: ts sent <id> <token> <duration_ms> <text>
received: ts received <id> <token> <text>
Missing token writes "-".
UDP simulator regex updated to accept both legacy 3-field test
payloads and the new 4-field format with token.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
from modjam.log import TsvLogger
|
|
|
|
|
|
def test_tsv_logger_writes_all_event_types(tmp_path):
|
|
logger = TsvLogger("Z", tmp_path)
|
|
logger.queued(42, "deadbeef", 915.1, 500.0, 7, 5, 22)
|
|
logger.sent(42, "deadbeef", 13, "1234.5,0.0,1,deadbeef|abc")
|
|
logger.received(99, "cafe1234", "1234.5,1.0,2,cafe1234|xyz")
|
|
logger.close()
|
|
|
|
rows = logger.path.read_text().strip().split("\n")
|
|
assert len(rows) == 3
|
|
|
|
parts0 = rows[0].split("\t")
|
|
assert parts0[1] == "queued"
|
|
assert parts0[2] == "42"
|
|
assert parts0[3] == "deadbeef"
|
|
assert parts0[4] == "915.1,500.0,7,5,22"
|
|
|
|
parts1 = rows[1].split("\t")
|
|
assert parts1[1] == "sent"
|
|
assert parts1[2] == "42"
|
|
assert parts1[3] == "deadbeef"
|
|
assert parts1[4] == "13"
|
|
assert parts1[5] == "1234.5,0.0,1,deadbeef|abc"
|
|
|
|
parts2 = rows[2].split("\t")
|
|
assert parts2[1] == "received"
|
|
assert parts2[2] == "99"
|
|
assert parts2[3] == "cafe1234"
|
|
assert parts2[4] == "1234.5,1.0,2,cafe1234|xyz"
|
|
|
|
|
|
def test_tsv_logger_renders_missing_token_as_dash(tmp_path):
|
|
logger = TsvLogger("Z", tmp_path)
|
|
logger.received(99, None, "no-token-text")
|
|
logger.close()
|
|
parts = logger.path.read_text().strip().split("\t")
|
|
assert parts[3] == "-"
|
|
|
|
|
|
def test_tsv_logger_creates_log_dir(tmp_path):
|
|
sub = tmp_path / "nested" / "logs"
|
|
logger = TsvLogger("A", sub)
|
|
logger.queued(1, "tok", 0, 0, 0, 0, 0)
|
|
logger.close()
|
|
assert sub.is_dir()
|
|
assert logger.path.exists()
|
|
|
|
|
|
def test_tsv_logger_filename_includes_test_name(tmp_path):
|
|
logger = TsvLogger("A", tmp_path, test_name="run42")
|
|
logger.close()
|
|
assert logger.path.name.startswith("run42-A-")
|
|
assert logger.path.name.endswith(".tsv")
|
|
|
|
|
|
def test_tsv_logger_filename_without_test_name(tmp_path):
|
|
logger = TsvLogger("A", tmp_path)
|
|
logger.close()
|
|
assert logger.path.name.startswith("A-")
|