SPB Git forge
3commits 1branches 0releases
417.0 KBsize
maindefault branch
10 days agolast push
TypeScript 66.5% Python 30.9% JavaScript 1.4% CSS 0.7%
3.4 KB · 66 lines python
Raw Blame History
1"""Connector parsing and classification on fixtures — never hits the network."""2from __future__ import annotations34from pathlib import Path56from satelliteindex import registry7from satelliteindex.connectors.orbital.celestrak.gp import parse_omm8from satelliteindex.connectors.orbital.celestrak.satcat import CelesTrakSatcatConnector9from satelliteindex.ids import normalize_name, satellite_slug, slugify10from satelliteindex.registry.reference import LAUNCH_SITES, OWNER_CODES, SATCAT_STATUS11from satelliteindex.services.classify import Classifier, object_type_from_name1213FIX = Path(__file__).parent / "fixtures"141516def test_parse_omm_stations():17    recs = parse_omm((FIX / "celestrak_stations.json").read_text())18    assert len(recs) >= 1019    iss = next(r for r in recs if r["norad"] == 25544)20    assert iss["cospar"] == "1998-067A" and iss["epoch"].tzinfo is not None21    assert 15 < iss["mean_motion"] < 16222324def test_parse_satcat_head():25    rows = CelesTrakSatcatConnector().parse((FIX / "satcat_head.csv").read_text())26    assert len(rows) >= 15027    sputnik = next(r for r in rows if r["norad"] == 2)28    assert sputnik["type"] == "PAYLOAD" and sputnik["owner"] == "CIS" and sputnik["decay"] is not None and sputnik["site"] == "TYMSC"29    assert SATCAT_STATUS[sputnik["ops"]] == "DECAYED"30    assert all(r["owner"] in OWNER_CODES for r in rows if r["owner"])31    assert all(r["site"] in LAUNCH_SITES for r in rows if r["site"])323334def test_registry_patterns():35    assert registry.match_constellation("STARLINK-32001").slug == "starlink"36    assert registry.match_constellation("ONEWEB-0123").slug == "oneweb"37    assert registry.match_constellation("NAVSTAR 81 (USA 343)").slug == "gps"38    assert registry.match_constellation("ISS (ZARYA)").slug == "iss"39    assert registry.match_constellation("COSMOS 2576").slug == "cosmos"40    assert registry.match_constellation("GALAXY 37 (HORIZONS 4)").slug == "intelsat"41    assert registry.match_constellation("FLOCK 4X-12").slug == "planet-flock"42    assert registry.match_constellation("RANDOM OBJECT 42") is None43    assert registry.match_mission("NOAA 19") == "weather"44    assert registry.match_mission("LANDSAT 9") == "earth-observation"45    assert registry.match_mission("HST") == "science"464748def test_classifier_offline():49    clf = Classifier(constellation_ids={"starlink": "con_1", "gps": "con_2"}, constellation_ops={"starlink": "org_spacex", "gps": "org_ussf"},50                     org_ids={"spacex": "org_spacex", "us-space-force": "org_ussf"}, owner_map={"US": ("US", None), "SES": ("LU", "org_ses")})51    out = clf.classify("STARLINK-1007", "US", "PAYLOAD")52    assert out == {"constellation_id": "con_1", "operator_id": "org_spacex", "country_code": "US", "mission_type": "communications", "method": "name_pattern"}53    out = clf.classify("SES-17", "SES", "PAYLOAD")54    assert out["operator_id"] == "org_ses" and out["country_code"] == "LU"55    out = clf.classify("SL-16 R/B", "CIS", "ROCKET_BODY")56    assert out["mission_type"] == "rocket-body" and out["constellation_id"] is None57    assert object_type_from_name("ISS (ZARYA)", "PAYLOAD") == "STATION"58    assert object_type_from_name("STARLINK-1", "PAYLOAD") == "PAYLOAD"596061def test_ids_and_slugs():62    assert slugify("ISS (ZARYA)") == "iss-zarya"63    assert satellite_slug("ISS (ZARYA)", 25544) == "iss-zarya-25544"64    assert normalize_name("Space Exploration Technologies Corp.") == "SPACE EXPLORATION TECHNOLOGIES CORP"65    assert slugify("Ñusat-1 (Fresco)") == "nusat-1-fresco"66