<s> import sys <EOL> import unittest <EOL> import Tkinter <EOL> import ttk <EOL> from test . test_support import requires , run_unittest <EOL> import support <EOL> requires ( '<STR_LIT>' ) <EOL> class LabeledScaleTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> support . root_deiconify ( ) <EOL> def tearDown ( self ) : <EOL> support . root_withdraw ( ) <EOL> def test_widget_destroy ( self ) : <EOL> x = ttk . LabeledScale ( ) <EOL> var = x . _variable . _name <EOL> x . destroy ( ) <EOL> self . assertRaises ( Tkinter . TclError , x . tk . globalgetvar , var ) <EOL> myvar = Tkinter . DoubleVar ( ) <EOL> name = myvar . _name <EOL> x = ttk . LabeledScale ( variable = myvar ) <EOL> x . destroy ( ) <EOL> self . assertEqual ( x . tk . globalgetvar ( name ) , myvar . get ( ) ) <EOL> del myvar <EOL> self . assertRaises ( Tkinter . TclError , x . tk . globalgetvar , name ) <EOL> myvar = Tkinter . IntVar ( ) <EOL> x = ttk . LabeledScale ( variable = myvar ) <EOL> x . destroy ( ) <EOL> ttk . LabeledScale ( variable = myvar ) <EOL> if hasattr ( sys , '<STR_LIT>' ) : <EOL> self . assertFalse ( sys . last_type == Tkinter . TclError ) <EOL> def test_initialization ( self ) : <EOL> x = ttk . LabeledScale ( ) <EOL> self . assertEqual ( x . master , Tkinter . _default_root ) <EOL> x . destroy ( ) <EOL> master = Tkinter . Frame ( ) <EOL> x = ttk . LabeledScale ( master ) <EOL> self . assertEqual ( x . master , master ) <EOL> x . destroy ( ) <EOL> passed_expected = ( ( <NUM_LIT> , <NUM_LIT:2> ) , ( '<STR_LIT:0>' , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:10> , <NUM_LIT:10> ) , <EOL> ( - <NUM_LIT:1> , - <NUM_LIT:1> ) , ( sys . maxint + <NUM_LIT:1> , sys . maxint + <NUM_LIT:1> ) ) <EOL> for pair in passed_expected : <EOL> x = ttk . LabeledScale ( from_ = pair [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( x . value , pair [ <NUM_LIT:1> ] ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( from_ = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , x . _variable . get ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( from_ = None ) <EOL> self . assertRaises ( ValueError , x . _variable . get ) <EOL> x . destroy ( ) <EOL> myvar = Tkinter . DoubleVar ( value = <NUM_LIT:20> ) <EOL> x = ttk . LabeledScale ( variable = myvar ) <EOL> self . assertEqual ( x . value , <NUM_LIT:0> ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( variable = myvar , from_ = <NUM_LIT:0.5> ) <EOL> self . assertEqual ( x . value , <NUM_LIT:0.5> ) <EOL> self . assertEqual ( x . _variable . _name , myvar . _name ) <EOL> x . destroy ( ) <EOL> def check_positions ( scale , scale_pos , label , label_pos ) : <EOL> self . assertEqual ( scale . pack_info ( ) [ '<STR_LIT>' ] , scale_pos ) <EOL> self . assertEqual ( label . place_info ( ) [ '<STR_LIT>' ] , label_pos ) <EOL> x = ttk . LabeledScale ( compound = '<STR_LIT>' ) <EOL> check_positions ( x . scale , '<STR_LIT>' , x . label , '<STR_LIT:n>' ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( compound = '<STR_LIT>' ) <EOL> check_positions ( x . scale , '<STR_LIT>' , x . label , '<STR_LIT:s>' ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( compound = '<STR_LIT>' ) <EOL> check_positions ( x . scale , '<STR_LIT>' , x . label , '<STR_LIT:s>' ) <EOL> x . destroy ( ) <EOL> x = ttk . LabeledScale ( ) <EOL> check_positions ( x . scale , '<STR_LIT>' , x . label , '<STR_LIT:n>' ) <EOL> x . destroy ( ) <EOL> self . assertRaises ( Tkinter . TclError , ttk . LabeledScale , a = '<STR_LIT:b>' ) <EOL> def test_horizontal_range ( self ) : <EOL> lscale = ttk . LabeledScale ( from_ = <NUM_LIT:0> , to = <NUM_LIT:10> ) <EOL> lscale . pack ( ) <EOL> lscale . wait_visibility ( ) <EOL> lscale . update ( ) <EOL> linfo_1 = lscale . label . place_info ( ) <EOL> prev_xcoord = lscale . scale . coords ( ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( prev_xcoord , int ( linfo_1 [ '<STR_LIT:x>' ] ) ) <EOL> lscale . scale . configure ( from_ = - <NUM_LIT:5> , to = <NUM_LIT:5> ) <EOL> lscale . update ( ) <EOL> curr_xcoord = lscale . scale . coords ( ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( prev_xcoord != curr_xcoord ) <EOL> linfo_2 = lscale . label . place_info ( ) <EOL> self . assertEqual ( lscale . label [ '<STR_LIT:text>' ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( curr_xcoord , int ( linfo_2 [ '<STR_LIT:x>' ] ) ) <EOL> lscale . scale . configure ( from_ = <NUM_LIT:0> , to = <NUM_LIT:10> ) <EOL> self . assertTrue ( prev_xcoord != curr_xcoord ) <EOL> self . assertEqual ( prev_xcoord , int ( linfo_1 [ '<STR_LIT:x>' ] ) ) <EOL> lscale . destroy ( ) <EOL> def test_variable_change ( self ) : <EOL> x = ttk . LabeledScale ( ) <EOL> x . pack ( ) <EOL> x . wait_visibility ( ) <EOL> x . update ( ) <EOL> curr_xcoord = x . scale . coords ( ) [ <NUM_LIT:0> ] <EOL> newval = x . value + <NUM_LIT:1> <EOL> x . value = newval <EOL> x . update ( ) <EOL> self . assertEqual ( x . label [ '<STR_LIT:text>' ] , newval ) <EOL> self . assertTrue ( x . scale . coords ( ) [ <NUM_LIT:0> ] > curr_xcoord ) <EOL> self . assertEqual ( x . scale . coords ( ) [ <NUM_LIT:0> ] , <EOL> int ( x . label . place_info ( ) [ '<STR_LIT:x>' ] ) ) <EOL> x . value = x . scale [ '<STR_LIT:to>' ] + <NUM_LIT:1> <EOL> x . update ( ) <EOL> self . assertEqual ( x . label [ '<STR_LIT:text>' ] , newval ) <EOL> self . assertEqual ( x . scale . coords ( ) [ <NUM_LIT:0> ] , <EOL> int ( x . label . place_info ( ) [ '<STR_LIT:x>' ] ) ) <EOL> x . destroy ( ) <EOL> def test_resize ( self ) : <EOL> x = ttk . LabeledScale ( ) <EOL> x . pack ( expand = True , fill = '<STR_LIT>' ) <EOL> x . wait_visibility ( ) <EOL> x . update ( ) <EOL> width , height = x . master . winfo_width ( ) , x . master . winfo_height ( ) <EOL> width_new , height_new = width * <NUM_LIT:2> , height * <NUM_LIT:2> <EOL> x . value = <NUM_LIT:3> <EOL> x . update ( ) <EOL> x . master . wm_geometry ( "<STR_LIT>" % ( width_new , height_new ) ) <EOL> self . assertEqual ( int ( x . label . place_info ( ) [ '<STR_LIT:x>' ] ) , <EOL> x . scale . coords ( ) [ <NUM_LIT:0> ] ) <EOL> x . master . wm_geometry ( "<STR_LIT>" % ( width , height ) ) <EOL> x . destroy ( ) <EOL> class OptionMenuTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> support . root_deiconify ( ) <EOL> self . textvar = Tkinter . StringVar ( ) <EOL> def tearDown ( self ) : <EOL> del self . textvar <EOL> support . root_withdraw ( ) <EOL> def test_widget_destroy ( self ) : <EOL> var = Tkinter . StringVar ( ) <EOL> optmenu = ttk . OptionMenu ( None , var ) <EOL> name = var . _name <EOL> optmenu . update_idletasks ( ) <EOL> optmenu . destroy ( ) <EOL> self . assertEqual ( optmenu . tk . globalgetvar ( name ) , var . get ( ) ) <EOL> del var <EOL> self . assertRaises ( Tkinter . TclError , optmenu . tk . globalgetvar , name ) <EOL> def test_initialization ( self ) : <EOL> self . assertRaises ( Tkinter . TclError , <EOL> ttk . OptionMenu , None , self . textvar , invalid = '<STR_LIT>' ) <EOL> optmenu = ttk . OptionMenu ( None , self . textvar , '<STR_LIT:b>' , '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> self . assertEqual ( optmenu . _variable . get ( ) , '<STR_LIT:b>' ) <EOL> self . assertTrue ( optmenu [ '<STR_LIT>' ] ) <EOL> self . assertTrue ( optmenu [ '<STR_LIT>' ] ) <EOL> optmenu . destroy ( ) <EOL> def test_menu ( self ) : <EOL> items = ( '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) <EOL> default = '<STR_LIT:a>' <EOL> optmenu = ttk . OptionMenu ( None , self . textvar , default , * items ) <EOL> found_default = False <EOL> for i in range ( len ( items ) ) : <EOL> value = optmenu [ '<STR_LIT>' ] . entrycget ( i , '<STR_LIT:value>' ) <EOL> self . assertEqual ( value , items [ i ] ) <EOL> if value == default : <EOL> found_default = True <EOL> self . assertTrue ( found_default ) <EOL> optmenu . destroy ( ) <EOL> default = '<STR_LIT:d>' <EOL> optmenu = ttk . OptionMenu ( None , self . textvar , default , * items ) <EOL> curr = None <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> last , curr = curr , optmenu [ '<STR_LIT>' ] . entryconfigure ( i , '<STR_LIT:value>' ) <EOL> if last == curr : <EOL> break <EOL> self . assertFalse ( curr == default ) <EOL> i += <NUM_LIT:1> <EOL> self . assertEqual ( i , len ( items ) ) <EOL> optmenu . pack ( ) <EOL> optmenu . wait_visibility ( ) <EOL> optmenu [ '<STR_LIT>' ] . invoke ( <NUM_LIT:0> ) <EOL> self . assertEqual ( optmenu . _variable . get ( ) , items [ <NUM_LIT:0> ] ) <EOL> self . assertRaises ( Tkinter . TclError , optmenu [ '<STR_LIT>' ] . invoke , - <NUM_LIT:1> ) <EOL> self . assertEqual ( optmenu . _variable . get ( ) , items [ <NUM_LIT:0> ] ) <EOL> optmenu . destroy ( ) <EOL> success = [ ] <EOL> def cb_test ( item ) : <EOL> self . assertEqual ( item , items [ <NUM_LIT:1> ] ) <EOL> success . append ( True ) <EOL> optmenu = ttk . OptionMenu ( None , self . textvar , '<STR_LIT:a>' , command = cb_test , <EOL> * items ) <EOL> optmenu [ '<STR_LIT>' ] . invoke ( <NUM_LIT:1> ) <EOL> if not success : <EOL> self . fail ( "<STR_LIT>" ) <EOL> optmenu . destroy ( ) <EOL> tests_gui = ( LabeledScaleTest , OptionMenuTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> run_unittest ( * tests_gui ) </s>
