@@ -26,13 +26,11 @@ def float_round(x):
2626 return float (round (x ))
2727
2828class AbstractToplevelTest (AbstractWidgetTest , PixelSizeTests ):
29- if tk_version < (9 , 0 ):
30- _no_round = {'padx' , 'pady' }
31- else :
32- _no_round = {'borderwidth' , 'height' , 'highlightthickness' , 'padx' ,
33- 'pady' , 'width' }
34- if tk_version < (9 , 0 ):
29+ _no_round = {'padx' , 'pady' }
30+ if tk_version < (8 , 7 ):
3531 _clipped = {'highlightthickness' }
32+ elif tk_version < (9 , 0 ):
33+ _clipped = {'borderwidth' , 'highlightthickness' , 'padx' , 'pady' }
3634 else :
3735 _clipped = {'borderwidth' , 'height' , 'highlightthickness' , 'padx' ,
3836 'pady' , 'width' }
@@ -122,11 +120,6 @@ class FrameTest(AbstractToplevelTest, unittest.TestCase):
122120 'highlightbackground' , 'highlightcolor' , 'highlightthickness' ,
123121 'padx' , 'pady' , 'relief' , 'takefocus' , 'tile' , 'visual' , 'width' ,
124122 )
125- if tk_version < (9 , 0 ):
126- _no_round = {'padx' , 'pady' }
127- else :
128- _no_round = {'borderwidth' , 'height' , 'highlightthickness' , 'padx' ,
129- 'pady' , 'width' }
130123
131124 def create (self , ** kwargs ):
132125 return tkinter .Frame (self .root , ** kwargs )
@@ -142,11 +135,6 @@ class LabelFrameTest(AbstractToplevelTest, unittest.TestCase):
142135 'labelanchor' , 'labelwidget' , 'padx' , 'pady' , 'relief' ,
143136 'takefocus' , 'text' , 'visual' , 'width' ,
144137 )
145- if tk_version < (9 , 0 ):
146- _no_round = {'padx' , 'pady' }
147- else :
148- _no_round = {'borderwidth' , 'height' , 'highlightthickness' , 'padx' ,
149- 'pady' , 'width' }
150138
151139 def create (self , ** kwargs ):
152140 return tkinter .LabelFrame (self .root , ** kwargs )
@@ -167,11 +155,13 @@ def test_configure_labelwidget(self):
167155# Label, Button, Checkbutton, Radiobutton, MenuButton
168156class AbstractLabelTest (AbstractWidgetTest , IntegerSizeTests ):
169157 _rounds_pixels = False
170- if tk_version < (9 , 0 ):
158+ if tk_version < (8 , 7 ):
171159 _clipped = {}
160+ elif tk_version < (9 , 0 ):
161+ _clipped = {'borderwidth' , 'height' , 'highlightthickness' , 'padx' , 'pady' , 'width' }
172162 else :
173- _clipped = {'borderwidth' , 'insertborderwidth ' , 'highlightthickness' ,
174- 'padx' , 'pady' }
163+ _clipped = {'borderwidth' , 'height ' , 'highlightthickness' ,
164+ 'insertborderwidth' , ' padx' , 'pady' , 'width ' }
175165
176166@add_configure_tests (StandardOptionsTests )
177167class LabelTest (AbstractLabelTest , unittest .TestCase ):
@@ -201,6 +191,11 @@ class ButtonTest(AbstractLabelTest, unittest.TestCase):
201191 'repeatdelay' , 'repeatinterval' ,
202192 'state' , 'takefocus' , 'text' , 'textvariable' ,
203193 'underline' , 'width' , 'wraplength' )
194+ if tk_version < (8 , 7 ):
195+ _clipped = {}
196+ else :
197+ _clipped = {'borderwidth' , 'height' , 'highlightthickness' ,
198+ 'padx' , 'pady' , 'width' }
204199
205200 def create (self , ** kwargs ):
206201 return tkinter .Button (self .root , ** kwargs )
@@ -301,10 +296,12 @@ class MenubuttonTest(AbstractLabelTest, unittest.TestCase):
301296 'underline' , 'width' , 'wraplength' ,
302297 )
303298 _rounds_pixels = (tk_version < (9 , 0 ))
304- if tk_version < (9 , 0 ):
299+ if tk_version < (8 , 7 ):
305300 _clipped = {'highlightthickness' , 'padx' , 'pady' }
301+ elif tk_version < (9 , 0 ):
302+ _clipped = {'borderwidth' , 'highlightthickness' , 'padx' , 'pady' }
306303 else :
307- _clipped = { 'insertborderwidth ' , 'highlightthickness' , 'padx' , 'pady' }
304+ _clipped = { 'borderwidth ' , 'highlightthickness' , 'insertborderwidth ' , 'padx' , 'pady' }
308305
309306 def create (self , ** kwargs ):
310307 return tkinter .Menubutton (self .root , ** kwargs )
@@ -316,16 +313,14 @@ def test_configure_direction(self):
316313
317314 def test_configure_height (self ):
318315 widget = self .create ()
319- if tk_version < (9 , 0 ):
320- self .checkIntegerParam (widget , 'height' , 100 , - 100 , 0 , conv = str )
321- else :
322- self .checkIntegerParam (widget , 'height' , 0 , - 100 , 0 )
316+ conv = str if tk_version < (8 , 7 ) else False
317+ self .checkIntegerParam (widget , 'height' , 100 , - 100 , 0 , conv = conv )
323318
324319 def test_configure_image (self ):
325320 widget = self .create ()
326321 image = tkinter .PhotoImage (master = self .root , name = 'image1' )
327322 self .checkParam (widget , 'image' , image , conv = str )
328- if tk_version < (9 , 0 ):
323+ if tk_version < (8 , 7 ):
329324 errmsg = 'image "spam" doesn\' t exist'
330325 else :
331326 errmsg = 'image "spam" does not exist'
@@ -346,10 +341,8 @@ def test_configure_menu(self):
346341
347342 def test_configure_width (self ):
348343 widget = self .create ()
349- if tk_version < (9 , 0 ):
350- self .checkIntegerParam (widget , 'width' , 402 , - 402 , 0 , conv = str )
351- else :
352- self .checkIntegerParam (widget , 'width' , 402 , 0 , 0 )
344+ conv = str if tk_version < (8 , 7 ) else False
345+ self .checkIntegerParam (widget , 'width' , 402 , - 402 , 0 , conv = conv )
353346
354347
355348class OptionMenuTest (MenubuttonTest , unittest .TestCase ):
@@ -368,12 +361,11 @@ def test_specify_name(self):
368361
369362@add_configure_tests (IntegerSizeTests , StandardOptionsTests )
370363class EntryTest (AbstractWidgetTest , unittest .TestCase ):
371- _rounds_pixels = (tk_version < (9 , 0 ))
372- if tk_version < (9 , 0 ):
364+ if tk_version < (8 , 7 ):
373365 _clipped = {'highlightthickness' }
374366 else :
375- _clipped = {'highlightthickness ' , 'borderwidth ' , 'insertborderwidth' ,
376- 'selectborderwidth' }
367+ _clipped = {'borderwidth ' , 'highlightthickness ' , 'insertborderwidth' ,
368+ 'insertwidth' , ' selectborderwidth' }
377369
378370 OPTIONS = (
379371 'background' , 'borderwidth' , 'cursor' ,
@@ -398,28 +390,21 @@ def test_configure_disabledbackground(self):
398390
399391 def test_configure_insertborderwidth (self ):
400392 widget = self .create (insertwidth = 100 )
401- if tk_version < (9 , 0 ):
402- self .checkPixelsParam (widget , 'insertborderwidth' ,
403- 0 , 1.3 , 2.6 , 6 , '10p' )
404- else :
405- self .checkPixelsParam (widget , 'insertborderwidth' ,
406- 0 , 1.3 , 3 , 6 , '10p' )
407- self .checkParam (widget , 'insertborderwidth' , - 2 )
393+ self .checkPixelsParam (widget , 'insertborderwidth' ,
394+ 0 , 1.3 , 2.6 , 6 , - 2 , '10p' )
408395 # insertborderwidth is bounded above by a half of insertwidth.
409- expected = 100 // 2 if tk_version < (9 , 0 ) else 60
396+ expected = 100 // 2 if tk_version < (8 , 7 ) else 60
410397 self .checkParam (widget , 'insertborderwidth' , 60 , expected = expected )
411398
412399 def test_configure_insertwidth (self ):
413400 widget = self .create ()
414- self .checkPixelsParam (widget , 'insertwidth' , 1.3 , 3.6 , '10p' )
415- if tk_version < (9 , 0 ):
401+ self .checkPixelsParam (widget , 'insertwidth' , 1.3 , 3.6 , 0.9 , '10p' )
402+ if tk_version < (8 , 7 ):
403+ self .checkParam (widget , 'insertwidth' , 0 , expected = 2 )
416404 self .checkParam (widget , 'insertwidth' , 0.1 , expected = 2 )
417405 self .checkParam (widget , 'insertwidth' , - 2 , expected = 2 )
418- self .checkParam (widget , 'insertwidth' , 0.9 , expected = 1 )
419406 else :
420- self .checkParam (widget , 'insertwidth' , 0.1 )
421- self .checkParam (widget , 'insertwidth' , - 2 , expected = 0 )
422- self .checkParam (widget , 'insertwidth' , 0.9 )
407+ self .checkPixelsParam (widget , 'insertwidth' , 0 , 0.1 , - 2 )
423408
424409 def test_configure_invalidcommand (self ):
425410 widget = self .create ()
@@ -562,7 +547,7 @@ def test_configure_values(self):
562547 # XXX
563548 widget = self .create ()
564549 self .assertEqual (widget ['values' ], '' )
565- if tk_version < (9 , 0 ):
550+ if tk_version < (8 , 7 ):
566551 expected = 'mon tue wed thur'
567552 else :
568553 expected = ('mon' , 'tue' , 'wed' , 'thur' )
@@ -571,7 +556,7 @@ def test_configure_values(self):
571556 self .checkParam (widget , 'values' , ('mon' , 'tue' , 'wed' , 'thur' ),
572557 expected = expected )
573558
574- if tk_version < (9 , 0 ):
559+ if tk_version < (8 , 7 ):
575560 expected = '42 3.14 {} {any string}'
576561 else :
577562 expected = (42 , 3.14 , '' , 'any string' )
@@ -640,9 +625,13 @@ class TextTest(AbstractWidgetTest, unittest.TestCase):
640625 'tabs' , 'tabstyle' , 'takefocus' , 'undo' , 'width' , 'wrap' ,
641626 'xscrollcommand' , 'yscrollcommand' ,
642627 )
643- _rounds_pixels = (tk_version < (9 , 0 ))
644628 _no_round = {'selectborderwidth' }
645- _clipped = {'highlightthickness' }
629+ if tk_version < (9 , 0 ):
630+ _clipped = {'highlightthickness' , 'spacing1' , 'spacing2' , 'spacing3' }
631+ else :
632+ _clipped = {'borderwidth' , 'highlightthickness' , 'insertborderwidth' ,
633+ 'insertwidth' , 'padx' , 'pady' , 'selectborderwidth' ,
634+ 'spacing1' , 'spacing2' , 'spacing3' }
646635
647636 def create (self , ** kwargs ):
648637 return tkinter .Text (self .root , ** kwargs )
@@ -672,8 +661,11 @@ def test_configure_height(self):
672661 widget = self .create ()
673662 self .checkPixelsParam (widget , 'height' , 100 , 101.2 , 102.6 , '3c' )
674663 expected = 1 if tk_version < (9 , 0 ) else 0
675- self .checkParam (widget , 'height' , - 100 , expected = expected )
676664 self .checkParam (widget , 'height' , 0 , expected = expected )
665+ if tk_version < (9 , 1 ):
666+ self .checkParam (widget , 'height' , - 100 , expected = expected )
667+ else :
668+ self .checkInvalidParam (widget , 'height' , - 100 )
677669
678670 def test_configure_maxundo (self ):
679671 widget = self .create ()
@@ -691,24 +683,20 @@ def test_configure_insertunfocussed(self):
691683
692684 def test_configure_selectborderwidth (self ):
693685 widget = self .create ()
694- value = - 2 if tk_version < (9 , 0 ) else 0
695686 self .checkPixelsParam (widget , 'selectborderwidth' ,
696- 1.3 , 2.6 , value , '10p' , conv = False )
687+ 1.3 , 2.6 , - 2 , '10p' , conv = False )
697688
698689 def test_configure_spacing1 (self ):
699690 widget = self .create ()
700- self .checkPixelsParam (widget , 'spacing1' , 20 , 21.4 , 22.6 , '0.5c' )
701- self .checkParam (widget , 'spacing1' , - 5 , expected = 0 )
691+ self .checkPixelsParam (widget , 'spacing1' , 20 , 21.4 , 22.6 , - 5 , '0.5c' )
702692
703693 def test_configure_spacing2 (self ):
704694 widget = self .create ()
705- self .checkPixelsParam (widget , 'spacing2' , 5 , 6.4 , 7.6 , '0.1c' )
706- self .checkParam (widget , 'spacing2' , - 1 , expected = 0 )
695+ self .checkPixelsParam (widget , 'spacing2' , 5 , 6.4 , 7.6 , - 1 , '0.1c' )
707696
708697 def test_configure_spacing3 (self ):
709698 widget = self .create ()
710- self .checkPixelsParam (widget , 'spacing3' , 20 , 21.4 , 22.6 , '0.5c' )
711- self .checkParam (widget , 'spacing3' , - 10 , expected = 0 )
699+ self .checkPixelsParam (widget , 'spacing3' , 20 , 21.4 , 22.6 , - 10 , '0.5c' )
712700
713701 def test_configure_startline (self ):
714702 widget = self .create ()
@@ -781,15 +769,16 @@ class CanvasTest(AbstractWidgetTest, unittest.TestCase):
781769 'xscrollcommand' , 'xscrollincrement' ,
782770 'yscrollcommand' , 'yscrollincrement' , 'width' ,
783771 )
784- _rounds_pixels = True
785- if tk_version < (9 , 0 ):
786- _noround = {}
772+ if tk_version < (8 , 7 ):
787773 _clipped = {'highlightthickness' }
774+ elif tk_version < (9 , 0 ):
775+ _clipped = {'borderwidth' , 'highlightthickness' , 'insertborderwidth' ,
776+ 'insertwidth' , 'selectborderwidth' , 'xscrollincrement' ,
777+ 'yscrollincrement' }
788778 else :
789- _no_round = {'borderwidth' , 'height' , 'highlightthickness' , 'width' ,
790- 'xscrollincrement' , 'yscrollincrement' }
791- _clipped = {'borderwidth' , 'height' , 'highlightthickness' , 'width' ,
792- 'xscrollincrement' , 'yscrollincrement' }
779+ _clipped = {'borderwidth' , 'height' , 'highlightthickness' ,
780+ 'insertborderwidth' , 'insertwidth' , 'selectborderwidth' ,
781+ 'width' , 'xscrollincrement' , 'yscrollincrement' }
793782 _stringify = True
794783
795784 def create (self , ** kwargs ):
@@ -938,7 +927,6 @@ def test_create_line(self):
938927
939928 def test_create_polygon (self ):
940929 c = self .create ()
941- tk87 = tk_version >= (8 , 7 )
942930 # In Tk < 8.7 polygons are filled, but has no outline by default.
943931 # This affects its size, so always explicitly specify outline.
944932 i1 = c .create_polygon (20 , 30 , 40 , 50 , 60 , 10 , outline = 'red' )
@@ -1043,11 +1031,10 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
10431031 'selectmode' , 'setgrid' , 'state' ,
10441032 'takefocus' , 'width' , 'xscrollcommand' , 'yscrollcommand' ,
10451033 )
1046- _rounds_pixels = (tk_version < (9 , 0 ))
1047- if tk_version < (9 , 0 ):
1034+ if tk_version < (8 , 7 ):
10481035 _clipped = {'highlightthickness' }
10491036 else :
1050- _clipped = { 'borderwidth' , 'highlightthickness' , 'selectborderwidth' }
1037+ _clipped = {'borderwidth' , 'highlightthickness' , 'selectborderwidth' }
10511038
10521039 def create (self , ** kwargs ):
10531040 return tkinter .Listbox (self .root , ** kwargs )
@@ -1185,7 +1172,6 @@ class ScaleTest(AbstractWidgetTest, unittest.TestCase):
11851172 'resolution' , 'showvalue' , 'sliderlength' , 'sliderrelief' , 'state' ,
11861173 'takefocus' , 'tickinterval' , 'to' , 'troughcolor' , 'variable' , 'width' ,
11871174 )
1188- _rounds_pixels = (tk_version < (9 , 0 ))
11891175 _clipped = {'highlightthickness' }
11901176 default_orient = 'vertical'
11911177
@@ -1255,12 +1241,10 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase):
12551241 'repeatdelay' , 'repeatinterval' ,
12561242 'takefocus' , 'troughcolor' , 'width' ,
12571243 )
1258- _rounds_pixels = True
1259- if tk_version >= (9 , 0 ):
1260- _no_round = {'borderwidth' , 'elementborderwidth' , 'highlightthickness' ,
1261- 'width' }
1262- if tk_version < (9 , 0 ):
1244+ if tk_version < (8 , 7 ):
12631245 _clipped = {'highlightthickness' }
1246+ elif tk_version < (9 , 0 ):
1247+ _clipped = {'borderwidth' , 'highlightthickness' }
12641248 else :
12651249 _clipped = {'borderwidth' , 'highlightthickness' , 'width' }
12661250 _stringify = True
@@ -1272,8 +1256,7 @@ def create(self, **kwargs):
12721256 def test_configure_elementborderwidth (self ):
12731257 widget = self .create ()
12741258 self .checkPixelsParam (widget , 'elementborderwidth' , 4.3 , 5.6 , '1m' )
1275- expected = self ._default_pixels if tk_version >= (8 , 7 ) else - 2
1276- self .checkParam (widget , 'elementborderwidth' , - 2 , expected = expected )
1259+ self .checkNegPixelParam (widget , 'elementborderwidth' , - 2 )
12771260
12781261 def test_configure_orient (self ):
12791262 widget = self .create ()
@@ -1311,14 +1294,8 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
13111294 'sashcursor' , 'sashpad' , 'sashrelief' , 'sashwidth' ,
13121295 'showhandle' , 'width' ,
13131296 )
1314- _rounds_pixels = True
1315- if tk_version < (9 , 0 ):
1316- _no_round = {'handlesize' , 'height' , 'proxyborderwidth' , 'sashwidth' ,
1317- 'selectborderwidth' , 'width' }
1318- else :
1319- _no_round = {'borderwidth' , 'handlepad' , 'handlesize' , 'height' ,
1320- 'proxyborderwidth' , 'sashpad' , 'sashwidth' ,
1321- 'selectborderwidth' , 'width' }
1297+ _no_round = {'handlesize' , 'height' , 'proxyborderwidth' , 'sashwidth' ,
1298+ 'selectborderwidth' , 'width' }
13221299 _clipped = {}
13231300 default_orient = 'horizontal'
13241301
@@ -1568,12 +1545,11 @@ class MessageTest(AbstractWidgetTest, unittest.TestCase):
15681545 'justify' , 'padx' , 'pady' , 'relief' ,
15691546 'takefocus' , 'text' , 'textvariable' , 'width' ,
15701547 )
1571- _rounds_pixels = (tk_version < (9 , 0 ))
15721548 _no_round = {'padx' , 'pady' }
1573- if tk_version < (9 , 0 ):
1549+ if tk_version < (8 , 7 ):
15741550 _clipped = {'highlightthickness' }
15751551 else :
1576- _clipped = {'borderwidth' , 'highlightthickness' , 'padx' , 'pady ' }
1552+ _clipped = {'borderwidth' , 'highlightthickness' , 'width ' }
15771553
15781554 def create (self , ** kwargs ):
15791555 return tkinter .Message (self .root , ** kwargs )
@@ -1585,20 +1561,16 @@ def test_configure_aspect(self):
15851561 def test_configure_padx (self ):
15861562 widget = self .create ()
15871563 self .checkPixelsParam (widget , 'padx' , 3 , 4.4 , 5.6 , '12m' )
1588- expected = - 2 if tk_version < (9 , 0 ) else self ._default_pixels
1589- self .checkParam (widget , 'padx' , - 2 , expected = expected )
1564+ self .checkNegPixelParam (widget , 'padx' , - 2 )
15901565
15911566 def test_configure_pady (self ):
15921567 widget = self .create ()
15931568 self .checkPixelsParam (widget , 'pady' , 3 , 4.4 , 5.6 , '12m' )
1594- expected = - 2 if tk_version < (9 , 0 ) else self ._default_pixels
1595- self .checkParam (widget , 'pady' , - 2 , expected = expected )
1569+ self .checkNegPixelParam (widget , 'pady' , - 2 )
15961570
15971571 def test_configure_width (self ):
15981572 widget = self .create ()
1599- self .checkPixelsParam (widget , 'width' , 402 , 403.4 , 404.6 , 0 , '5i' )
1600- expected = 0 if tk_version >= (8 , 7 ) else - 402
1601- self .checkParam (widget , 'width' , - 402 , expected = expected )
1573+ self .checkPixelsParam (widget , 'width' , 402 , 403.4 , 404.6 , 0 , - 402 , '5i' )
16021574
16031575
16041576class DefaultRootTest (AbstractDefaultRootTest , unittest .TestCase ):
0 commit comments