Two new views, picked from mockups. `sky`: a star chart of the sky over Zlín as seen lying on your back, with the planets, the moon in its phase, tonight's darkness, cloud for the next 12 hours and the next visible ISS pass. `iss`: a dotted world map with day and night, the ISS and its ground track, and the next pass over Zlín with the cloud cover for that hour. Positions are calculated locally with ephem; only the ISS orbit (CelesTrak, every 6 h, retried gently) and cloud cover (Open-Meteo) are fetched. The poller gained a per-source retry delay for that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
import json
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from PIL import ImageChops
|
|
|
|
import astro
|
|
from iss_view import MAP_TOP, MARKER, IssView, is_day, map_xy
|
|
from sky_data import parse_clouds, parse_tle
|
|
from tests.helpers import count_near
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
TLE = parse_tle((FIXTURES / "celestrak-iss.tle").read_text())
|
|
CLOUDS = parse_clouds(json.loads((FIXTURES / "open-meteo-clouds.json").read_text()))
|
|
NOW = datetime(2026, 10, 28, 19, 30, 8)
|
|
NIGHT_IN_ZLIN = (-13.3, -101.5) # subsolar point at that moment
|
|
|
|
|
|
class StubPoller:
|
|
def __init__(self, value=None, version=1, age=60.0):
|
|
self.value, self.version, self._age = value, version, age
|
|
self.failures = 0
|
|
|
|
def age(self):
|
|
return self._age
|
|
|
|
def start(self):
|
|
pass
|
|
|
|
def stop(self):
|
|
pass
|
|
|
|
|
|
def view(tle=TLE, clouds=CLOUDS, tle_age=3600.0):
|
|
return IssView(StubPoller(tle, age=tle_age), StubPoller(clouds))
|
|
|
|
|
|
def test_render_size_is_480x320():
|
|
assert view().render(NOW).size == (480, 320)
|
|
|
|
|
|
def test_frame_key_changes_every_ten_seconds():
|
|
v = view()
|
|
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 0)) == v.frame_key(datetime(2026, 10, 28, 19, 30, 9))
|
|
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 9)) != v.frame_key(datetime(2026, 10, 28, 19, 30, 10))
|
|
|
|
|
|
def test_frame_key_changes_when_the_orbit_updates():
|
|
tle = StubPoller(TLE)
|
|
v = IssView(tle, StubPoller(CLOUDS))
|
|
before = v.frame_key(NOW)
|
|
tle.version = 2
|
|
assert v.frame_key(NOW) != before
|
|
|
|
|
|
def test_nothing_to_patch_between_frames():
|
|
assert view().patch(NOW) is None
|
|
|
|
|
|
def test_map_is_equirectangular_under_the_header():
|
|
assert map_xy(0, 0) == pytest.approx((240, MAP_TOP + 120))
|
|
assert map_xy(90, -180) == pytest.approx((0, MAP_TOP))
|
|
assert map_xy(-90, 180) == pytest.approx((480, MAP_TOP + 240))
|
|
|
|
|
|
def test_day_and_night():
|
|
assert is_day(0, 0, (0, 0))
|
|
assert not is_day(0, 180, (0, 0))
|
|
assert not is_day(49.2, 17.7, NIGHT_IN_ZLIN) # Zlín at 19:30 in October
|
|
assert is_day(-10, -50, NIGHT_IN_ZLIN) # Brazil in the afternoon
|
|
|
|
|
|
def test_marker_is_where_the_iss_is():
|
|
img = view().render(NOW)
|
|
fix = astro.iss_fix(TLE, NOW)
|
|
x, y = map_xy(fix.lat, fix.lon)
|
|
assert count_near(img, MARKER, 40, (int(x) - 9, int(y) - 9, int(x) + 10, int(y) + 10)) > 20
|
|
|
|
|
|
def test_without_an_orbit_there_is_no_marker():
|
|
with_orbit, without = view().render(NOW), view(tle=None).render(NOW)
|
|
fix = astro.iss_fix(TLE, NOW)
|
|
x, y = map_xy(fix.lat, fix.lon)
|
|
box = (int(x) - 9, int(y) - 9, int(x) + 10, int(y) + 10)
|
|
assert count_near(without, MARKER, 40, box) < count_near(with_orbit, MARKER, 40, box) / 4
|
|
|
|
|
|
def test_stale_tag_only_when_the_orbit_is_old_and_only_in_the_header():
|
|
fresh = view().render(NOW)
|
|
old = view(tle_age=4 * 86400).render(NOW)
|
|
bbox = ImageChops.difference(fresh, old).getbbox()
|
|
assert bbox is not None and bbox[3] <= MAP_TOP
|