27
27
28
28
def test_column_creation ():
29
29
# Width less than 1
30
- with pytest .raises (ValueError ) as excinfo :
30
+ with pytest .raises (ValueError , match = "Column width cannot be less than 1" ) :
31
31
Column ("Column 1" , width = 0 )
32
- assert "Column width cannot be less than 1" in str (excinfo .value )
33
32
34
33
# Width specified
35
34
c = Column ("header" , width = 20 )
36
35
assert c .width == 20
37
36
38
37
# 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" ) :
40
39
Column ("Column 1" , max_data_lines = 0 )
41
- assert "Max data lines cannot be less than 1" in str (excinfo .value )
42
40
43
41
# No width specified, blank label
44
42
c = Column ("" )
@@ -311,15 +309,13 @@ def test_generate_row_exceptions():
311
309
# Unprintable characters
312
310
for arg in ['fill_char' , 'pre_line' , 'inter_cell' , 'post_line' ]:
313
311
kwargs = {arg : '\n ' }
314
- with pytest .raises (ValueError ) as excinfo :
312
+ with pytest .raises (ValueError , match = f" { arg } contains an unprintable character" ) :
315
313
tc .generate_row (row_data = row_data , is_header = False , ** kwargs )
316
- assert "{} contains an unprintable character" .format (arg ) in str (excinfo .value )
317
314
318
315
# Data with too many columns
319
316
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" ) :
321
318
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 )
323
319
324
320
325
321
def test_tabs ():
@@ -332,9 +328,8 @@ def test_tabs():
332
328
row = tc .generate_row (row_data , is_header = True , fill_char = '\t ' , pre_line = '\t ' , inter_cell = '\t ' , post_line = '\t ' )
333
329
assert row == ' Col 1 Col 2 '
334
330
335
- with pytest .raises (ValueError ) as excinfo :
331
+ with pytest .raises (ValueError , match = "Tab width cannot be less than 1" ) :
336
332
TableCreator ([column_1 , column_2 ], tab_width = 0 )
337
- assert "Tab width cannot be less than 1" in str (excinfo .value )
338
333
339
334
340
335
def test_simple_table_creation ():
@@ -439,24 +434,20 @@ def test_simple_table_creation():
439
434
)
440
435
441
436
# Invalid column spacing
442
- with pytest .raises (ValueError ) as excinfo :
437
+ with pytest .raises (ValueError , match = "Column spacing cannot be less than 0" ) :
443
438
SimpleTable ([column_1 , column_2 ], column_spacing = - 1 )
444
- assert "Column spacing cannot be less than 0" in str (excinfo .value )
445
439
446
440
# Invalid divider character
447
- with pytest .raises (TypeError ) as excinfo :
441
+ with pytest .raises (TypeError , match = "Divider character must be exactly one character long" ) :
448
442
SimpleTable ([column_1 , column_2 ], divider_char = 'too long' )
449
- assert "Divider character must be exactly one character long" in str (excinfo .value )
450
443
451
- with pytest .raises (ValueError ) as excinfo :
444
+ with pytest .raises (ValueError , match = "Divider character is an unprintable character" ) :
452
445
SimpleTable ([column_1 , column_2 ], divider_char = '\n ' )
453
- assert "Divider character is an unprintable character" in str (excinfo .value )
454
446
455
447
# Invalid row spacing
456
448
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" ) :
458
450
st .generate_table (row_data , row_spacing = - 1 )
459
- assert "Row spacing cannot be less than 0" in str (excinfo .value )
460
451
461
452
# Test header and data colors
462
453
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():
487
478
assert SimpleTable .base_width (num_cols ) == (num_cols - 1 ) * 2
488
479
489
480
# Invalid num_cols value
490
- with pytest .raises (ValueError ) as excinfo :
481
+ with pytest .raises (ValueError , match = "Column count cannot be less than 1" ) :
491
482
SimpleTable .base_width (0 )
492
- assert "Column count cannot be less than 1" in str (excinfo .value )
493
483
494
484
# Total width
495
485
column_1 = Column ("Col 1" , width = 16 )
@@ -509,9 +499,8 @@ def test_simple_generate_data_row_exceptions():
509
499
510
500
# Data with too many columns
511
501
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" ) :
513
503
tc .generate_data_row (row_data = row_data )
514
- assert "Length of row_data must match length of cols" in str (excinfo .value )
515
504
516
505
517
506
def test_bordered_table_creation ():
@@ -573,9 +562,8 @@ def test_bordered_table_creation():
573
562
)
574
563
575
564
# Invalid padding
576
- with pytest .raises (ValueError ) as excinfo :
565
+ with pytest .raises (ValueError , match = "Padding cannot be less than 0" ) :
577
566
BorderedTable ([column_1 , column_2 ], padding = - 1 )
578
- assert "Padding cannot be less than 0" in str (excinfo .value )
579
567
580
568
# Test border, header, and data colors
581
569
bt = BorderedTable ([column_1 , column_2 ], border_fg = Fg .LIGHT_YELLOW , border_bg = Bg .WHITE ,
@@ -629,9 +617,8 @@ def test_bordered_table_width():
629
617
assert BorderedTable .base_width (3 , padding = 3 ) == 22
630
618
631
619
# Invalid num_cols value
632
- with pytest .raises (ValueError ) as excinfo :
620
+ with pytest .raises (ValueError , match = "Column count cannot be less than 1" ) :
633
621
BorderedTable .base_width (0 )
634
- assert "Column count cannot be less than 1" in str (excinfo .value )
635
622
636
623
# Total width
637
624
column_1 = Column ("Col 1" , width = 15 )
@@ -651,9 +638,8 @@ def test_bordered_generate_data_row_exceptions():
651
638
652
639
# Data with too many columns
653
640
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" ) :
655
642
tc .generate_data_row (row_data = row_data )
656
- assert "Length of row_data must match length of cols" in str (excinfo .value )
657
643
658
644
659
645
def test_alternating_table_creation ():
@@ -711,9 +697,8 @@ def test_alternating_table_creation():
711
697
)
712
698
713
699
# Invalid padding
714
- with pytest .raises (ValueError ) as excinfo :
700
+ with pytest .raises (ValueError , match = "Padding cannot be less than 0" ) :
715
701
AlternatingTable ([column_1 , column_2 ], padding = - 1 )
716
- assert "Padding cannot be less than 0" in str (excinfo .value )
717
702
718
703
# Test border, header, and data colors
719
704
at = AlternatingTable ([column_1 , column_2 ], border_fg = Fg .LIGHT_YELLOW , border_bg = Bg .WHITE ,
0 commit comments