<s> import sys <EOL> sys . path . append ( "<STR_LIT:..>" ) <EOL> import unittest <EOL> import ansi <EOL> from termenu import Termenu , Plugin , FilterPlugin <EOL> OPTIONS = [ "<STR_LIT>" % i for i in xrange ( <NUM_LIT:1> , <NUM_LIT:100> ) ] <EOL> RESULTS = [ "<STR_LIT>" % i for i in xrange ( <NUM_LIT:1> , <NUM_LIT:100> ) ] <EOL> def strmenu ( menu ) : <EOL> return menu . _get_debug_view ( ) <EOL> class Down ( unittest . TestCase ) : <EOL> def test_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_down ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_middle ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . cursor = <NUM_LIT:1> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_down ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . cursor = <NUM_LIT:2> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_down ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_bottom_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:3> <EOL> menu . cursor = <NUM_LIT:2> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_down ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> class Up ( unittest . TestCase ) : <EOL> def test_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . cursor = <NUM_LIT:0> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_up ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_middle ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . cursor = <NUM_LIT:1> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_up ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . cursor = <NUM_LIT:2> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_up ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_bottom_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:3> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:3> <EOL> menu . cursor = <NUM_LIT:0> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_up ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> class PageDown ( unittest . TestCase ) : <EOL> def test_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageDown ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_middle ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . cursor = <NUM_LIT:1> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageDown ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . cursor = <NUM_LIT:3> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageDown ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_bottom_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:4> <EOL> menu . cursor = <NUM_LIT:3> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageDown ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_almost_bottom_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:5> <EOL> menu . cursor = <NUM_LIT:3> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageDown ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> class PageUp ( unittest . TestCase ) : <EOL> def test_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageUp ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_middle ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . cursor = <NUM_LIT:2> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageUp ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_cursor_bottom ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . cursor = <NUM_LIT:3> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageUp ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_bottom_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:4> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageUp ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_scroll_almost_top_cursor_top ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = <NUM_LIT:1> <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_pageUp ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> class Default ( unittest . TestCase ) : <EOL> def test_found ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_notfount ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_requires_scroll ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_last ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_before_last ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_multiple ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> def test_multiple_active ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> def test_multiple_empty_list ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , default = [ ] ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> class MultiSelect ( unittest . TestCase ) : <EOL> def test_select ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_space ( ) <EOL> menu . _on_space ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> def test_deselect ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_space ( ) <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> menu . _on_up ( ) <EOL> menu . _on_space ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert "<STR_LIT:U+0020>" . join ( menu . get_result ( ) ) == "<STR_LIT>" <EOL> def test_off ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , multiselect = False ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_space ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert menu . get_result ( ) == "<STR_LIT>" <EOL> class Results ( unittest . TestCase ) : <EOL> def test_single ( self ) : <EOL> menu = Termenu ( zip ( OPTIONS , RESULTS ) , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_down ( ) <EOL> menu . _on_down ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert menu . get_result ( ) == [ "<STR_LIT>" ] <EOL> def test_multiple ( self ) : <EOL> menu = Termenu ( zip ( OPTIONS , RESULTS ) , height = <NUM_LIT:4> ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_space ( ) <EOL> menu . _on_space ( ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert menu . get_result ( ) == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def active ( s ) : <EOL> return ansi . colorize ( s , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def selected ( s ) : <EOL> return ansi . colorize ( s , "<STR_LIT>" ) <EOL> def active_selected ( s ) : <EOL> return ansi . colorize ( s , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def white ( s ) : <EOL> return ansi . colorize ( s , "<STR_LIT>" , bright = True ) <EOL> class Decorate ( unittest . TestCase ) : <EOL> def test_active ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT:text>" , active = True ) == "<STR_LIT:U+0020>" + active ( "<STR_LIT:text>" ) + "<STR_LIT:U+0020>" <EOL> def test_selected ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT:text>" , selected = True ) == "<STR_LIT:*>" + selected ( "<STR_LIT:text>" ) + "<STR_LIT:U+0020>" <EOL> def test_active_selected ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT:text>" , active = True , selected = True ) == "<STR_LIT:*>" + active_selected ( "<STR_LIT:text>" ) + "<STR_LIT:U+0020>" <EOL> def test_more_above ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT:text>" , active = True , selected = True , moreAbove = True ) == "<STR_LIT:*>" + active_selected ( "<STR_LIT:text>" ) + "<STR_LIT:U+0020>" + white ( "<STR_LIT>" ) <EOL> def test_more_below ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT:text>" , active = True , selected = True , moreBelow = True ) == "<STR_LIT:*>" + active_selected ( "<STR_LIT:text>" ) + "<STR_LIT:U+0020>" + white ( "<STR_LIT:v>" ) <EOL> def test_max_opti_on_len ( self ) : <EOL> menu = Termenu ( "<STR_LIT>" . split ( ) , height = <NUM_LIT:4> ) <EOL> assert menu . _decorate ( "<STR_LIT>" , active = True , selected = True ) == "<STR_LIT:*>" + active_selected ( "<STR_LIT>" ) + "<STR_LIT:U+0020>" <EOL> class DecorateFlags ( unittest . TestCase ) : <EOL> def test_active ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ True , False , False , False ] <EOL> def test_selected ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . _on_down ( ) <EOL> menu . _on_space ( ) <EOL> menu . _on_space ( ) <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ False , True , True , False ] <EOL> def test_more_above_none ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ False , False , False , False ] <EOL> def test_more_above_one ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = <NUM_LIT:1> <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ True , False , False , False ] <EOL> def test_more_below_one ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ False , False , False , True ] <EOL> def test_more_below_none ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> ) <EOL> menu . scroll = len ( OPTIONS ) - <NUM_LIT:4> <EOL> assert [ menu . _decorate_flags ( i ) [ "<STR_LIT>" ] for i in xrange ( <NUM_LIT:4> ) ] == [ False , False , False , False ] <EOL> class Plugins ( unittest . TestCase ) : <EOL> class SamplePlugin ( Plugin ) : <EOL> def __init__ ( self , callPrev ) : <EOL> self . ran = False <EOL> self . callPrev = callPrev <EOL> def _on_key ( self , key ) : <EOL> self . ran = True <EOL> if self . callPrev : <EOL> self . parent . _on_key ( key ) <EOL> def test_multiple_plugins_all ( self ) : <EOL> plugins = [ self . SamplePlugin ( True ) , self . SamplePlugin ( True ) , self . SamplePlugin ( True ) ] <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , plugins = plugins ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert [ p . ran for p in plugins ] == [ True , True , True ] <EOL> def test_multiple_plugins_no_call_prev ( self ) : <EOL> plugins = [ self . SamplePlugin ( False ) , self . SamplePlugin ( False ) , self . SamplePlugin ( False ) ] <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , plugins = plugins ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> assert [ p . ran for p in plugins ] == [ False , False , True ] <EOL> class FilterPluginTest ( unittest . TestCase ) : <EOL> def test_filter ( self ) : <EOL> menu = Termenu ( OPTIONS , height = <NUM_LIT:4> , plugins = [ FilterPlugin ( ) ] ) <EOL> menu . _on_key ( "<STR_LIT:4>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_case_insensitive ( self ) : <EOL> menu = Termenu ( "<STR_LIT>" . split ( ) , height = <NUM_LIT:4> , plugins = [ FilterPlugin ( ) ] ) <EOL> menu . _on_key ( "<STR_LIT:e>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_backspace ( self ) : <EOL> menu = Termenu ( "<STR_LIT>" . split ( ) , height = <NUM_LIT:4> , plugins = [ FilterPlugin ( ) ] ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT:e>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT:n>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> def test_esc ( self ) : <EOL> menu = Termenu ( "<STR_LIT>" . split ( ) , height = <NUM_LIT:4> , plugins = [ FilterPlugin ( ) ] ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT:e>" ) <EOL> menu . _on_key ( "<STR_LIT:n>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> menu . _on_key ( "<STR_LIT>" ) <EOL> assert strmenu ( menu ) == "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
