Back to index

python3.2  3.2.2
Public Member Functions
tkinter.test.test_ttk.test_extensions.LabeledScaleTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_widget_destroy
def test_initialization
def test_horizontal_range
def test_variable_change
def test_resize

Detailed Description

Definition at line 11 of file test_extensions.py.


Member Function Documentation

Definition at line 13 of file test_extensions.py.

00013 
00014     def setUp(self):
00015         support.root_deiconify()

Here is the caller graph for this function:

Definition at line 16 of file test_extensions.py.

00016 
00017     def tearDown(self):
00018         support.root_withdraw()
00019 

Here is the caller graph for this function:

Definition at line 106 of file test_extensions.py.

00106 
00107     def test_horizontal_range(self):
00108         lscale = ttk.LabeledScale(from_=0, to=10)
00109         lscale.pack()
00110         lscale.wait_visibility()
00111         lscale.update()
00112 
00113         linfo_1 = lscale.label.place_info()
00114         prev_xcoord = lscale.scale.coords()[0]
00115         self.assertEqual(prev_xcoord, int(linfo_1['x']))
00116         # change range to: from -5 to 5. This should change the x coord of
00117         # the scale widget, since 0 is at the middle of the new
00118         # range.
00119         lscale.scale.configure(from_=-5, to=5)
00120         # The following update is needed since the test doesn't use mainloop,
00121         # at the same time this shouldn't affect test outcome
00122         lscale.update()
00123         curr_xcoord = lscale.scale.coords()[0]
00124         self.assertTrue(prev_xcoord != curr_xcoord)
00125         # the label widget should have been repositioned too
00126         linfo_2 = lscale.label.place_info()
00127         self.assertEqual(lscale.label['text'], 0)
00128         self.assertEqual(curr_xcoord, int(linfo_2['x']))
00129         # change the range back
00130         lscale.scale.configure(from_=0, to=10)
00131         self.assertTrue(prev_xcoord != curr_xcoord)
00132         self.assertEqual(prev_xcoord, int(linfo_1['x']))
00133 
00134         lscale.destroy()
00135 

Here is the call graph for this function:

Definition at line 51 of file test_extensions.py.

00051 
00052     def test_initialization(self):
00053         # master passing
00054         x = ttk.LabeledScale()
00055         self.assertEqual(x.master, tkinter._default_root)
00056         x.destroy()
00057         master = tkinter.Frame()
00058         x = ttk.LabeledScale(master)
00059         self.assertEqual(x.master, master)
00060         x.destroy()
00061 
00062         # variable initialization/passing
00063         passed_expected = ((2.5, 2), ('0', 0), (0, 0), (10, 10),
00064             (-1, -1), (sys.maxsize + 1, sys.maxsize + 1))
00065         for pair in passed_expected:
00066             x = ttk.LabeledScale(from_=pair[0])
00067             self.assertEqual(x.value, pair[1])
00068             x.destroy()
00069         x = ttk.LabeledScale(from_='2.5')
00070         self.assertRaises(ValueError, x._variable.get)
00071         x.destroy()
00072         x = ttk.LabeledScale(from_=None)
00073         self.assertRaises(ValueError, x._variable.get)
00074         x.destroy()
00075         # variable should have its default value set to the from_ value
00076         myvar = tkinter.DoubleVar(value=20)
00077         x = ttk.LabeledScale(variable=myvar)
00078         self.assertEqual(x.value, 0)
00079         x.destroy()
00080         # check that it is really using a DoubleVar
00081         x = ttk.LabeledScale(variable=myvar, from_=0.5)
00082         self.assertEqual(x.value, 0.5)
00083         self.assertEqual(x._variable._name, myvar._name)
00084         x.destroy()
00085 
00086         # widget positionment
00087         def check_positions(scale, scale_pos, label, label_pos):
00088             self.assertEqual(scale.pack_info()['side'], scale_pos)
00089             self.assertEqual(label.place_info()['anchor'], label_pos)
00090         x = ttk.LabeledScale(compound='top')
00091         check_positions(x.scale, 'bottom', x.label, 'n')
00092         x.destroy()
00093         x = ttk.LabeledScale(compound='bottom')
00094         check_positions(x.scale, 'top', x.label, 's')
00095         x.destroy()
00096         x = ttk.LabeledScale(compound='unknown') # invert default positions
00097         check_positions(x.scale, 'top', x.label, 's')
00098         x.destroy()
00099         x = ttk.LabeledScale() # take default positions
00100         check_positions(x.scale, 'bottom', x.label, 'n')
00101         x.destroy()
00102 
00103         # extra, and invalid, kwargs
00104         self.assertRaises(tkinter.TclError, ttk.LabeledScale, a='b')
00105 

