10
10
requires ('gui' )
11
11
12
12
13
+ EXPECTED_FLOAT_ERRMSG = 'expected floating-point number but got "{}"'
14
+ EXPECTED_FLOAT_OR_EMPTY_ERRMSG = 'expected floating-point number (or "" )?but got "{}"'
15
+ EXPECTED_SCREEN_DISTANCE_ERRMSG = '(bad|expected) screen distance (but got )?"{}"'
16
+ EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG = '(bad|expected) screen distance (or "" but got )?"{}"'
17
+
13
18
class PackTest (AbstractWidgetTest , unittest .TestCase ):
14
19
15
20
test_keys = None
@@ -317,7 +322,8 @@ def test_place_configure_x(self):
317
322
self .assertEqual (f2 .place_info ()['x' ], '-10' )
318
323
self .root .update ()
319
324
self .assertEqual (f2 .winfo_x (), 190 )
320
- with self .assertRaisesRegex (TclError , 'bad screen distance "spam"' ):
325
+ with self .assertRaisesRegex (TclError ,
326
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('spam' )):
321
327
f2 .place_configure (in_ = f , x = 'spam' )
322
328
323
329
def test_place_configure_y (self ):
@@ -334,7 +340,8 @@ def test_place_configure_y(self):
334
340
self .assertEqual (f2 .place_info ()['y' ], '-10' )
335
341
self .root .update ()
336
342
self .assertEqual (f2 .winfo_y (), 110 )
337
- with self .assertRaisesRegex (TclError , 'bad screen distance "spam"' ):
343
+ with self .assertRaisesRegex (TclError ,
344
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('spam' )):
338
345
f2 .place_configure (in_ = f , y = 'spam' )
339
346
340
347
def test_place_configure_relx (self ):
@@ -351,8 +358,7 @@ def test_place_configure_relx(self):
351
358
self .assertEqual (f2 .place_info ()['relx' ], '1' )
352
359
self .root .update ()
353
360
self .assertEqual (f2 .winfo_x (), 200 )
354
- with self .assertRaisesRegex (TclError , 'expected floating-point number '
355
- 'but got "spam"' ):
361
+ with self .assertRaisesRegex (TclError , EXPECTED_FLOAT_ERRMSG .format ('spam' )):
356
362
f2 .place_configure (in_ = f , relx = 'spam' )
357
363
358
364
def test_place_configure_rely (self ):
@@ -369,8 +375,7 @@ def test_place_configure_rely(self):
369
375
self .assertEqual (f2 .place_info ()['rely' ], '1' )
370
376
self .root .update ()
371
377
self .assertEqual (f2 .winfo_y (), 120 )
372
- with self .assertRaisesRegex (TclError , 'expected floating-point number '
373
- 'but got "spam"' ):
378
+ with self .assertRaisesRegex (TclError , EXPECTED_FLOAT_ERRMSG .format ('spam' )):
374
379
f2 .place_configure (in_ = f , rely = 'spam' )
375
380
376
381
def test_place_configure_anchor (self ):
@@ -391,7 +396,8 @@ def test_place_configure_width(self):
391
396
f2 .place_configure (width = '' )
392
397
self .root .update ()
393
398
self .assertEqual (f2 .winfo_width (), 30 )
394
- with self .assertRaisesRegex (TclError , 'bad screen distance "abcd"' ):
399
+ with self .assertRaisesRegex (TclError ,
400
+ EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG .format ('abcd' )):
395
401
f2 .place_configure (width = 'abcd' )
396
402
397
403
def test_place_configure_height (self ):
@@ -402,7 +408,8 @@ def test_place_configure_height(self):
402
408
f2 .place_configure (height = '' )
403
409
self .root .update ()
404
410
self .assertEqual (f2 .winfo_height (), 60 )
405
- with self .assertRaisesRegex (TclError , 'bad screen distance "abcd"' ):
411
+ with self .assertRaisesRegex (TclError ,
412
+ EXPECTED_SCREEN_DISTANCE_OR_EMPTY_ERRMSG .format ('abcd' )):
406
413
f2 .place_configure (height = 'abcd' )
407
414
408
415
def test_place_configure_relwidth (self ):
@@ -413,8 +420,7 @@ def test_place_configure_relwidth(self):
413
420
f2 .place_configure (relwidth = '' )
414
421
self .root .update ()
415
422
self .assertEqual (f2 .winfo_width (), 30 )
416
- with self .assertRaisesRegex (TclError , 'expected floating-point number '
417
- 'but got "abcd"' ):
423
+ with self .assertRaisesRegex (TclError , EXPECTED_FLOAT_OR_EMPTY_ERRMSG .format ('abcd' )):
418
424
f2 .place_configure (relwidth = 'abcd' )
419
425
420
426
def test_place_configure_relheight (self ):
@@ -425,8 +431,7 @@ def test_place_configure_relheight(self):
425
431
f2 .place_configure (relheight = '' )
426
432
self .root .update ()
427
433
self .assertEqual (f2 .winfo_height (), 60 )
428
- with self .assertRaisesRegex (TclError , 'expected floating-point number '
429
- 'but got "abcd"' ):
434
+ with self .assertRaisesRegex (TclError , EXPECTED_FLOAT_OR_EMPTY_ERRMSG .format ('abcd' )):
430
435
f2 .place_configure (relheight = 'abcd' )
431
436
432
437
def test_place_configure_bordermode (self ):
@@ -629,7 +634,8 @@ def test_grid_columnconfigure(self):
629
634
self .assertEqual (self .root .grid_columnconfigure (0 , 'weight' ), 4 )
630
635
631
636
def test_grid_columnconfigure_minsize (self ):
632
- with self .assertRaisesRegex (TclError , 'bad screen distance "foo"' ):
637
+ with self .assertRaisesRegex (TclError ,
638
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('foo' )):
633
639
self .root .grid_columnconfigure (0 , minsize = 'foo' )
634
640
self .root .grid_columnconfigure (0 , minsize = 10 )
635
641
self .assertEqual (self .root .grid_columnconfigure (0 , 'minsize' ), 10 )
@@ -646,7 +652,8 @@ def test_grid_columnconfigure_weight(self):
646
652
self .assertEqual (self .root .grid_columnconfigure (0 )['weight' ], 3 )
647
653
648
654
def test_grid_columnconfigure_pad (self ):
649
- with self .assertRaisesRegex (TclError , 'bad screen distance "foo"' ):
655
+ with self .assertRaisesRegex (TclError ,
656
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('foo' )):
650
657
self .root .grid_columnconfigure (0 , pad = 'foo' )
651
658
with self .assertRaisesRegex (TclError , 'invalid arg "-pad": '
652
659
'should be non-negative' ):
@@ -683,7 +690,8 @@ def test_grid_rowconfigure(self):
683
690
self .assertEqual (self .root .grid_rowconfigure (0 , 'weight' ), 4 )
684
691
685
692
def test_grid_rowconfigure_minsize (self ):
686
- with self .assertRaisesRegex (TclError , 'bad screen distance "foo"' ):
693
+ with self .assertRaisesRegex (TclError ,
694
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('foo' )):
687
695
self .root .grid_rowconfigure (0 , minsize = 'foo' )
688
696
self .root .grid_rowconfigure (0 , minsize = 10 )
689
697
self .assertEqual (self .root .grid_rowconfigure (0 , 'minsize' ), 10 )
@@ -700,7 +708,8 @@ def test_grid_rowconfigure_weight(self):
700
708
self .assertEqual (self .root .grid_rowconfigure (0 )['weight' ], 3 )
701
709
702
710
def test_grid_rowconfigure_pad (self ):
703
- with self .assertRaisesRegex (TclError , 'bad screen distance "foo"' ):
711
+ with self .assertRaisesRegex (TclError ,
712
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('foo' )):
704
713
self .root .grid_rowconfigure (0 , pad = 'foo' )
705
714
with self .assertRaisesRegex (TclError , 'invalid arg "-pad": '
706
715
'should be non-negative' ):
@@ -818,9 +827,11 @@ def test_grid_location(self):
818
827
self .root .grid_location (0 )
819
828
with self .assertRaises (TypeError ):
820
829
self .root .grid_location (0 , 0 , 0 )
821
- with self .assertRaisesRegex (TclError , 'bad screen distance "x"' ):
830
+ with self .assertRaisesRegex (TclError ,
831
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('x' )):
822
832
self .root .grid_location ('x' , 'y' )
823
- with self .assertRaisesRegex (TclError , 'bad screen distance "y"' ):
833
+ with self .assertRaisesRegex (TclError ,
834
+ EXPECTED_SCREEN_DISTANCE_ERRMSG .format ('y' )):
824
835
self .root .grid_location ('1c' , 'y' )
825
836
t = self .root
826
837
# de-maximize
0 commit comments