Skip to content

Commit 22b2ced

Browse files
committed
Add FlightTelemetryTools parser tests.
1 parent a2433ef commit 22b2ced

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Parser tests across DJI SRT dialects."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
9+
from flight_telemetry.parser import parse_srt_file, parse_srt_text
10+
11+
12+
def test_classic_font_wrapped(classic_srt: Path) -> None:
13+
frames = parse_srt_file(classic_srt)
14+
# 4 cues, 1 missing GPS -> 3 frames
15+
assert len(frames) == 3
16+
assert frames[0].latitude == pytest.approx(59.302335)
17+
assert frames[0].longitude == pytest.approx(18.203059)
18+
assert frames[0].altitude_source == "absolute"
19+
assert frames[0].altitude_m == pytest.approx(142.760)
20+
assert frames[0].abs_alt_m == pytest.approx(142.760)
21+
assert frames[0].rel_alt_m == pytest.approx(10.200)
22+
assert frames[0].datetime_utc is not None
23+
24+
25+
def test_bracket_mini_and_missing_gps(bracket_srt: Path) -> None:
26+
frames = parse_srt_file(bracket_srt)
27+
# cues 1,2,4 have GPS; cue 3 missing
28+
assert len(frames) == 3
29+
assert frames[0].speed_source == "recorded"
30+
assert frames[0].speed_mps == pytest.approx(3.50)
31+
# frame 2 has no recorded speed -> estimated from previous
32+
assert frames[1].speed_source == "estimated"
33+
assert frames[1].speed_mps is not None and frames[1].speed_mps > 0
34+
35+
36+
def test_gps_function_and_hs(gps_func_srt: Path) -> None:
37+
frames = parse_srt_file(gps_func_srt)
38+
assert len(frames) == 2
39+
assert frames[0].latitude == pytest.approx(39.906217)
40+
assert frames[0].altitude_m == pytest.approx(69.800)
41+
assert frames[0].altitude_source == "absolute"
42+
assert frames[1].speed_source == "recorded"
43+
assert frames[1].speed_mps == pytest.approx(4.25)
44+
45+
46+
def test_skip_empty_and_no_file(tmp_path: Path) -> None:
47+
assert parse_srt_text("") == []
48+
missing = tmp_path / "nope.SRT"
49+
with pytest.raises(FileNotFoundError):
50+
parse_srt_file(missing)
51+
52+
53+
def test_rel_alt_only_when_abs_missing() -> None:
54+
text = """1
55+
00:00:00,000 --> 00:00:01,000
56+
[latitude: 10.0] [longitude: 20.0] [rel_alt: 7.5]
57+
"""
58+
frames = parse_srt_text(text)
59+
assert len(frames) == 1
60+
assert frames[0].altitude_source == "relative"
61+
assert frames[0].altitude_m == pytest.approx(7.5)

0 commit comments

Comments
 (0)