<s> from random import randint <EOL> import unittest <EOL> from asciimatics . scene import Scene <EOL> from asciimatics . screen import Screen <EOL> from tests . mock_objects import MockEffect <EOL> class TestScreen ( unittest . TestCase ) : <EOL> def test_wrapper ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> self . assertIsNotNone ( screen ) <EOL> self . assertGreater ( screen . width , <NUM_LIT:0> ) <EOL> self . assertGreater ( screen . height , <NUM_LIT:0> ) <EOL> self . assertGreater ( screen . colours , <NUM_LIT:0> ) <EOL> for x in range ( screen . width ) : <EOL> for y in range ( screen . height ) : <EOL> char , fg , attr , bg = screen . get_from ( x , y ) <EOL> self . assertEqual ( char , ord ( "<STR_LIT:U+0020>" ) ) <EOL> self . assertEqual ( fg , Screen . COLOUR_WHITE ) <EOL> self . assertEqual ( attr , <NUM_LIT:0> ) <EOL> self . assertEqual ( bg , Screen . COLOUR_BLACK ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_print_and_get ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> for x in range ( screen . width ) : <EOL> for y in range ( screen . height ) : <EOL> char = randint ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> fg = randint ( <NUM_LIT:0> , Screen . COLOUR_WHITE ) <EOL> bg = randint ( <NUM_LIT:0> , Screen . COLOUR_WHITE ) <EOL> attr = randint ( <NUM_LIT:0> , Screen . A_UNDERLINE ) <EOL> screen . print_at ( chr ( char ) , x , y , fg , attr , bg ) <EOL> char2 , fg2 , attr2 , bg2 = screen . get_from ( x , y ) <EOL> self . assertEqual ( char , char2 ) <EOL> self . assertEqual ( fg , fg2 ) <EOL> self . assertEqual ( attr , attr2 ) <EOL> self . assertEqual ( bg , bg2 ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_visible ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> self . assertTrue ( screen . is_visible ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> self . assertTrue ( screen . is_visible ( <EOL> screen . width - <NUM_LIT:1> , screen . height - <NUM_LIT:1> ) ) <EOL> self . assertFalse ( screen . is_visible ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> self . assertFalse ( screen . is_visible ( <EOL> screen . width , screen . height ) ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_paint ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> screen . paint ( <EOL> "<STR_LIT>" , <NUM_LIT:0> , <NUM_LIT:0> , <EOL> colour_map = ( ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:4> ) , ( <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:2> ) , ( <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:1> ) ) ) <EOL> char , fg , _ , bg = screen . get_from ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( fg , <NUM_LIT:1> ) <EOL> self . assertEqual ( bg , <NUM_LIT:4> ) <EOL> char , fg , _ , bg = screen . get_from ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> self . assertEqual ( fg , <NUM_LIT:4> ) <EOL> self . assertEqual ( bg , <NUM_LIT:1> ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_limits ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> self . assertEqual ( screen . dimensions [ <NUM_LIT:1> ] , screen . width ) <EOL> self . assertEqual ( screen . dimensions [ <NUM_LIT:0> ] , screen . height ) <EOL> self . assertIsNone ( screen . get_from ( - <NUM_LIT:1> , - <NUM_LIT:1> ) ) <EOL> self . assertIsNone ( screen . get_from ( screen . width , screen . height ) ) <EOL> screen . print_at ( "<STR_LIT:hello>" , <NUM_LIT:0> , - <NUM_LIT:1> ) <EOL> screen . print_at ( "<STR_LIT:hello>" , <NUM_LIT:0> , screen . height ) <EOL> screen . print_at ( "<STR_LIT>" , - <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> char , fg , _ , bg = screen . get_from ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . assertEqual ( char , ord ( "<STR_LIT:2>" ) ) <EOL> self . assertEqual ( fg , Screen . COLOUR_WHITE ) <EOL> self . assertEqual ( bg , Screen . COLOUR_BLACK ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_scroll ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> self . assertEqual ( screen . start_line , <NUM_LIT:0> ) <EOL> screen . scroll ( ) <EOL> self . assertEqual ( screen . start_line , <NUM_LIT:1> ) <EOL> screen . scroll_to ( <NUM_LIT:0> ) <EOL> self . assertEqual ( screen . start_line , <NUM_LIT:0> ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_centre ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> screen . centre ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> char , fg , _ , bg = screen . get_from ( ( screen . width - <NUM_LIT:4> ) // <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> self . assertEqual ( char , ord ( "<STR_LIT:1>" ) ) <EOL> self . assertEqual ( fg , Screen . COLOUR_WHITE ) <EOL> self . assertEqual ( bg , Screen . COLOUR_BLACK ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_draw ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> for line_type in ( True , False ) : <EOL> for start in range ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:10> ) : <EOL> screen . print_at ( str ( start ) , <NUM_LIT:11> , <NUM_LIT:2> ) <EOL> screen . move ( start , <NUM_LIT:0> ) <EOL> screen . draw ( <NUM_LIT:10> - start , <NUM_LIT:0> , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT>" if line_type else "<STR_LIT:#>" ) ) <EOL> screen . draw ( start , <NUM_LIT:0> , char = "<STR_LIT:U+0020>" , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:U+0020>" ) ) <EOL> screen . move ( <NUM_LIT:0> , start ) <EOL> screen . draw ( <NUM_LIT:0> , <NUM_LIT:10> - start , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:|>" if line_type else "<STR_LIT:#>" ) ) <EOL> screen . draw ( <NUM_LIT:0> , start , char = "<STR_LIT:U+0020>" , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:U+0020>" ) ) <EOL> screen . move ( <NUM_LIT:0> , start ) <EOL> screen . draw ( <NUM_LIT:10> , <NUM_LIT:10> - start , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:1> , <NUM_LIT:9> if start else <NUM_LIT:1> ) <EOL> if line_type : <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:/>" if start else "<STR_LIT:\\>" ) ) <EOL> else : <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:d>" if start else "<STR_LIT:Y>" ) ) <EOL> screen . move ( <NUM_LIT:0> , start ) <EOL> screen . draw ( <NUM_LIT:10> , <NUM_LIT:10> - start , char = "<STR_LIT:U+0020>" , thin = line_type ) <EOL> res = screen . get_from ( <NUM_LIT:1> , <NUM_LIT:9> if start else <NUM_LIT:1> ) <EOL> self . assertEqual ( res [ <NUM_LIT:0> ] , ord ( "<STR_LIT:U+0020>" ) ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_palette ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> self . assertGreater ( screen . colours , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( screen . palette ) , <NUM_LIT> * <NUM_LIT:3> ) <EOL> for i , c in enumerate ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> self . assertEqual ( screen . palette [ i ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT:3> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT:6> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT:9> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT:12> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT:15> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT> ] , c ) <EOL> for i , c in enumerate ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ) : <EOL> self . assertEqual ( screen . palette [ i + <NUM_LIT> ] , c ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_putch_and_getch ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> for x in range ( screen . width ) : <EOL> for y in range ( screen . height ) : <EOL> char = randint ( <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> fg = randint ( <NUM_LIT:0> , Screen . COLOUR_WHITE ) <EOL> bg = randint ( <NUM_LIT:0> , Screen . COLOUR_WHITE ) <EOL> attr = randint ( <NUM_LIT:0> , Screen . A_UNDERLINE ) <EOL> screen . putch ( chr ( char ) , x , y , fg , attr , bg ) <EOL> char2 , fg2 , attr2 , bg2 = screen . getch ( x , y ) <EOL> self . assertEqual ( char , char2 ) <EOL> self . assertEqual ( fg , fg2 ) <EOL> self . assertEqual ( attr , attr2 ) <EOL> self . assertEqual ( bg , bg2 ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_play ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> test_effect = MockEffect ( ) <EOL> screen . play ( [ Scene ( [ test_effect ] , <NUM_LIT:0> ) ] ) <EOL> self . assertTrue ( test_effect . stop_called ) <EOL> self . assertTrue ( test_effect . reset_called ) <EOL> test_effect = MockEffect ( count = <NUM_LIT:6> ) <EOL> screen . play ( [ Scene ( [ test_effect ] , <NUM_LIT:15> ) ] ) <EOL> self . assertFalse ( test_effect . stop_called ) <EOL> self . assertTrue ( test_effect . reset_called ) <EOL> Screen . wrapper ( internal_checks ) <EOL> def test_next_scene ( self ) : <EOL> """<STR_LIT>""" <EOL> def internal_checks ( screen ) : <EOL> test_effect1 = MockEffect ( stop = False ) <EOL> test_effect2 = MockEffect ( count = <NUM_LIT:5> ) <EOL> screen . play ( [ <EOL> Scene ( [ test_effect1 ] , <NUM_LIT:5> ) , <EOL> Scene ( [ test_effect2 ] , <NUM_LIT:0> ) ] ) <EOL> self . assertTrue ( test_effect1 . reset_called ) <EOL> self . assertTrue ( test_effect2 . reset_called ) <EOL> test_effect1 = MockEffect ( stop = False ) <EOL> scene1 = Scene ( [ test_effect1 ] , <NUM_LIT:5> , name = "<STR_LIT:1>" ) <EOL> test_effect2 = MockEffect ( count = <NUM_LIT:3> ) <EOL> scene2 = Scene ( [ test_effect2 ] , <NUM_LIT:0> , name = "<STR_LIT:2>" ) <EOL> screen . play ( [ scene1 , scene2 ] , start_scene = scene2 ) <EOL> self . assertFalse ( test_effect1 . reset_called ) <EOL> self . assertTrue ( test_effect2 . reset_called ) <EOL> Screen . wrapper ( internal_checks ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