Here is the call graph for this function:

Definition at line 163 of file test_extensions.py.

00163 
00164     def test_resize(self):
00165         x = ttk.LabeledScale()
00166         x.pack(expand=True, fill='both')
00167         x.wait_visibility()
00168         x.update()
00169 
00170         width, height = x.master.winfo_width(), x.master.winfo_height()
00171         width_new, height_new = width * 2, height * 2
00172 
00173         x.value = 3
00174         x.update()
00175         x.master.wm_geometry("%dx%d" % (width_new, height_new))
00176         self.assertEqual(int(x.label.place_info()['x']),
00177             x.scale.coords()[0])
00178 
00179         # Reset geometry
00180         x.master.wm_geometry("%dx%d" % (width, height))
00181         x.destroy()
00182 

Here is the call graph for this function:

Definition at line 136 of file test_extensions.py.

00136 
00137     def test_variable_change(self):
00138         x = ttk.LabeledScale()
00139         x.pack()
00140         x.wait_visibility()
00141         x.update()
00142 
00143         curr_xcoord = x.scale.coords()[0]
00144         newval = x.value + 1
00145         x.value = newval
00146         # The following update is needed since the test doesn't use mainloop,
00147         # at the same time this shouldn't affect test outcome
00148         x.update()
00149         self.assertEqual(x.label['text'], newval)
00150         self.assertTrue(x.scale.coords()[0] > curr_xcoord)
00151         self.assertEqual(x.scale.coords()[0],
00152             int(x.label.place_info()['x']))
00153 
00154         # value outside range
00155         x.value = x.scale['to'] + 1 # no changes shouldn't happen
00156         x.update()
00157         self.assertEqual(x.label['text'], newval)
00158         self.assertEqual(x.scale.coords()[0],
00159             int(x.label.place_info()['x']))
00160 
00161         x.destroy()
00162 

Here is the call graph for this function:

Definition at line 20 of file test_extensions.py.

00020 
00021     def test_widget_destroy(self):
00022         # automatically created variable
00023         x = ttk.LabeledScale()
00024         var = x._variable._name
00025         x.destroy()
00026         self.assertRaises(tkinter.TclError, x.tk.globalgetvar, var)
00027 
00028         # manually created variable
00029         myvar = tkinter.DoubleVar()
00030         name = myvar._name
00031         x = ttk.LabeledScale(variable=myvar)
00032         x.destroy()
00033         self.assertEqual(x.tk.globalgetvar(name), myvar.get())
00034         del myvar
00035         self.assertRaises(tkinter.TclError, x.tk.globalgetvar, name)
00036 
00037         # checking that the tracing callback is properly removed
00038         myvar = tkinter.IntVar()
00039         # LabeledScale will start tracing myvar
00040         x = ttk.LabeledScale(variable=myvar)
00041         x.destroy()
00042         # Unless the tracing callback was removed, creating a new
00043         # LabeledScale with the same var will cause an error now. This
00044         # happens because the variable will be set to (possibly) a new
00045         # value which causes the tracing callback to be called and then
00046         # it tries calling instance attributes not yet defined.
00047         ttk.LabeledScale(variable=myvar)
00048         if hasattr(sys, 'last_type'):
00049             self.assertFalse(sys.last_type == tkinter.TclError)
00050 

Here is the call graph for this function:


The documentation for this class was generated from the following file: