Cyberpunk 2077 look for the server view, refreshed every second
Rajdhani font (OFL), chamfered/glitch drawing kit, Docker list every 5 s and process ranking over 3 s windows so the 1 s refresh stays cheap and calm. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
edba341f30
commit
5e64bfb64e
15 files changed
+524
-95
No files matched your search
+47
-12
@@ -2,10 +2,10 @@ from datetime import datetime
|
||||
|
||||
from PIL import ImageChops
|
||||
|
||||
from lcdkit import INK
|
||||
from cyber import DIM, RED, TEXT
|
||||
from server_view import ServerView
|
||||
from stats_data import Container, Proc, Stats
|
||||
from tests.helpers import count_colour
|
||||
from tests.helpers import count_colour, count_near
|
||||
|
||||
NOW = datetime(2026, 10, 22, 14, 32, 8)
|
||||
|
||||
@@ -49,10 +49,13 @@ def test_render_size_is_480x320():
|
||||
assert view(stats()).render(NOW).size == (480, 320)
|
||||
|
||||
|
||||
def test_frame_key_changes_every_five_seconds():
|
||||
v = view(stats())
|
||||
assert v.frame_key(datetime(2026, 10, 22, 14, 32, 5)) == v.frame_key(datetime(2026, 10, 22, 14, 32, 9))
|
||||
assert v.frame_key(datetime(2026, 10, 22, 14, 32, 9)) != v.frame_key(datetime(2026, 10, 22, 14, 32, 10))
|
||||
def test_frame_key_follows_the_data_not_the_clock():
|
||||
p = StubPoller(stats(), version=1)
|
||||
v = ServerView(p)
|
||||
before = v.frame_key(datetime(2026, 10, 22, 14, 32, 5))
|
||||
assert before == v.frame_key(datetime(2026, 10, 22, 14, 32, 40)) # the clock does not matter
|
||||
p.version = 2
|
||||
assert v.frame_key(datetime(2026, 10, 22, 14, 32, 5)) != before # new data does
|
||||
|
||||
|
||||
def test_frame_key_changes_on_new_data_and_stale_flip():
|
||||
@@ -89,14 +92,21 @@ def test_stale_tag_only_when_old():
|
||||
old = view(stats(), age=ServerView.STALE_AFTER + 5).render(NOW)
|
||||
bbox = region_diff(fresh, old)
|
||||
assert bbox is not None
|
||||
assert bbox[0] >= 360 and bbox[1] >= 12 and bbox[3] <= 40
|
||||
assert bbox[0] >= 360 and bbox[1] >= 12 and bbox[3] <= 44 # only the top-right status corner changes
|
||||
|
||||
|
||||
def test_bar_reflects_value():
|
||||
def test_gauge_reflects_value():
|
||||
idle = view(stats(cpu_pct=0.0)).render(NOW)
|
||||
busy = view(stats(cpu_pct=100.0)).render(NOW)
|
||||
box = (72, 54, 232, 78) # the CPU bar
|
||||
assert count_colour(busy, INK, box) > count_colour(idle, INK, box) + 500
|
||||
busy = view(stats(cpu_pct=60.0)).render(NOW)
|
||||
box = (24, 76, 246, 86) # the CPU gauge
|
||||
assert count_colour(busy, DIM, box) < count_colour(idle, DIM, box) - 500
|
||||
|
||||
|
||||
def test_hot_gauge_turns_red():
|
||||
box = (24, 76, 246, 86)
|
||||
calm = view(stats(cpu_pct=20.0)).render(NOW)
|
||||
hot = view(stats(cpu_pct=95.0)).render(NOW)
|
||||
assert count_colour(hot, RED, box) > count_colour(calm, RED, box) + 500
|
||||
|
||||
|
||||
def test_no_docker_differs_from_container_list():
|
||||
@@ -104,7 +114,7 @@ def test_no_docker_differs_from_container_list():
|
||||
missing = view(stats(containers=None)).render(NOW)
|
||||
bbox = region_diff(listed, missing)
|
||||
assert bbox is not None
|
||||
assert bbox[1] >= 160 and bbox[2] <= 304 # only the docker panel changes
|
||||
assert bbox[1] >= 176 and bbox[2] <= 322 # only the docker panel changes
|
||||
|
||||
|
||||
def test_attention_containers_sort_first():
|
||||
@@ -113,3 +123,28 @@ def test_attention_containers_sort_first():
|
||||
first_rows = view(stats(containers=fine + (sick,))).render(NOW)
|
||||
sorted_ok = view(stats(containers=(sick,) + fine)).render(NOW)
|
||||
assert region_diff(first_rows, sorted_ok) is None # input order does not matter
|
||||
|
||||
|
||||
def test_failed_container_gets_a_red_chip():
|
||||
ok = view(stats(containers=containers(3))).render(NOW)
|
||||
broken = view(stats(containers=containers(2) + (Container("zzz", "exited", None),))).render(NOW)
|
||||
panel = (24, 196, 322, 300)
|
||||
assert count_colour(broken, RED, panel) > count_colour(ok, RED, panel) + 100
|
||||
|
||||
|
||||
def test_long_container_name_stays_in_its_column():
|
||||
long_name = Container("an-extraordinarily-long-container-name-that-would-run-into-the-process-list", "running", "healthy")
|
||||
img = view(stats(containers=(long_name,) + containers(2))).render(NOW)
|
||||
process_column = (326, 196, 470, 300)
|
||||
assert count_near(img, TEXT, 20, process_column) == 0 # container names are the only near-white text
|
||||
|
||||
|
||||
def test_status_chip_is_wide_enough_for_its_label():
|
||||
import numpy as np
|
||||
from cyber import INK
|
||||
img = view(stats(containers=(Container("web", "running", "unhealthy"),))).render(NOW)
|
||||
panel = np.asarray(img.crop((24, 196, 322, 300)).convert("RGB"))
|
||||
ys, xs = np.where((panel == np.array(RED)).all(axis=2))
|
||||
ink_ys, ink_xs = np.where((panel == np.array(INK)).all(axis=2)) # the label is drawn in INK on the chip
|
||||
assert len(xs) > 0 and len(ink_xs) > 0
|
||||
assert ink_xs.min() > xs.min() and ink_xs.max() < xs.max() # the label sits inside the chip, not past its edges
|
||||
Reference in new issue
Block a user