okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
64b48c0d0
main
1"""F13 (QATUI 0213): `?` in the monitor shows the key list on the Overview as on the other views, and it stays up past the next poll.""" 2 3from __future__import annotations 4 5import asyncio 6import sys 7import unittest 8from pathlib import Path 9 10sys .path .insert (0 ,str (Path (__file__ ).resolve ().parent )) 11 12from test_overview import Source ,metrics # noqa: E402 13from strata_cli .monitor import MonitorApp # noqa: E402 14 15KEYS = "Space freeze r refresh t theme q detach" 16 17 18def last_line (app )-> str : 19return [s .text for s in app .screen ._compositor .render_strips ()][- 1 ] 20 21 22class Help (unittest .TestCase ): 23def _run (self ,view_key :str ): 24async def go (): 25# a one-second poll in real use; 0.2 s here so several polls pass while the help is up 26app = MonitorApp (Source (metrics ("generating" )),None ,interval = 0.2 ) 27async with app .run_test (size = (140 ,36 ))as pilot : 28await pilot .pause (0.5 ) 29await pilot .press (view_key ) 30await pilot .pause (0.3 ) 31self .assertNotIn ("Space freeze r refresh" ,last_line (app )) 32await pilot .press ("question_mark" ) 33await pilot .pause (1.0 )# several polls later 34self .assertIn (KEYS ,last_line (app )) 35await pilot .press ("question_mark" )# again: closes it 36await pilot .pause (0.3 ) 37self .assertNotIn ("Space freeze r refresh" ,last_line (app )) 38await pilot .press ("question_mark" ) 39await pilot .pause (0.3 ) 40self .assertIn (KEYS ,last_line (app )) 41await pilot .press ("escape" ) 42await pilot .pause (0.3 ) 43self .assertNotIn ("Space freeze r refresh" ,last_line (app )) 44asyncio .run (go ()) 45 46def test_overview (self ): 47self ._run ("1" ) 48 49def test_serving_view (self ): 50self ._run ("2" ) 51 52def test_changing_view_closes_it (self ): 53async def go (): 54app = MonitorApp (Source (metrics ("generating" )),None ,interval = 0.2 ) 55async with app .run_test (size = (140 ,36 ))as pilot : 56await pilot .pause (0.5 ) 57await pilot .press ("question_mark" ) 58await pilot .pause (0.3 ) 59self .assertIn (KEYS ,last_line (app )) 60await pilot .press ("3" ) 61await pilot .pause (0.3 ) 62self .assertNotIn ("Space freeze r refresh" ,last_line (app )) 63asyncio .run (go ()) 64 65def test_narrow_terminals_wrap_the_list_at_the_keys_and_show_every_key (self ): 66async def go (width ,height ): 67app = MonitorApp (Source (metrics ("generating" )),None ,interval = 0.2 ) 68async with app .run_test (size = (width ,height ))as pilot : 69await pilot .pause (0.5 ) 70for key in ("1" ,"2" ): 71await pilot .press (key ) 72await pilot .pause (0.3 ) 73await pilot .press ("question_mark" ) 74await pilot .pause (0.8 )# polls pass; it stays 75rows = [s .text .rstrip ()for s in app .screen ._compositor .render_strips ()] 76shown = "\n" .join (rows ) 77items = app ._help_line ().split (" " ) 78self .assertGreater (len (items ),5 ) 79for item in items : 80self .assertIn (item ,shown ,f" { width } x { height } view { key } : { item !r } cut off" ) 81self .assertTrue (all (len (r )<= width for r in rows )) 82self .assertGreater (len (app ._help_wrapped (width )),1 ,"narrower than the line: it wraps" ) 83await pilot .press ("question_mark" ) 84await pilot .pause (0.3 ) 85self .assertIn ("Read only" ,last_line (app ))# back to the one-line message 86for size in ((80 ,24 ), (60 ,16 )): 87asyncio .run (go (* size )) 88 89 90if __name__ == "__main__" : 91unittest .main ()