66 lines
2 KiB
Python
66 lines
2 KiB
Python
"""Tests for the CSV and KVN export renderers added for the ODMS service."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import csv
|
|
import io
|
|
|
|
from odm import GP_FIELDS, OmmRecord, as_celestrak_csv, as_omm_kvn
|
|
|
|
|
|
def _record() -> OmmRecord:
|
|
omm = {
|
|
"OBJECT_NAME": "ISS (ZARYA)",
|
|
"OBJECT_ID": "1998-067A",
|
|
"EPOCH": "2026-05-13T22:14:00",
|
|
"MEAN_MOTION": 15.498,
|
|
"ECCENTRICITY": 0.000284,
|
|
"INCLINATION": 51.64,
|
|
"RA_OF_ASC_NODE": 20.23,
|
|
"ARG_OF_PERICENTER": 74.12,
|
|
"MEAN_ANOMALY": 10.2,
|
|
"EPHEMERIS_TYPE": 0,
|
|
"CLASSIFICATION_TYPE": "U",
|
|
"NORAD_CAT_ID": "25544",
|
|
"ELEMENT_SET_NO": 999,
|
|
"REV_AT_EPOCH": 100,
|
|
"BSTAR": 0.00012345,
|
|
"MEAN_MOTION_DOT": 7.2e-05,
|
|
"MEAN_MOTION_DDOT": 0.0,
|
|
}
|
|
return OmmRecord(omm=omm, object_name="ISS (ZARYA)", object_id="1998-067A", originator="YKSA")
|
|
|
|
|
|
def test_celestrak_csv_header_matches_gp_field_order():
|
|
text = as_celestrak_csv([_record()])
|
|
rows = list(csv.reader(io.StringIO(text)))
|
|
assert tuple(rows[0]) == GP_FIELDS
|
|
# One data row, NORAD in the right column.
|
|
assert rows[1][GP_FIELDS.index("NORAD_CAT_ID")] == "25544"
|
|
assert rows[1][GP_FIELDS.index("OBJECT_NAME")] == "ISS (ZARYA)"
|
|
|
|
|
|
def test_celestrak_csv_multiple_records():
|
|
text = as_celestrak_csv([_record(), _record()])
|
|
rows = list(csv.reader(io.StringIO(text)))
|
|
assert len(rows) == 3 # header + 2
|
|
|
|
|
|
def test_omm_kvn_has_version_and_key_value_lines():
|
|
text = as_omm_kvn([_record()], originator="YKSA")
|
|
assert text.startswith("CCSDS_OMM_VERS = 3.0")
|
|
kv = dict(
|
|
line.split(" = ", 1)
|
|
for line in text.splitlines()
|
|
if " = " in line
|
|
)
|
|
assert kv["ORIGINATOR"] == "YKSA"
|
|
assert kv["NORAD_CAT_ID"] == "25544"
|
|
assert kv["MEAN_ELEMENT_THEORY"] == "SGP4"
|
|
assert kv["INCLINATION"] == "51.64"
|
|
|
|
|
|
def test_omm_kvn_separates_records_with_blank_line():
|
|
text = as_omm_kvn([_record(), _record()])
|
|
assert text.count("CCSDS_OMM_VERS = 3.0") == 2
|
|
assert "\n\n" in text
|