2727
2828def test_column_creation ():
2929 # Width less than 1
30- with pytest .raises (ValueError ) as excinfo :
30+ with pytest .raises (ValueError , match = "Column width cannot be less than 1" ) :
3131 Column ("Column 1" , width = 0 )
32- assert "Column width cannot be less than 1" in str (excinfo .value )
3332
3433 # Width specified
3534 c = Column ("header" , width = 20 )
3635 assert c .width == 20
3736
3837 # max_data_lines less than 1
39- with pytest .raises (ValueError ) as excinfo :
38+ with pytest .raises (ValueError , match = "Max data lines cannot be less than 1" ) :
4039 Column ("Column 1" , max_data_lines = 0 )
41- assert "Max data lines cannot be less than 1" in str (excinfo .value )
4240
4341 # No width specified, blank label
4442 c = Column ("" )
@@ -311,15 +309,13 @@ def test_generate_row_exceptions():
311309 # Unprintable characters
312310 for arg in ['fill_char' , 'pre_line' , 'inter_cell' , 'post_line' ]:
313311 kwargs = {arg : '\n ' }
314- with pytest .raises (ValueError ) as excinfo :
312+ with pytest .raises (ValueError , match = f" { arg } contains an unprintable character" ) :
315313 tc .generate_row (row_data = row_data , is_header = False , ** kwargs )
316- assert "{} contains an unprintable character" .format (arg ) in str (excinfo .value )
317314
318315 # Data with too many columns
319316 row_data = ['Data 1' , 'Extra Column' ]
320- with pytest .raises (ValueError ) as excinfo :
317+ with pytest .raises (ValueError , match = "Length of row_data must match length of cols" ) :
321318 tc .generate_row (row_data = row_data , is_header = False )
322- assert "Length of row_data must match length of cols" in str (excinfo .value )
323319
324320
325321def test_tabs ():
@@ -332,9 +328,8 @@ def test_tabs():
332328 row = tc .generate_row (row_data , is_header = True , fill_char = '\t ' , pre_line = '\t ' , inter_cell = '\t ' , post_line = '\t ' )
333329 assert row == ' Col 1 Col 2 '
334330
335- with pytest .raises (ValueError ) as excinfo :
331+ with pytest .raises (ValueError , match = "Tab width cannot be less than 1" ) :
336332 TableCreator ([column_1 , column_2 ], tab_width = 0 )
337- assert "Tab width cannot be less than 1" in str (excinfo .value )
338333
339334
340335def test_simple_table_creation ():
@@ -439,24 +434,20 @@ def test_simple_table_creation():
439434 )
440435
441436 # Invalid column spacing
442- with pytest .raises (ValueError ) as excinfo :
437+ with pytest .raises (ValueError , match = "Column spacing cannot be less than 0" ) :
443438 SimpleTable ([column_1 , column_2 ], column_spacing = - 1 )
444- assert "Column spacing cannot be less than 0" in str (excinfo .value )
445439
446440 # Invalid divider character
447- with pytest .raises (TypeError ) as excinfo :
441+ with pytest .raises (TypeError , match = "Divider character must be exactly one character long" ) :
448442 SimpleTable ([column_1 , column_2 ], divider_char = 'too long' )
449- assert "Divider character must be exactly one character long" in str (excinfo .value )
450443
451- with pytest .raises (ValueError ) as excinfo :
444+ with pytest .raises (ValueError , match = "Divider character is an unprintable character" ) :
452445 SimpleTable ([column_1 , column_2 ], divider_char = '\n ' )
453- assert "Divider character is an unprintable character" in str (excinfo .value )
454446
455447 # Invalid row spacing
456448 st = SimpleTable ([column_1 , column_2 ])
457- with pytest .raises (ValueError ) as excinfo :
449+ with pytest .raises (ValueError , match = "Row spacing cannot be less than 0" ) :
458450 st .generate_table (row_data , row_spacing = - 1 )
459- assert "Row spacing cannot be less than 0" in str (excinfo .value )
460451
461452 # Test header and data colors
462453 st = SimpleTable ([column_1 , column_2 ], divider_char = None , header_bg = Bg .GREEN , data_bg = Bg .LIGHT_BLUE )
@@ -487,9 +478,8 @@ def test_simple_table_width():
487478 assert SimpleTable .base_width (num_cols ) == (num_cols - 1 ) * 2
488479
489480 # Invalid num_cols value
490- with pytest .raises (ValueError ) as excinfo :
481+ with pytest .raises (ValueError , match = "Column count cannot be less than 1" ) :
491482 SimpleTable .base_width (0 )
492- assert "Column count cannot be less than 1" in str (excinfo .value )
493483
494484 # Total width
495485 column_1 = Column ("Col 1" , width = 16 )
@@ -509,9 +499,8 @@ def test_simple_generate_data_row_exceptions():
509499
510500 # Data with too many columns
511501 row_data = ['Data 1' , 'Extra Column' ]
512- with pytest .raises (ValueError ) as excinfo :
502+ with pytest .raises (ValueError , match = "Length of row_data must match length of cols" ) :
513503 tc .generate_data_row (row_data = row_data )
514- assert "Length of row_data must match length of cols" in str (excinfo .value )
515504
516505
517506def test_bordered_table_creation ():
@@ -573,9 +562,8 @@ def test_bordered_table_creation():
573562 )
574563
575564 # Invalid padding
576- with pytest .raises (ValueError ) as excinfo :
565+ with pytest .raises (ValueError , match = "Padding cannot be less than 0" ) :
577566 BorderedTable ([column_1 , column_2 ], padding = - 1 )
578- assert "Padding cannot be less than 0" in str (excinfo .value )
579567
580568 # Test border, header, and data colors
581569 bt = BorderedTable ([column_1 , column_2 ], border_fg = Fg .LIGHT_YELLOW , border_bg = Bg .WHITE ,
@@ -629,9 +617,8 @@ def test_bordered_table_width():
629617 assert BorderedTable .base_width (3 , padding = 3 ) == 22
630618
631619 # Invalid num_cols value
632- with pytest .raises (ValueError ) as excinfo :
620+ with pytest .raises (ValueError , match = "Column count cannot be less than 1" ) :
633621 BorderedTable .base_width (0 )
634- assert "Column count cannot be less than 1" in str (excinfo .value )
635622
636623 # Total width
637624 column_1 = Column ("Col 1" , width = 15 )
@@ -651,9 +638,8 @@ def test_bordered_generate_data_row_exceptions():
651638
652639 # Data with too many columns
653640 row_data = ['Data 1' , 'Extra Column' ]
654- with pytest .raises (ValueError ) as excinfo :
641+ with pytest .raises (ValueError , match = "Length of row_data must match length of cols" ) :
655642 tc .generate_data_row (row_data = row_data )
656- assert "Length of row_data must match length of cols" in str (excinfo .value )
657643
658644
659645def test_alternating_table_creation ():
@@ -711,9 +697,8 @@ def test_alternating_table_creation():
711697 )
712698
713699 # Invalid padding
714- with pytest .raises (ValueError ) as excinfo :
700+ with pytest .raises (ValueError , match = "Padding cannot be less than 0" ) :
715701 AlternatingTable ([column_1 , column_2 ], padding = - 1 )
716- assert "Padding cannot be less than 0" in str (excinfo .value )
717702
718703 # Test border, header, and data colors
719704 at = AlternatingTable ([column_1 , column_2 ], border_fg = Fg .LIGHT_YELLOW , border_bg = Bg .WHITE ,
0 commit comments