|
| 1 | +"""GPX / KML well-formed export tests.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import xml.etree.ElementTree as ET |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from flight_telemetry.export_gpx import frames_to_gpx, write_gpx |
| 9 | +from flight_telemetry.export_kml import frames_to_kml, write_kml |
| 10 | +from flight_telemetry.parser import parse_srt_file |
| 11 | + |
| 12 | + |
| 13 | +GPX_NS = {"gpx": "http://www.topografix.com/GPX/1/1"} |
| 14 | +KML_NS = { |
| 15 | + "kml": "http://www.opengis.net/kml/2.2", |
| 16 | + "gx": "http://www.google.com/kml/ext/2.2", |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +def test_gpx_well_formed(classic_srt: Path, tmp_path: Path) -> None: |
| 21 | + frames = parse_srt_file(classic_srt) |
| 22 | + xml = frames_to_gpx(frames) |
| 23 | + root = ET.fromstring(xml) |
| 24 | + assert root.tag.endswith("gpx") |
| 25 | + pts = root.findall(".//{http://www.topografix.com/GPX/1/1}trkpt") |
| 26 | + assert len(pts) == len(frames) |
| 27 | + for pt in pts: |
| 28 | + assert "lat" in pt.attrib and "lon" in pt.attrib |
| 29 | + assert pt.find("{http://www.topografix.com/GPX/1/1}ele") is not None |
| 30 | + assert pt.find("{http://www.topografix.com/GPX/1/1}time") is not None |
| 31 | + out = write_gpx(frames, tmp_path / "out.gpx") |
| 32 | + assert out.is_file() |
| 33 | + ET.parse(out) |
| 34 | + |
| 35 | + |
| 36 | +def test_kml_linestring_and_gx_track(classic_srt: Path, tmp_path: Path) -> None: |
| 37 | + frames = parse_srt_file(classic_srt) |
| 38 | + xml = frames_to_kml(frames) |
| 39 | + root = ET.fromstring(xml) |
| 40 | + assert root.tag.endswith("kml") |
| 41 | + coords = root.find(".//{http://www.opengis.net/kml/2.2}coordinates") |
| 42 | + assert coords is not None and coords.text and "," in coords.text |
| 43 | + whens = root.findall(".//{http://www.opengis.net/kml/2.2}when") |
| 44 | + gx_coords = root.findall(".//{http://www.google.com/kml/ext/2.2}coord") |
| 45 | + assert len(whens) == len(frames) |
| 46 | + assert len(gx_coords) == len(frames) |
| 47 | + alt_mode = root.find(".//{http://www.opengis.net/kml/2.2}altitudeMode") |
| 48 | + assert alt_mode is not None |
| 49 | + assert alt_mode.text in ("absolute", "relativeToGround") |
| 50 | + # classic fixture uses abs_alt -> absolute |
| 51 | + assert alt_mode.text == "absolute" |
| 52 | + out = write_kml(frames, tmp_path / "out.kml") |
| 53 | + ET.parse(out) |
0 commit comments