Files
MeshChatX/tests/backend/test_telemetry_extended.py
Sudo-Ivan e2586e9052
Some checks failed
CI / test-backend (push) Successful in 32s
CI / lint (push) Failing after 2m12s
CI / build-frontend (pull_request) Successful in 1m38s
Build and Publish Docker Image / build (pull_request) Has been skipped
CI / test-backend (pull_request) Successful in 24s
OSV-Scanner PR Scan / scan-pr (pull_request) Successful in 53s
CI / test-lang (pull_request) Successful in 1m15s
CI / lint (pull_request) Failing after 5m8s
CI / build-frontend (push) Successful in 9m46s
CI / test-lang (push) Successful in 9m48s
Tests / test (push) Successful in 13m32s
Tests / test (pull_request) Successful in 11m23s
Build Test / Build and Test (push) Successful in 15m56s
Build and Publish Docker Image / build-dev (pull_request) Successful in 13m42s
Build Test / Build and Test (pull_request) Successful in 16m9s
feat(tests): add comprehensive telemetry and interface tests
- Introduced new test files for telemetry functionality, including integration, fuzzing, and extended tests to ensure robustness and performance.
- Added tests for parsing LXMF display names and telemetry data, addressing potential bugs and ensuring correct handling of various input formats.
- Implemented performance tests for the InterfacesPage component, validating rendering efficiency with a large number of discovered interfaces.
- Enhanced existing tests for markdown rendering and link utilities to cover additional edge cases and improve stability.
2026-01-07 19:22:00 -06:00

48 lines
1.8 KiB
Python

import time
from meshchatx.src.backend.telemetry_utils import Telemeter
def test_pack_unpack_battery_and_link():
battery = {"charge_percent": 85, "charging": 1}
physical_link = {"rssi": -90, "snr": 8, "q": 95}
ts = int(time.time())
packed = Telemeter.pack(time_utc=ts, battery=battery, physical_link=physical_link)
assert isinstance(packed, bytes)
unpacked = Telemeter.from_packed(packed)
assert unpacked["time"]["utc"] == ts
assert unpacked["battery"]["charge_percent"] == battery["charge_percent"]
assert unpacked["battery"]["charging"] == battery["charging"]
assert unpacked["physical_link"]["rssi"] == physical_link["rssi"]
assert unpacked["physical_link"]["snr"] == physical_link["snr"]
assert unpacked["physical_link"]["q"] == physical_link["q"]
def test_telemeter_from_packed_robustness():
# Test with corrupted umsgpack data
assert Telemeter.from_packed(b"\xff\xff\xff") is None
# Test with empty data
assert Telemeter.from_packed(b"") is None
# Test with valid umsgpack but unexpected structure
from RNS.vendor import umsgpack
invalid_structure = umsgpack.packb({"not_a_sensor": 123})
assert Telemeter.from_packed(invalid_structure) == {}
def test_telemeter_unpack_location_robustness():
# Test with insufficient elements
assert Telemeter.unpack_location([b"lat", b"lon"]) is None
# Test with invalid types
assert Telemeter.unpack_location(["not_bytes"] * 7) is None
def test_sideband_request_format_compatibility():
# Sideband telemetry request command is 0x01
# It can be a simple int 0x01 or a dict {0x01: timebase}
# This test is more about the logic in on_lxmf_delivery,
# but we can verify our assumptions about command structure here if needed.
pass