@ -167,6 +167,78 @@ def test_endbildschirm_fehler_wird_abgefangen():
assert lcd . calls [ - 1 ] == " close "
assert lcd . calls [ - 1 ] == " close "
def test_auffrischung_genau_nach_ablauf_des_intervalls ( ) :
# fällig 600 s nach dem Verbindungsaufbau, danach 600 s nach der letzten (hier verspäteten) Auffrischung
times = iter ( [ 0 , 599 , 600 , 1250 , 1849 , 1850 ] )
lcd = FakeLcd ( )
run_fake ( lcd , iterations = 6 , monotonic = lambda : next ( times ) )
assert lcd . calls == [
" open " , " orientation " , ( " brightness " , 20 ) , " show " , # t=0
" orientation " , ( " brightness " , 20 ) , " show " , # t=600
" orientation " , ( " brightness " , 20 ) , " show " , # t=1250
" orientation " , ( " brightness " , 20 ) , " show " , # t=1850
" show " , " close " , # Endbildschirm
]
assert sizes ( lcd ) == [ ( 0 , 0 , ( 320 , 480 ) ) ] * 5 # unverändertes Bild trotzdem als Vollbild
def test_nach_neuverbindung_beginnt_auffrischungsintervall_neu ( ) :
# Bild 0 scheitert bei t=0, Wiederverbinden bei t=30 → nächste Auffrischung erst bei t=90, nicht bei t=60
times = iter ( [ 0 , 0 , 30 , 30 , 89 , 90 ] ) # Durchlauf, Fehler, Ausfalldauer, dann je Durchlauf
lcd = FakeLcd ( show_failures = { 0 } )
run_fake ( lcd , iterations = 4 , monotonic = lambda : next ( times ) , full_refresh_interval = 60 )
assert lcd . calls == [
" open " , " orientation " , ( " brightness " , 20 ) , " close " ,
" open " , " orientation " , ( " brightness " , 20 ) , " show " , # t=30
" orientation " , ( " brightness " , 20 ) , " show " , # t=90
" show " , " close " ,
]
class CommandFailingLcd ( FakeLcd ) :
""" Der n-te Aufruf (ab 0) von Ausrichtung oder Helligkeit scheitert mit einem Schreibfehler. """
def __init__ ( self , command , index ) :
super ( ) . __init__ ( )
self . failing = ( command , index )
self . counts = { " orientation " : 0 , " brightness " : 0 }
def _send ( self , command ) :
index = self . counts [ command ]
self . counts [ command ] + = 1
if ( command , index ) == self . failing :
raise OSError ( " Schreibfehler " )
def set_orientation_portrait ( self ) :
self . _send ( " orientation " )
super ( ) . set_orientation_portrait ( )
def set_brightness ( self , percent ) :
self . _send ( " brightness " )
super ( ) . set_brightness ( percent )
@pytest . mark . parametrize (
( " make_lcd " , " sent " ) ,
[
( lambda : CommandFailingLcd ( " orientation " , 1 ) , [ ] ) , # Aufruf 0 gehört zum Verbindungsaufbau
( lambda : CommandFailingLcd ( " brightness " , 1 ) , [ " orientation " ] ) ,
( lambda : FakeLcd ( show_failures = { 1 } ) , [ " orientation " , ( " brightness " , 20 ) ] ) , # Vollbild scheitert
] ,
ids = [ " ausrichtung " , " helligkeit " , " vollbild " ] ,
)
def test_fehler_bei_auffrischung_fuehrt_zu_neuverbindung ( make_lcd , sent ) :
times = iter ( [ 0 , 600 , 600 , 610 , 610 ] ) # Durchlauf, Auffrischung, Fehler, Ausfalldauer, Durchlauf
lcd = make_lcd ( )
run_fake ( lcd , iterations = 3 , monotonic = lambda : next ( times ) )
assert lcd . calls == [
" open " , " orientation " , ( " brightness " , 20 ) , " show " ,
* sent , " close " ,
" open " , " orientation " , ( " brightness " , 20 ) , " show " , # Neuverbindung mit Vollbild
" show " , " close " ,
]
class Clock :
class Clock :
""" Gesteuertes monotonic: liefert die zuletzt gesetzte Zeit. """
""" Gesteuertes monotonic: liefert die zuletzt gesetzte Zeit. """