ยปCore Development>Code coverage>Lib/tkinter/test/test_tkinter/test_widgets.py

Python code coverage for Lib/tkinter/test/test_tkinter/test_widgets.py

#countcontent
1n/aimport unittest
2n/aimport tkinter
3n/afrom tkinter import TclError
4n/aimport os
5n/aimport sys
6n/afrom test.support import requires
7n/a
8n/afrom tkinter.test.support import (tcl_version, requires_tcl,
9n/a get_tk_patchlevel, widget_eq)
10n/afrom tkinter.test.widget_tests import (
11n/a add_standard_options, noconv, pixels_round,
12n/a AbstractWidgetTest, StandardOptionsTests, IntegerSizeTests, PixelSizeTests,
13n/a setUpModule)
14n/a
15n/arequires('gui')
16n/a
17n/a
18n/adef float_round(x):
19n/a return float(round(x))
20n/a
21n/a
22n/aclass AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests):
23n/a _conv_pad_pixels = noconv
24n/a
25n/a def test_class(self):
26n/a widget = self.create()
27n/a self.assertEqual(widget['class'],
28n/a widget.__class__.__name__.title())
29n/a self.checkInvalidParam(widget, 'class', 'Foo',
30n/a errmsg="can't modify -class option after widget is created")
31n/a widget2 = self.create(class_='Foo')
32n/a self.assertEqual(widget2['class'], 'Foo')
33n/a
34n/a def test_colormap(self):
35n/a widget = self.create()
36n/a self.assertEqual(widget['colormap'], '')
37n/a self.checkInvalidParam(widget, 'colormap', 'new',
38n/a errmsg="can't modify -colormap option after widget is created")
39n/a widget2 = self.create(colormap='new')
40n/a self.assertEqual(widget2['colormap'], 'new')
41n/a
42n/a def test_container(self):
43n/a widget = self.create()
44n/a self.assertEqual(widget['container'], 0 if self.wantobjects else '0')
45n/a self.checkInvalidParam(widget, 'container', 1,
46n/a errmsg="can't modify -container option after widget is created")
47n/a widget2 = self.create(container=True)
48n/a self.assertEqual(widget2['container'], 1 if self.wantobjects else '1')
49n/a
50n/a def test_visual(self):
51n/a widget = self.create()
52n/a self.assertEqual(widget['visual'], '')
53n/a self.checkInvalidParam(widget, 'visual', 'default',
54n/a errmsg="can't modify -visual option after widget is created")
55n/a widget2 = self.create(visual='default')
56n/a self.assertEqual(widget2['visual'], 'default')
57n/a
58n/a
59n/a@add_standard_options(StandardOptionsTests)
60n/aclass ToplevelTest(AbstractToplevelTest, unittest.TestCase):
61n/a OPTIONS = (
62n/a 'background', 'borderwidth',
63n/a 'class', 'colormap', 'container', 'cursor', 'height',
64n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
65n/a 'menu', 'padx', 'pady', 'relief', 'screen',
66n/a 'takefocus', 'use', 'visual', 'width',
67n/a )
68n/a
69n/a def create(self, **kwargs):
70n/a return tkinter.Toplevel(self.root, **kwargs)
71n/a
72n/a def test_menu(self):
73n/a widget = self.create()
74n/a menu = tkinter.Menu(self.root)
75n/a self.checkParam(widget, 'menu', menu, eq=widget_eq)
76n/a self.checkParam(widget, 'menu', '')
77n/a
78n/a def test_screen(self):
79n/a widget = self.create()
80n/a self.assertEqual(widget['screen'], '')
81n/a try:
82n/a display = os.environ['DISPLAY']
83n/a except KeyError:
84n/a self.skipTest('No $DISPLAY set.')
85n/a self.checkInvalidParam(widget, 'screen', display,
86n/a errmsg="can't modify -screen option after widget is created")
87n/a widget2 = self.create(screen=display)
88n/a self.assertEqual(widget2['screen'], display)
89n/a
90n/a def test_use(self):
91n/a widget = self.create()
92n/a self.assertEqual(widget['use'], '')
93n/a parent = self.create(container=True)
94n/a wid = hex(parent.winfo_id())
95n/a with self.subTest(wid=wid):
96n/a widget2 = self.create(use=wid)
97n/a self.assertEqual(widget2['use'], wid)
98n/a
99n/a
100n/a@add_standard_options(StandardOptionsTests)
101n/aclass FrameTest(AbstractToplevelTest, unittest.TestCase):
102n/a OPTIONS = (
103n/a 'background', 'borderwidth',
104n/a 'class', 'colormap', 'container', 'cursor', 'height',
105n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
106n/a 'padx', 'pady', 'relief', 'takefocus', 'visual', 'width',
107n/a )
108n/a
109n/a def create(self, **kwargs):
110n/a return tkinter.Frame(self.root, **kwargs)
111n/a
112n/a
113n/a@add_standard_options(StandardOptionsTests)
114n/aclass LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
115n/a OPTIONS = (
116n/a 'background', 'borderwidth',
117n/a 'class', 'colormap', 'container', 'cursor',
118n/a 'font', 'foreground', 'height',
119n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
120n/a 'labelanchor', 'labelwidget', 'padx', 'pady', 'relief',
121n/a 'takefocus', 'text', 'visual', 'width',
122n/a )
123n/a
124n/a def create(self, **kwargs):
125n/a return tkinter.LabelFrame(self.root, **kwargs)
126n/a
127n/a def test_labelanchor(self):
128n/a widget = self.create()
129n/a self.checkEnumParam(widget, 'labelanchor',
130n/a 'e', 'en', 'es', 'n', 'ne', 'nw',
131n/a 's', 'se', 'sw', 'w', 'wn', 'ws')
132n/a self.checkInvalidParam(widget, 'labelanchor', 'center')
133n/a
134n/a def test_labelwidget(self):
135n/a widget = self.create()
136n/a label = tkinter.Label(self.root, text='Mupp', name='foo')
137n/a self.checkParam(widget, 'labelwidget', label, expected='.foo')
138n/a label.destroy()
139n/a
140n/a
141n/aclass AbstractLabelTest(AbstractWidgetTest, IntegerSizeTests):
142n/a _conv_pixels = noconv
143n/a
144n/a def test_highlightthickness(self):
145n/a widget = self.create()
146n/a self.checkPixelsParam(widget, 'highlightthickness',
147n/a 0, 1.3, 2.6, 6, -2, '10p')
148n/a
149n/a
150n/a@add_standard_options(StandardOptionsTests)
151n/aclass LabelTest(AbstractLabelTest, unittest.TestCase):
152n/a OPTIONS = (
153n/a 'activebackground', 'activeforeground', 'anchor',
154n/a 'background', 'bitmap', 'borderwidth', 'compound', 'cursor',
155n/a 'disabledforeground', 'font', 'foreground', 'height',
156n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
157n/a 'image', 'justify', 'padx', 'pady', 'relief', 'state',
158n/a 'takefocus', 'text', 'textvariable',
159n/a 'underline', 'width', 'wraplength',
160n/a )
161n/a
162n/a def create(self, **kwargs):
163n/a return tkinter.Label(self.root, **kwargs)
164n/a
165n/a
166n/a@add_standard_options(StandardOptionsTests)
167n/aclass ButtonTest(AbstractLabelTest, unittest.TestCase):
168n/a OPTIONS = (
169n/a 'activebackground', 'activeforeground', 'anchor',
170n/a 'background', 'bitmap', 'borderwidth',
171n/a 'command', 'compound', 'cursor', 'default',
172n/a 'disabledforeground', 'font', 'foreground', 'height',
173n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
174n/a 'image', 'justify', 'overrelief', 'padx', 'pady', 'relief',
175n/a 'repeatdelay', 'repeatinterval',
176n/a 'state', 'takefocus', 'text', 'textvariable',
177n/a 'underline', 'width', 'wraplength')
178n/a
179n/a def create(self, **kwargs):
180n/a return tkinter.Button(self.root, **kwargs)
181n/a
182n/a def test_default(self):
183n/a widget = self.create()
184n/a self.checkEnumParam(widget, 'default', 'active', 'disabled', 'normal')
185n/a
186n/a
187n/a@add_standard_options(StandardOptionsTests)
188n/aclass CheckbuttonTest(AbstractLabelTest, unittest.TestCase):
189n/a OPTIONS = (
190n/a 'activebackground', 'activeforeground', 'anchor',
191n/a 'background', 'bitmap', 'borderwidth',
192n/a 'command', 'compound', 'cursor',
193n/a 'disabledforeground', 'font', 'foreground', 'height',
194n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
195n/a 'image', 'indicatoron', 'justify',
196n/a 'offrelief', 'offvalue', 'onvalue', 'overrelief',
197n/a 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state',
198n/a 'takefocus', 'text', 'textvariable',
199n/a 'tristateimage', 'tristatevalue',
200n/a 'underline', 'variable', 'width', 'wraplength',
201n/a )
202n/a
203n/a def create(self, **kwargs):
204n/a return tkinter.Checkbutton(self.root, **kwargs)
205n/a
206n/a
207n/a def test_offvalue(self):
208n/a widget = self.create()
209n/a self.checkParams(widget, 'offvalue', 1, 2.3, '', 'any string')
210n/a
211n/a def test_onvalue(self):
212n/a widget = self.create()
213n/a self.checkParams(widget, 'onvalue', 1, 2.3, '', 'any string')
214n/a
215n/a
216n/a@add_standard_options(StandardOptionsTests)
217n/aclass RadiobuttonTest(AbstractLabelTest, unittest.TestCase):
218n/a OPTIONS = (
219n/a 'activebackground', 'activeforeground', 'anchor',
220n/a 'background', 'bitmap', 'borderwidth',
221n/a 'command', 'compound', 'cursor',
222n/a 'disabledforeground', 'font', 'foreground', 'height',
223n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
224n/a 'image', 'indicatoron', 'justify', 'offrelief', 'overrelief',
225n/a 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state',
226n/a 'takefocus', 'text', 'textvariable',
227n/a 'tristateimage', 'tristatevalue',
228n/a 'underline', 'value', 'variable', 'width', 'wraplength',
229n/a )
230n/a
231n/a def create(self, **kwargs):
232n/a return tkinter.Radiobutton(self.root, **kwargs)
233n/a
234n/a def test_value(self):
235n/a widget = self.create()
236n/a self.checkParams(widget, 'value', 1, 2.3, '', 'any string')
237n/a
238n/a
239n/a@add_standard_options(StandardOptionsTests)
240n/aclass MenubuttonTest(AbstractLabelTest, unittest.TestCase):
241n/a OPTIONS = (
242n/a 'activebackground', 'activeforeground', 'anchor',
243n/a 'background', 'bitmap', 'borderwidth',
244n/a 'compound', 'cursor', 'direction',
245n/a 'disabledforeground', 'font', 'foreground', 'height',
246n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
247n/a 'image', 'indicatoron', 'justify', 'menu',
248n/a 'padx', 'pady', 'relief', 'state',
249n/a 'takefocus', 'text', 'textvariable',
250n/a 'underline', 'width', 'wraplength',
251n/a )
252n/a _conv_pixels = staticmethod(pixels_round)
253n/a
254n/a def create(self, **kwargs):
255n/a return tkinter.Menubutton(self.root, **kwargs)
256n/a
257n/a def test_direction(self):
258n/a widget = self.create()
259n/a self.checkEnumParam(widget, 'direction',
260n/a 'above', 'below', 'flush', 'left', 'right')
261n/a
262n/a def test_height(self):
263n/a widget = self.create()
264n/a self.checkIntegerParam(widget, 'height', 100, -100, 0, conv=str)
265n/a
266n/a test_highlightthickness = StandardOptionsTests.test_highlightthickness
267n/a
268n/a @unittest.skipIf(sys.platform == 'darwin',
269n/a 'crashes with Cocoa Tk (issue19733)')
270n/a def test_image(self):
271n/a widget = self.create()
272n/a image = tkinter.PhotoImage(master=self.root, name='image1')
273n/a self.checkParam(widget, 'image', image, conv=str)
274n/a errmsg = 'image "spam" doesn\'t exist'
275n/a with self.assertRaises(tkinter.TclError) as cm:
276n/a widget['image'] = 'spam'
277n/a if errmsg is not None:
278n/a self.assertEqual(str(cm.exception), errmsg)
279n/a with self.assertRaises(tkinter.TclError) as cm:
280n/a widget.configure({'image': 'spam'})
281n/a if errmsg is not None:
282n/a self.assertEqual(str(cm.exception), errmsg)
283n/a
284n/a def test_menu(self):
285n/a widget = self.create()
286n/a menu = tkinter.Menu(widget, name='menu')
287n/a self.checkParam(widget, 'menu', menu, eq=widget_eq)
288n/a menu.destroy()
289n/a
290n/a def test_padx(self):
291n/a widget = self.create()
292n/a self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, '12m')
293n/a self.checkParam(widget, 'padx', -2, expected=0)
294n/a
295n/a def test_pady(self):
296n/a widget = self.create()
297n/a self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, '12m')
298n/a self.checkParam(widget, 'pady', -2, expected=0)
299n/a
300n/a def test_width(self):
301n/a widget = self.create()
302n/a self.checkIntegerParam(widget, 'width', 402, -402, 0, conv=str)
303n/a
304n/a
305n/aclass OptionMenuTest(MenubuttonTest, unittest.TestCase):
306n/a
307n/a def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
308n/a return tkinter.OptionMenu(self.root, None, default, *values, **kwargs)
309n/a
310n/a
311n/a@add_standard_options(IntegerSizeTests, StandardOptionsTests)
312n/aclass EntryTest(AbstractWidgetTest, unittest.TestCase):
313n/a OPTIONS = (
314n/a 'background', 'borderwidth', 'cursor',
315n/a 'disabledbackground', 'disabledforeground',
316n/a 'exportselection', 'font', 'foreground',
317n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
318n/a 'insertbackground', 'insertborderwidth',
319n/a 'insertofftime', 'insertontime', 'insertwidth',
320n/a 'invalidcommand', 'justify', 'readonlybackground', 'relief',
321n/a 'selectbackground', 'selectborderwidth', 'selectforeground',
322n/a 'show', 'state', 'takefocus', 'textvariable',
323n/a 'validate', 'validatecommand', 'width', 'xscrollcommand',
324n/a )
325n/a
326n/a def create(self, **kwargs):
327n/a return tkinter.Entry(self.root, **kwargs)
328n/a
329n/a def test_disabledbackground(self):
330n/a widget = self.create()
331n/a self.checkColorParam(widget, 'disabledbackground')
332n/a
333n/a def test_insertborderwidth(self):
334n/a widget = self.create(insertwidth=100)
335n/a self.checkPixelsParam(widget, 'insertborderwidth',
336n/a 0, 1.3, 2.6, 6, -2, '10p')
337n/a # insertborderwidth is bounded above by a half of insertwidth.
338n/a self.checkParam(widget, 'insertborderwidth', 60, expected=100//2)
339n/a
340n/a def test_insertwidth(self):
341n/a widget = self.create()
342n/a self.checkPixelsParam(widget, 'insertwidth', 1.3, 3.6, '10p')
343n/a self.checkParam(widget, 'insertwidth', 0.1, expected=2)
344n/a self.checkParam(widget, 'insertwidth', -2, expected=2)
345n/a if pixels_round(0.9) <= 0:
346n/a self.checkParam(widget, 'insertwidth', 0.9, expected=2)
347n/a else:
348n/a self.checkParam(widget, 'insertwidth', 0.9, expected=1)
349n/a
350n/a def test_invalidcommand(self):
351n/a widget = self.create()
352n/a self.checkCommandParam(widget, 'invalidcommand')
353n/a self.checkCommandParam(widget, 'invcmd')
354n/a
355n/a def test_readonlybackground(self):
356n/a widget = self.create()
357n/a self.checkColorParam(widget, 'readonlybackground')
358n/a
359n/a def test_show(self):
360n/a widget = self.create()
361n/a self.checkParam(widget, 'show', '*')
362n/a self.checkParam(widget, 'show', '')
363n/a self.checkParam(widget, 'show', ' ')
364n/a
365n/a def test_state(self):
366n/a widget = self.create()
367n/a self.checkEnumParam(widget, 'state',
368n/a 'disabled', 'normal', 'readonly')
369n/a
370n/a def test_validate(self):
371n/a widget = self.create()
372n/a self.checkEnumParam(widget, 'validate',
373n/a 'all', 'key', 'focus', 'focusin', 'focusout', 'none')
374n/a
375n/a def test_validatecommand(self):
376n/a widget = self.create()
377n/a self.checkCommandParam(widget, 'validatecommand')
378n/a self.checkCommandParam(widget, 'vcmd')
379n/a
380n/a
381n/a@add_standard_options(StandardOptionsTests)
382n/aclass SpinboxTest(EntryTest, unittest.TestCase):
383n/a OPTIONS = (
384n/a 'activebackground', 'background', 'borderwidth',
385n/a 'buttonbackground', 'buttoncursor', 'buttondownrelief', 'buttonuprelief',
386n/a 'command', 'cursor', 'disabledbackground', 'disabledforeground',
387n/a 'exportselection', 'font', 'foreground', 'format', 'from',
388n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
389n/a 'increment',
390n/a 'insertbackground', 'insertborderwidth',
391n/a 'insertofftime', 'insertontime', 'insertwidth',
392n/a 'invalidcommand', 'justify', 'relief', 'readonlybackground',
393n/a 'repeatdelay', 'repeatinterval',
394n/a 'selectbackground', 'selectborderwidth', 'selectforeground',
395n/a 'state', 'takefocus', 'textvariable', 'to',
396n/a 'validate', 'validatecommand', 'values',
397n/a 'width', 'wrap', 'xscrollcommand',
398n/a )
399n/a
400n/a def create(self, **kwargs):
401n/a return tkinter.Spinbox(self.root, **kwargs)
402n/a
403n/a test_show = None
404n/a
405n/a def test_buttonbackground(self):
406n/a widget = self.create()
407n/a self.checkColorParam(widget, 'buttonbackground')
408n/a
409n/a def test_buttoncursor(self):
410n/a widget = self.create()
411n/a self.checkCursorParam(widget, 'buttoncursor')
412n/a
413n/a def test_buttondownrelief(self):
414n/a widget = self.create()
415n/a self.checkReliefParam(widget, 'buttondownrelief')
416n/a
417n/a def test_buttonuprelief(self):
418n/a widget = self.create()
419n/a self.checkReliefParam(widget, 'buttonuprelief')
420n/a
421n/a def test_format(self):
422n/a widget = self.create()
423n/a self.checkParam(widget, 'format', '%2f')
424n/a self.checkParam(widget, 'format', '%2.2f')
425n/a self.checkParam(widget, 'format', '%.2f')
426n/a self.checkParam(widget, 'format', '%2.f')
427n/a self.checkInvalidParam(widget, 'format', '%2e-1f')
428n/a self.checkInvalidParam(widget, 'format', '2.2')
429n/a self.checkInvalidParam(widget, 'format', '%2.-2f')
430n/a self.checkParam(widget, 'format', '%-2.02f')
431n/a self.checkParam(widget, 'format', '% 2.02f')
432n/a self.checkParam(widget, 'format', '% -2.200f')
433n/a self.checkParam(widget, 'format', '%09.200f')
434n/a self.checkInvalidParam(widget, 'format', '%d')
435n/a
436n/a def test_from(self):
437n/a widget = self.create()
438n/a self.checkParam(widget, 'to', 100.0)
439n/a self.checkFloatParam(widget, 'from', -10, 10.2, 11.7)
440n/a self.checkInvalidParam(widget, 'from', 200,
441n/a errmsg='-to value must be greater than -from value')
442n/a
443n/a def test_increment(self):
444n/a widget = self.create()
445n/a self.checkFloatParam(widget, 'increment', -1, 1, 10.2, 12.8, 0)
446n/a
447n/a def test_to(self):
448n/a widget = self.create()
449n/a self.checkParam(widget, 'from', -100.0)
450n/a self.checkFloatParam(widget, 'to', -10, 10.2, 11.7)
451n/a self.checkInvalidParam(widget, 'to', -200,
452n/a errmsg='-to value must be greater than -from value')
453n/a
454n/a def test_values(self):
455n/a # XXX
456n/a widget = self.create()
457n/a self.assertEqual(widget['values'], '')
458n/a self.checkParam(widget, 'values', 'mon tue wed thur')
459n/a self.checkParam(widget, 'values', ('mon', 'tue', 'wed', 'thur'),
460n/a expected='mon tue wed thur')
461n/a self.checkParam(widget, 'values', (42, 3.14, '', 'any string'),
462n/a expected='42 3.14 {} {any string}')
463n/a self.checkParam(widget, 'values', '')
464n/a
465n/a def test_wrap(self):
466n/a widget = self.create()
467n/a self.checkBooleanParam(widget, 'wrap')
468n/a
469n/a def test_bbox(self):
470n/a widget = self.create()
471n/a self.assertIsBoundingBox(widget.bbox(0))
472n/a self.assertRaises(tkinter.TclError, widget.bbox, 'noindex')
473n/a self.assertRaises(tkinter.TclError, widget.bbox, None)
474n/a self.assertRaises(TypeError, widget.bbox)
475n/a self.assertRaises(TypeError, widget.bbox, 0, 1)
476n/a
477n/a
478n/a@add_standard_options(StandardOptionsTests)
479n/aclass TextTest(AbstractWidgetTest, unittest.TestCase):
480n/a OPTIONS = (
481n/a 'autoseparators', 'background', 'blockcursor', 'borderwidth',
482n/a 'cursor', 'endline', 'exportselection',
483n/a 'font', 'foreground', 'height',
484n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
485n/a 'inactiveselectbackground', 'insertbackground', 'insertborderwidth',
486n/a 'insertofftime', 'insertontime', 'insertunfocussed', 'insertwidth',
487n/a 'maxundo', 'padx', 'pady', 'relief',
488n/a 'selectbackground', 'selectborderwidth', 'selectforeground',
489n/a 'setgrid', 'spacing1', 'spacing2', 'spacing3', 'startline', 'state',
490n/a 'tabs', 'tabstyle', 'takefocus', 'undo', 'width', 'wrap',
491n/a 'xscrollcommand', 'yscrollcommand',
492n/a )
493n/a if tcl_version < (8, 5):
494n/a _stringify = True
495n/a
496n/a def create(self, **kwargs):
497n/a return tkinter.Text(self.root, **kwargs)
498n/a
499n/a def test_autoseparators(self):
500n/a widget = self.create()
501n/a self.checkBooleanParam(widget, 'autoseparators')
502n/a
503n/a @requires_tcl(8, 5)
504n/a def test_blockcursor(self):
505n/a widget = self.create()
506n/a self.checkBooleanParam(widget, 'blockcursor')
507n/a
508n/a @requires_tcl(8, 5)
509n/a def test_endline(self):
510n/a widget = self.create()
511n/a text = '\n'.join('Line %d' for i in range(100))
512n/a widget.insert('end', text)
513n/a self.checkParam(widget, 'endline', 200, expected='')
514n/a self.checkParam(widget, 'endline', -10, expected='')
515n/a self.checkInvalidParam(widget, 'endline', 'spam',
516n/a errmsg='expected integer but got "spam"')
517n/a self.checkParam(widget, 'endline', 50)
518n/a self.checkParam(widget, 'startline', 15)
519n/a self.checkInvalidParam(widget, 'endline', 10,
520n/a errmsg='-startline must be less than or equal to -endline')
521n/a
522n/a def test_height(self):
523n/a widget = self.create()
524n/a self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, '3c')
525n/a self.checkParam(widget, 'height', -100, expected=1)
526n/a self.checkParam(widget, 'height', 0, expected=1)
527n/a
528n/a def test_maxundo(self):
529n/a widget = self.create()
530n/a self.checkIntegerParam(widget, 'maxundo', 0, 5, -1)
531n/a
532n/a @requires_tcl(8, 5)
533n/a def test_inactiveselectbackground(self):
534n/a widget = self.create()
535n/a self.checkColorParam(widget, 'inactiveselectbackground')
536n/a
537n/a @requires_tcl(8, 6)
538n/a def test_insertunfocussed(self):
539n/a widget = self.create()
540n/a self.checkEnumParam(widget, 'insertunfocussed',
541n/a 'hollow', 'none', 'solid')
542n/a
543n/a def test_selectborderwidth(self):
544n/a widget = self.create()
545n/a self.checkPixelsParam(widget, 'selectborderwidth',
546n/a 1.3, 2.6, -2, '10p', conv=noconv,
547n/a keep_orig=tcl_version >= (8, 5))
548n/a
549n/a def test_spacing1(self):
550n/a widget = self.create()
551n/a self.checkPixelsParam(widget, 'spacing1', 20, 21.4, 22.6, '0.5c')
552n/a self.checkParam(widget, 'spacing1', -5, expected=0)
553n/a
554n/a def test_spacing2(self):
555n/a widget = self.create()
556n/a self.checkPixelsParam(widget, 'spacing2', 5, 6.4, 7.6, '0.1c')
557n/a self.checkParam(widget, 'spacing2', -1, expected=0)
558n/a
559n/a def test_spacing3(self):
560n/a widget = self.create()
561n/a self.checkPixelsParam(widget, 'spacing3', 20, 21.4, 22.6, '0.5c')
562n/a self.checkParam(widget, 'spacing3', -10, expected=0)
563n/a
564n/a @requires_tcl(8, 5)
565n/a def test_startline(self):
566n/a widget = self.create()
567n/a text = '\n'.join('Line %d' for i in range(100))
568n/a widget.insert('end', text)
569n/a self.checkParam(widget, 'startline', 200, expected='')
570n/a self.checkParam(widget, 'startline', -10, expected='')
571n/a self.checkInvalidParam(widget, 'startline', 'spam',
572n/a errmsg='expected integer but got "spam"')
573n/a self.checkParam(widget, 'startline', 10)
574n/a self.checkParam(widget, 'endline', 50)
575n/a self.checkInvalidParam(widget, 'startline', 70,
576n/a errmsg='-startline must be less than or equal to -endline')
577n/a
578n/a def test_state(self):
579n/a widget = self.create()
580n/a if tcl_version < (8, 5):
581n/a self.checkParams(widget, 'state', 'disabled', 'normal')
582n/a else:
583n/a self.checkEnumParam(widget, 'state', 'disabled', 'normal')
584n/a
585n/a def test_tabs(self):
586n/a widget = self.create()
587n/a if get_tk_patchlevel() < (8, 5, 11):
588n/a self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'),
589n/a expected=('10.2', '20.7', '1i', '2i'))
590n/a else:
591n/a self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'))
592n/a self.checkParam(widget, 'tabs', '10.2 20.7 1i 2i',
593n/a expected=('10.2', '20.7', '1i', '2i'))
594n/a self.checkParam(widget, 'tabs', '2c left 4c 6c center',
595n/a expected=('2c', 'left', '4c', '6c', 'center'))
596n/a self.checkInvalidParam(widget, 'tabs', 'spam',
597n/a errmsg='bad screen distance "spam"',
598n/a keep_orig=tcl_version >= (8, 5))
599n/a
600n/a @requires_tcl(8, 5)
601n/a def test_tabstyle(self):
602n/a widget = self.create()
603n/a self.checkEnumParam(widget, 'tabstyle', 'tabular', 'wordprocessor')
604n/a
605n/a def test_undo(self):
606n/a widget = self.create()
607n/a self.checkBooleanParam(widget, 'undo')
608n/a
609n/a def test_width(self):
610n/a widget = self.create()
611n/a self.checkIntegerParam(widget, 'width', 402)
612n/a self.checkParam(widget, 'width', -402, expected=1)
613n/a self.checkParam(widget, 'width', 0, expected=1)
614n/a
615n/a def test_wrap(self):
616n/a widget = self.create()
617n/a if tcl_version < (8, 5):
618n/a self.checkParams(widget, 'wrap', 'char', 'none', 'word')
619n/a else:
620n/a self.checkEnumParam(widget, 'wrap', 'char', 'none', 'word')
621n/a
622n/a def test_bbox(self):
623n/a widget = self.create()
624n/a self.assertIsBoundingBox(widget.bbox('1.1'))
625n/a self.assertIsNone(widget.bbox('end'))
626n/a self.assertRaises(tkinter.TclError, widget.bbox, 'noindex')
627n/a self.assertRaises(tkinter.TclError, widget.bbox, None)
628n/a self.assertRaises(TypeError, widget.bbox)
629n/a self.assertRaises(TypeError, widget.bbox, '1.1', 'end')
630n/a
631n/a
632n/a@add_standard_options(PixelSizeTests, StandardOptionsTests)
633n/aclass CanvasTest(AbstractWidgetTest, unittest.TestCase):
634n/a OPTIONS = (
635n/a 'background', 'borderwidth',
636n/a 'closeenough', 'confine', 'cursor', 'height',
637n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
638n/a 'insertbackground', 'insertborderwidth',
639n/a 'insertofftime', 'insertontime', 'insertwidth',
640n/a 'offset', 'relief', 'scrollregion',
641n/a 'selectbackground', 'selectborderwidth', 'selectforeground',
642n/a 'state', 'takefocus',
643n/a 'xscrollcommand', 'xscrollincrement',
644n/a 'yscrollcommand', 'yscrollincrement', 'width',
645n/a )
646n/a
647n/a _conv_pixels = round
648n/a _stringify = True
649n/a
650n/a def create(self, **kwargs):
651n/a return tkinter.Canvas(self.root, **kwargs)
652n/a
653n/a def test_closeenough(self):
654n/a widget = self.create()
655n/a self.checkFloatParam(widget, 'closeenough', 24, 2.4, 3.6, -3,
656n/a conv=float)
657n/a
658n/a def test_confine(self):
659n/a widget = self.create()
660n/a self.checkBooleanParam(widget, 'confine')
661n/a
662n/a def test_offset(self):
663n/a widget = self.create()
664n/a self.assertEqual(widget['offset'], '0,0')
665n/a self.checkParams(widget, 'offset',
666n/a 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center')
667n/a self.checkParam(widget, 'offset', '10,20')
668n/a self.checkParam(widget, 'offset', '#5,6')
669n/a self.checkInvalidParam(widget, 'offset', 'spam')
670n/a
671n/a def test_scrollregion(self):
672n/a widget = self.create()
673n/a self.checkParam(widget, 'scrollregion', '0 0 200 150')
674n/a self.checkParam(widget, 'scrollregion', (0, 0, 200, 150),
675n/a expected='0 0 200 150')
676n/a self.checkParam(widget, 'scrollregion', '')
677n/a self.checkInvalidParam(widget, 'scrollregion', 'spam',
678n/a errmsg='bad scrollRegion "spam"')
679n/a self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 'spam'))
680n/a self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200))
681n/a self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 150, 0))
682n/a
683n/a def test_state(self):
684n/a widget = self.create()
685n/a self.checkEnumParam(widget, 'state', 'disabled', 'normal',
686n/a errmsg='bad state value "{}": must be normal or disabled')
687n/a
688n/a def test_xscrollincrement(self):
689n/a widget = self.create()
690n/a self.checkPixelsParam(widget, 'xscrollincrement',
691n/a 40, 0, 41.2, 43.6, -40, '0.5i')
692n/a
693n/a def test_yscrollincrement(self):
694n/a widget = self.create()
695n/a self.checkPixelsParam(widget, 'yscrollincrement',
696n/a 10, 0, 11.2, 13.6, -10, '0.1i')
697n/a
698n/a
699n/a@add_standard_options(IntegerSizeTests, StandardOptionsTests)
700n/aclass ListboxTest(AbstractWidgetTest, unittest.TestCase):
701n/a OPTIONS = (
702n/a 'activestyle', 'background', 'borderwidth', 'cursor',
703n/a 'disabledforeground', 'exportselection',
704n/a 'font', 'foreground', 'height',
705n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
706n/a 'listvariable', 'relief',
707n/a 'selectbackground', 'selectborderwidth', 'selectforeground',
708n/a 'selectmode', 'setgrid', 'state',
709n/a 'takefocus', 'width', 'xscrollcommand', 'yscrollcommand',
710n/a )
711n/a
712n/a def create(self, **kwargs):
713n/a return tkinter.Listbox(self.root, **kwargs)
714n/a
715n/a def test_activestyle(self):
716n/a widget = self.create()
717n/a self.checkEnumParam(widget, 'activestyle',
718n/a 'dotbox', 'none', 'underline')
719n/a
720n/a def test_listvariable(self):
721n/a widget = self.create()
722n/a var = tkinter.DoubleVar(self.root)
723n/a self.checkVariableParam(widget, 'listvariable', var)
724n/a
725n/a def test_selectmode(self):
726n/a widget = self.create()
727n/a self.checkParam(widget, 'selectmode', 'single')
728n/a self.checkParam(widget, 'selectmode', 'browse')
729n/a self.checkParam(widget, 'selectmode', 'multiple')
730n/a self.checkParam(widget, 'selectmode', 'extended')
731n/a
732n/a def test_state(self):
733n/a widget = self.create()
734n/a self.checkEnumParam(widget, 'state', 'disabled', 'normal')
735n/a
736n/a def test_itemconfigure(self):
737n/a widget = self.create()
738n/a with self.assertRaisesRegex(TclError, 'item number "0" out of range'):
739n/a widget.itemconfigure(0)
740n/a colors = 'red orange yellow green blue white violet'.split()
741n/a widget.insert('end', *colors)
742n/a for i, color in enumerate(colors):
743n/a widget.itemconfigure(i, background=color)
744n/a with self.assertRaises(TypeError):
745n/a widget.itemconfigure()
746n/a with self.assertRaisesRegex(TclError, 'bad listbox index "red"'):
747n/a widget.itemconfigure('red')
748n/a self.assertEqual(widget.itemconfigure(0, 'background'),
749n/a ('background', 'background', 'Background', '', 'red'))
750n/a self.assertEqual(widget.itemconfigure('end', 'background'),
751n/a ('background', 'background', 'Background', '', 'violet'))
752n/a self.assertEqual(widget.itemconfigure('@0,0', 'background'),
753n/a ('background', 'background', 'Background', '', 'red'))
754n/a
755n/a d = widget.itemconfigure(0)
756n/a self.assertIsInstance(d, dict)
757n/a for k, v in d.items():
758n/a self.assertIn(len(v), (2, 5))
759n/a if len(v) == 5:
760n/a self.assertEqual(v, widget.itemconfigure(0, k))
761n/a self.assertEqual(v[4], widget.itemcget(0, k))
762n/a
763n/a def check_itemconfigure(self, name, value):
764n/a widget = self.create()
765n/a widget.insert('end', 'a', 'b', 'c', 'd')
766n/a widget.itemconfigure(0, **{name: value})
767n/a self.assertEqual(widget.itemconfigure(0, name)[4], value)
768n/a self.assertEqual(widget.itemcget(0, name), value)
769n/a with self.assertRaisesRegex(TclError, 'unknown color name "spam"'):
770n/a widget.itemconfigure(0, **{name: 'spam'})
771n/a
772n/a def test_itemconfigure_background(self):
773n/a self.check_itemconfigure('background', '#ff0000')
774n/a
775n/a def test_itemconfigure_bg(self):
776n/a self.check_itemconfigure('bg', '#ff0000')
777n/a
778n/a def test_itemconfigure_fg(self):
779n/a self.check_itemconfigure('fg', '#110022')
780n/a
781n/a def test_itemconfigure_foreground(self):
782n/a self.check_itemconfigure('foreground', '#110022')
783n/a
784n/a def test_itemconfigure_selectbackground(self):
785n/a self.check_itemconfigure('selectbackground', '#110022')
786n/a
787n/a def test_itemconfigure_selectforeground(self):
788n/a self.check_itemconfigure('selectforeground', '#654321')
789n/a
790n/a def test_box(self):
791n/a lb = self.create()
792n/a lb.insert(0, *('el%d' % i for i in range(8)))
793n/a lb.pack()
794n/a self.assertIsBoundingBox(lb.bbox(0))
795n/a self.assertIsNone(lb.bbox(-1))
796n/a self.assertIsNone(lb.bbox(10))
797n/a self.assertRaises(TclError, lb.bbox, 'noindex')
798n/a self.assertRaises(TclError, lb.bbox, None)
799n/a self.assertRaises(TypeError, lb.bbox)
800n/a self.assertRaises(TypeError, lb.bbox, 0, 1)
801n/a
802n/a def test_curselection(self):
803n/a lb = self.create()
804n/a lb.insert(0, *('el%d' % i for i in range(8)))
805n/a lb.selection_clear(0, tkinter.END)
806n/a lb.selection_set(2, 4)
807n/a lb.selection_set(6)
808n/a self.assertEqual(lb.curselection(), (2, 3, 4, 6))
809n/a self.assertRaises(TypeError, lb.curselection, 0)
810n/a
811n/a def test_get(self):
812n/a lb = self.create()
813n/a lb.insert(0, *('el%d' % i for i in range(8)))
814n/a self.assertEqual(lb.get(0), 'el0')
815n/a self.assertEqual(lb.get(3), 'el3')
816n/a self.assertEqual(lb.get('end'), 'el7')
817n/a self.assertEqual(lb.get(8), '')
818n/a self.assertEqual(lb.get(-1), '')
819n/a self.assertEqual(lb.get(3, 5), ('el3', 'el4', 'el5'))
820n/a self.assertEqual(lb.get(5, 'end'), ('el5', 'el6', 'el7'))
821n/a self.assertEqual(lb.get(5, 0), ())
822n/a self.assertEqual(lb.get(0, 0), ('el0',))
823n/a self.assertRaises(TclError, lb.get, 'noindex')
824n/a self.assertRaises(TclError, lb.get, None)
825n/a self.assertRaises(TypeError, lb.get)
826n/a self.assertRaises(TclError, lb.get, 'end', 'noindex')
827n/a self.assertRaises(TypeError, lb.get, 1, 2, 3)
828n/a self.assertRaises(TclError, lb.get, 2.4)
829n/a
830n/a
831n/a@add_standard_options(PixelSizeTests, StandardOptionsTests)
832n/aclass ScaleTest(AbstractWidgetTest, unittest.TestCase):
833n/a OPTIONS = (
834n/a 'activebackground', 'background', 'bigincrement', 'borderwidth',
835n/a 'command', 'cursor', 'digits', 'font', 'foreground', 'from',
836n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
837n/a 'label', 'length', 'orient', 'relief',
838n/a 'repeatdelay', 'repeatinterval',
839n/a 'resolution', 'showvalue', 'sliderlength', 'sliderrelief', 'state',
840n/a 'takefocus', 'tickinterval', 'to', 'troughcolor', 'variable', 'width',
841n/a )
842n/a default_orient = 'vertical'
843n/a
844n/a def create(self, **kwargs):
845n/a return tkinter.Scale(self.root, **kwargs)
846n/a
847n/a def test_bigincrement(self):
848n/a widget = self.create()
849n/a self.checkFloatParam(widget, 'bigincrement', 12.4, 23.6, -5)
850n/a
851n/a def test_digits(self):
852n/a widget = self.create()
853n/a self.checkIntegerParam(widget, 'digits', 5, 0)
854n/a
855n/a def test_from(self):
856n/a widget = self.create()
857n/a self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=float_round)
858n/a
859n/a def test_label(self):
860n/a widget = self.create()
861n/a self.checkParam(widget, 'label', 'any string')
862n/a self.checkParam(widget, 'label', '')
863n/a
864n/a def test_length(self):
865n/a widget = self.create()
866n/a self.checkPixelsParam(widget, 'length', 130, 131.2, 135.6, '5i')
867n/a
868n/a def test_resolution(self):
869n/a widget = self.create()
870n/a self.checkFloatParam(widget, 'resolution', 4.2, 0, 6.7, -2)
871n/a
872n/a def test_showvalue(self):
873n/a widget = self.create()
874n/a self.checkBooleanParam(widget, 'showvalue')
875n/a
876n/a def test_sliderlength(self):
877n/a widget = self.create()
878n/a self.checkPixelsParam(widget, 'sliderlength',
879n/a 10, 11.2, 15.6, -3, '3m')
880n/a
881n/a def test_sliderrelief(self):
882n/a widget = self.create()
883n/a self.checkReliefParam(widget, 'sliderrelief')
884n/a
885n/a def test_tickinterval(self):
886n/a widget = self.create()
887n/a self.checkFloatParam(widget, 'tickinterval', 1, 4.3, 7.6, 0,
888n/a conv=float_round)
889n/a self.checkParam(widget, 'tickinterval', -2, expected=2,
890n/a conv=float_round)
891n/a
892n/a def test_to(self):
893n/a widget = self.create()
894n/a self.checkFloatParam(widget, 'to', 300, 14.9, 15.1, -10,
895n/a conv=float_round)
896n/a
897n/a
898n/a@add_standard_options(PixelSizeTests, StandardOptionsTests)
899n/aclass ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
900n/a OPTIONS = (
901n/a 'activebackground', 'activerelief',
902n/a 'background', 'borderwidth',
903n/a 'command', 'cursor', 'elementborderwidth',
904n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
905n/a 'jump', 'orient', 'relief',
906n/a 'repeatdelay', 'repeatinterval',
907n/a 'takefocus', 'troughcolor', 'width',
908n/a )
909n/a _conv_pixels = round
910n/a _stringify = True
911n/a default_orient = 'vertical'
912n/a
913n/a def create(self, **kwargs):
914n/a return tkinter.Scrollbar(self.root, **kwargs)
915n/a
916n/a def test_activerelief(self):
917n/a widget = self.create()
918n/a self.checkReliefParam(widget, 'activerelief')
919n/a
920n/a def test_elementborderwidth(self):
921n/a widget = self.create()
922n/a self.checkPixelsParam(widget, 'elementborderwidth', 4.3, 5.6, -2, '1m')
923n/a
924n/a def test_orient(self):
925n/a widget = self.create()
926n/a self.checkEnumParam(widget, 'orient', 'vertical', 'horizontal',
927n/a errmsg='bad orientation "{}": must be vertical or horizontal')
928n/a
929n/a def test_activate(self):
930n/a sb = self.create()
931n/a for e in ('arrow1', 'slider', 'arrow2'):
932n/a sb.activate(e)
933n/a self.assertEqual(sb.activate(), e)
934n/a sb.activate('')
935n/a self.assertIsNone(sb.activate())
936n/a self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2')
937n/a
938n/a def test_set(self):
939n/a sb = self.create()
940n/a sb.set(0.2, 0.4)
941n/a self.assertEqual(sb.get(), (0.2, 0.4))
942n/a self.assertRaises(TclError, sb.set, 'abc', 'def')
943n/a self.assertRaises(TclError, sb.set, 0.6, 'def')
944n/a self.assertRaises(TclError, sb.set, 0.6, None)
945n/a self.assertRaises(TypeError, sb.set, 0.6)
946n/a self.assertRaises(TypeError, sb.set, 0.6, 0.7, 0.8)
947n/a
948n/a
949n/a@add_standard_options(StandardOptionsTests)
950n/aclass PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
951n/a OPTIONS = (
952n/a 'background', 'borderwidth', 'cursor',
953n/a 'handlepad', 'handlesize', 'height',
954n/a 'opaqueresize', 'orient', 'relief',
955n/a 'sashcursor', 'sashpad', 'sashrelief', 'sashwidth',
956n/a 'showhandle', 'width',
957n/a )
958n/a default_orient = 'horizontal'
959n/a
960n/a def create(self, **kwargs):
961n/a return tkinter.PanedWindow(self.root, **kwargs)
962n/a
963n/a def test_handlepad(self):
964n/a widget = self.create()
965n/a self.checkPixelsParam(widget, 'handlepad', 5, 6.4, 7.6, -3, '1m')
966n/a
967n/a def test_handlesize(self):
968n/a widget = self.create()
969n/a self.checkPixelsParam(widget, 'handlesize', 8, 9.4, 10.6, -3, '2m',
970n/a conv=noconv)
971n/a
972n/a def test_height(self):
973n/a widget = self.create()
974n/a self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, -100, 0, '1i',
975n/a conv=noconv)
976n/a
977n/a def test_opaqueresize(self):
978n/a widget = self.create()
979n/a self.checkBooleanParam(widget, 'opaqueresize')
980n/a
981n/a def test_sashcursor(self):
982n/a widget = self.create()
983n/a self.checkCursorParam(widget, 'sashcursor')
984n/a
985n/a def test_sashpad(self):
986n/a widget = self.create()
987n/a self.checkPixelsParam(widget, 'sashpad', 8, 1.3, 2.6, -2, '2m')
988n/a
989n/a def test_sashrelief(self):
990n/a widget = self.create()
991n/a self.checkReliefParam(widget, 'sashrelief')
992n/a
993n/a def test_sashwidth(self):
994n/a widget = self.create()
995n/a self.checkPixelsParam(widget, 'sashwidth', 10, 11.1, 15.6, -3, '1m',
996n/a conv=noconv)
997n/a
998n/a def test_showhandle(self):
999n/a widget = self.create()
1000n/a self.checkBooleanParam(widget, 'showhandle')
1001n/a
1002n/a def test_width(self):
1003n/a widget = self.create()
1004n/a self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i',
1005n/a conv=noconv)
1006n/a
1007n/a def create2(self):
1008n/a p = self.create()
1009n/a b = tkinter.Button(p)
1010n/a c = tkinter.Button(p)
1011n/a p.add(b)
1012n/a p.add(c)
1013n/a return p, b, c
1014n/a
1015n/a def test_paneconfigure(self):
1016n/a p, b, c = self.create2()
1017n/a self.assertRaises(TypeError, p.paneconfigure)
1018n/a d = p.paneconfigure(b)
1019n/a self.assertIsInstance(d, dict)
1020n/a for k, v in d.items():
1021n/a self.assertEqual(len(v), 5)
1022n/a self.assertEqual(v, p.paneconfigure(b, k))
1023n/a self.assertEqual(v[4], p.panecget(b, k))
1024n/a
1025n/a def check_paneconfigure(self, p, b, name, value, expected, stringify=False):
1026n/a conv = lambda x: x
1027n/a if not self.wantobjects or stringify:
1028n/a expected = str(expected)
1029n/a if self.wantobjects and stringify:
1030n/a conv = str
1031n/a p.paneconfigure(b, **{name: value})
1032n/a self.assertEqual(conv(p.paneconfigure(b, name)[4]), expected)
1033n/a self.assertEqual(conv(p.panecget(b, name)), expected)
1034n/a
1035n/a def check_paneconfigure_bad(self, p, b, name, msg):
1036n/a with self.assertRaisesRegex(TclError, msg):
1037n/a p.paneconfigure(b, **{name: 'badValue'})
1038n/a
1039n/a def test_paneconfigure_after(self):
1040n/a p, b, c = self.create2()
1041n/a self.check_paneconfigure(p, b, 'after', c, str(c))
1042n/a self.check_paneconfigure_bad(p, b, 'after',
1043n/a 'bad window path name "badValue"')
1044n/a
1045n/a def test_paneconfigure_before(self):
1046n/a p, b, c = self.create2()
1047n/a self.check_paneconfigure(p, b, 'before', c, str(c))
1048n/a self.check_paneconfigure_bad(p, b, 'before',
1049n/a 'bad window path name "badValue"')
1050n/a
1051n/a def test_paneconfigure_height(self):
1052n/a p, b, c = self.create2()
1053n/a self.check_paneconfigure(p, b, 'height', 10, 10,
1054n/a stringify=get_tk_patchlevel() < (8, 5, 11))
1055n/a self.check_paneconfigure_bad(p, b, 'height',
1056n/a 'bad screen distance "badValue"')
1057n/a
1058n/a @requires_tcl(8, 5)
1059n/a def test_paneconfigure_hide(self):
1060n/a p, b, c = self.create2()
1061n/a self.check_paneconfigure(p, b, 'hide', False, 0)
1062n/a self.check_paneconfigure_bad(p, b, 'hide',
1063n/a 'expected boolean value but got "badValue"')
1064n/a
1065n/a def test_paneconfigure_minsize(self):
1066n/a p, b, c = self.create2()
1067n/a self.check_paneconfigure(p, b, 'minsize', 10, 10)
1068n/a self.check_paneconfigure_bad(p, b, 'minsize',
1069n/a 'bad screen distance "badValue"')
1070n/a
1071n/a def test_paneconfigure_padx(self):
1072n/a p, b, c = self.create2()
1073n/a self.check_paneconfigure(p, b, 'padx', 1.3, 1)
1074n/a self.check_paneconfigure_bad(p, b, 'padx',
1075n/a 'bad screen distance "badValue"')
1076n/a
1077n/a def test_paneconfigure_pady(self):
1078n/a p, b, c = self.create2()
1079n/a self.check_paneconfigure(p, b, 'pady', 1.3, 1)
1080n/a self.check_paneconfigure_bad(p, b, 'pady',
1081n/a 'bad screen distance "badValue"')
1082n/a
1083n/a def test_paneconfigure_sticky(self):
1084n/a p, b, c = self.create2()
1085n/a self.check_paneconfigure(p, b, 'sticky', 'nsew', 'nesw')
1086n/a self.check_paneconfigure_bad(p, b, 'sticky',
1087n/a 'bad stickyness value "badValue": must '
1088n/a 'be a string containing zero or more of '
1089n/a 'n, e, s, and w')
1090n/a
1091n/a @requires_tcl(8, 5)
1092n/a def test_paneconfigure_stretch(self):
1093n/a p, b, c = self.create2()
1094n/a self.check_paneconfigure(p, b, 'stretch', 'alw', 'always')
1095n/a self.check_paneconfigure_bad(p, b, 'stretch',
1096n/a 'bad stretch "badValue": must be '
1097n/a 'always, first, last, middle, or never')
1098n/a
1099n/a def test_paneconfigure_width(self):
1100n/a p, b, c = self.create2()
1101n/a self.check_paneconfigure(p, b, 'width', 10, 10,
1102n/a stringify=get_tk_patchlevel() < (8, 5, 11))
1103n/a self.check_paneconfigure_bad(p, b, 'width',
1104n/a 'bad screen distance "badValue"')
1105n/a
1106n/a
1107n/a@add_standard_options(StandardOptionsTests)
1108n/aclass MenuTest(AbstractWidgetTest, unittest.TestCase):
1109n/a OPTIONS = (
1110n/a 'activebackground', 'activeborderwidth', 'activeforeground',
1111n/a 'background', 'borderwidth', 'cursor',
1112n/a 'disabledforeground', 'font', 'foreground',
1113n/a 'postcommand', 'relief', 'selectcolor', 'takefocus',
1114n/a 'tearoff', 'tearoffcommand', 'title', 'type',
1115n/a )
1116n/a _conv_pixels = noconv
1117n/a
1118n/a def create(self, **kwargs):
1119n/a return tkinter.Menu(self.root, **kwargs)
1120n/a
1121n/a def test_postcommand(self):
1122n/a widget = self.create()
1123n/a self.checkCommandParam(widget, 'postcommand')
1124n/a
1125n/a def test_tearoff(self):
1126n/a widget = self.create()
1127n/a self.checkBooleanParam(widget, 'tearoff')
1128n/a
1129n/a def test_tearoffcommand(self):
1130n/a widget = self.create()
1131n/a self.checkCommandParam(widget, 'tearoffcommand')
1132n/a
1133n/a def test_title(self):
1134n/a widget = self.create()
1135n/a self.checkParam(widget, 'title', 'any string')
1136n/a
1137n/a def test_type(self):
1138n/a widget = self.create()
1139n/a self.checkEnumParam(widget, 'type',
1140n/a 'normal', 'tearoff', 'menubar')
1141n/a
1142n/a def test_entryconfigure(self):
1143n/a m1 = self.create()
1144n/a m1.add_command(label='test')
1145n/a self.assertRaises(TypeError, m1.entryconfigure)
1146n/a with self.assertRaisesRegex(TclError, 'bad menu entry index "foo"'):
1147n/a m1.entryconfigure('foo')
1148n/a d = m1.entryconfigure(1)
1149n/a self.assertIsInstance(d, dict)
1150n/a for k, v in d.items():
1151n/a self.assertIsInstance(k, str)
1152n/a self.assertIsInstance(v, tuple)
1153n/a self.assertEqual(len(v), 5)
1154n/a self.assertEqual(v[0], k)
1155n/a self.assertEqual(m1.entrycget(1, k), v[4])
1156n/a m1.destroy()
1157n/a
1158n/a def test_entryconfigure_label(self):
1159n/a m1 = self.create()
1160n/a m1.add_command(label='test')
1161n/a self.assertEqual(m1.entrycget(1, 'label'), 'test')
1162n/a m1.entryconfigure(1, label='changed')
1163n/a self.assertEqual(m1.entrycget(1, 'label'), 'changed')
1164n/a
1165n/a def test_entryconfigure_variable(self):
1166n/a m1 = self.create()
1167n/a v1 = tkinter.BooleanVar(self.root)
1168n/a v2 = tkinter.BooleanVar(self.root)
1169n/a m1.add_checkbutton(variable=v1, onvalue=True, offvalue=False,
1170n/a label='Nonsense')
1171n/a self.assertEqual(str(m1.entrycget(1, 'variable')), str(v1))
1172n/a m1.entryconfigure(1, variable=v2)
1173n/a self.assertEqual(str(m1.entrycget(1, 'variable')), str(v2))
1174n/a
1175n/a
1176n/a@add_standard_options(PixelSizeTests, StandardOptionsTests)
1177n/aclass MessageTest(AbstractWidgetTest, unittest.TestCase):
1178n/a OPTIONS = (
1179n/a 'anchor', 'aspect', 'background', 'borderwidth',
1180n/a 'cursor', 'font', 'foreground',
1181n/a 'highlightbackground', 'highlightcolor', 'highlightthickness',
1182n/a 'justify', 'padx', 'pady', 'relief',
1183n/a 'takefocus', 'text', 'textvariable', 'width',
1184n/a )
1185n/a _conv_pad_pixels = noconv
1186n/a
1187n/a def create(self, **kwargs):
1188n/a return tkinter.Message(self.root, **kwargs)
1189n/a
1190n/a def test_aspect(self):
1191n/a widget = self.create()
1192n/a self.checkIntegerParam(widget, 'aspect', 250, 0, -300)
1193n/a
1194n/a
1195n/atests_gui = (
1196n/a ButtonTest, CanvasTest, CheckbuttonTest, EntryTest,
1197n/a FrameTest, LabelFrameTest,LabelTest, ListboxTest,
1198n/a MenubuttonTest, MenuTest, MessageTest, OptionMenuTest,
1199n/a PanedWindowTest, RadiobuttonTest, ScaleTest, ScrollbarTest,
1200n/a SpinboxTest, TextTest, ToplevelTest,
1201n/a)
1202n/a
1203n/aif __name__ == '__main__':
1204n/a unittest.main()