1010requires ('gui' )
1111
1212
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+
1318class PackTest (AbstractWidgetTest , unittest .TestCase ):
1419
1520 test_keys = None
@@ -317,7 +322,8 @@ def test_place_configure_x(self):
317322 self .assertEqual (f2 .place_info ()['x' ], '-10' )
318323 self .root .update ()
319324 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' )):
321327 f2 .place_configure (in_ = f , x = 'spam' )
322328
323329 def test_place_configure_y (self ):
@@ -334,7 +340,8 @@ def test_place_configure_y(self):
334340 self .assertEqual (f2 .place_info ()['y' ], '-10' )
335341 self .root .update ()
336342 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' )):
338345 f2 .place_configure (in_ = f , y = 'spam' )
339346
340347 def test_place_configure_relx (self ):
@@ -351,8 +358,7 @@ def test_place_configure_relx(self):
351358 self .assertEqual (f2 .place_info ()['relx' ], '1' )
352359 self .root .update ()
353360 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' )):
356362 f2 .place_configure (in_ = f , relx = 'spam' )
357363
358364 def test_place_configure_rely (self ):
@@ -369,8 +375,7 @@ def test_place_configure_rely(self):
369375 self .assertEqual (f2 .place_info ()['rely' ], '1' )
370376 self .root .update ()
371377 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' )):
374379 f2 .place_configure (in_ = f , rely = 'spam' )
375380
376381 def test_place_configure_anchor (self ):
@@ -391,7 +396,8 @@ def test_place_configure_width(self):
391396 f2 .place_configure (width = '' )
392397 self .root .update ()
393398 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' )):
395401 f2 .place_configure (width = 'abcd' )
396402
397403 def test_place_configure_height (self ):
@@ -402,7 +408,8 @@ def test_place_configure_height(self):
402408 f2 .place_configure (height = '' )
403409 self .root .update ()
404410 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' )):
406413 f2 .place_configure (height = 'abcd' )
407414
408415 def test_place_configure_relwidth (self ):
@@ -413,8 +420,7 @@ def test_place_configure_relwidth(self):
413420 f2 .place_configure (relwidth = '' )
414421 self .root .update ()
415422 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' )):
418424 f2 .place_configure (relwidth = 'abcd' )
419425
420426 def test_place_configure_relheight (self ):
@@ -425,8 +431,7 @@ def test_place_configure_relheight(self):
425431 f2 .place_configure (relheight = '' )
426432 self .root .update ()
427433 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' )):
430435 f2 .place_configure (relheight = 'abcd' )
431436
432437 def test_place_configure_bordermode (self ):
@@ -629,7 +634,8 @@ def test_grid_columnconfigure(self):
629634 self .assertEqual (self .root .grid_columnconfigure (0 , 'weight' ), 4 )
630635
631636 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' )):
633639 self .root .grid_columnconfigure (0 , minsize = 'foo' )
634640 self .root .grid_columnconfigure (0 , minsize = 10 )
635641 self .assertEqual (self .root .grid_columnconfigure (0 , 'minsize' ), 10 )
@@ -646,7 +652,8 @@ def test_grid_columnconfigure_weight(self):
646652 self .assertEqual (self .root .grid_columnconfigure (0 )['weight' ], 3 )
647653
648654 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' )):
650657 self .root .grid_columnconfigure (0 , pad = 'foo' )
651658 with self .assertRaisesRegex (TclError , 'invalid arg "-pad": '
652659 'should be non-negative' ):
@@ -683,7 +690,8 @@ def test_grid_rowconfigure(self):
683690 self .assertEqual (self .root .grid_rowconfigure (0 , 'weight' ), 4 )
684691
685692 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' )):
687695 self .root .grid_rowconfigure (0 , minsize = 'foo' )
688696 self .root .grid_rowconfigure (0 , minsize = 10 )
689697 self .assertEqual (self .root .grid_rowconfigure (0 , 'minsize' ), 10 )
@@ -700,7 +708,8 @@ def test_grid_rowconfigure_weight(self):
700708 self .assertEqual (self .root .grid_rowconfigure (0 )['weight' ], 3 )
701709
702710 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' )):
704713 self .root .grid_rowconfigure (0 , pad = 'foo' )
705714 with self .assertRaisesRegex (TclError , 'invalid arg "-pad": '
706715 'should be non-negative' ):
@@ -818,9 +827,11 @@ def test_grid_location(self):
818827 self .root .grid_location (0 )
819828 with self .assertRaises (TypeError ):
820829 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' )):
822832 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' )):
824835 self .root .grid_location ('1c' , 'y' )
825836 t = self .root
826837 # de-maximize
0 commit comments