Coverage for tests / unit / formatters / styles / test_style_grid.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-04-03 18:53 +0000

1"""Unit tests for GridStyle formatter. 

2 

3Tests verify GridStyle correctly formats tabular data as grid-style 

4tables with borders and proper alignment. 

5""" 

6 

7from __future__ import annotations 

8 

9from assertpy import assert_that 

10 

11from lintro.formatters.styles.grid import GridStyle 

12 

13from .conftest import MULTI_ROW_DATA, SINGLE_ROW_DATA, STANDARD_COLUMNS, TWO_COLUMNS 

14 

15 

16def test_grid_style_single_row_contains_header_and_data( 

17 grid_style: GridStyle, 

18) -> None: 

19 """GridStyle format includes header and data values. 

20 

21 Args: 

22 grid_style: The GridStyle formatter instance. 

23 """ 

24 result = grid_style.format(STANDARD_COLUMNS, SINGLE_ROW_DATA) 

25 

26 assert_that(result).contains("File") 

27 assert_that(result).contains("src/main.py") 

28 

29 

30def test_grid_style_multiple_rows_contains_all_files(grid_style: GridStyle) -> None: 

31 """GridStyle format includes all file paths from multiple rows. 

32 

33 Args: 

34 grid_style: The GridStyle formatter instance. 

35 """ 

36 result = grid_style.format(TWO_COLUMNS, MULTI_ROW_DATA) 

37 

38 assert_that(result).contains("src/a.py") 

39 assert_that(result).contains("src/b.py") 

40 

41 

42def test_grid_style_column_alignment_produces_output(grid_style: GridStyle) -> None: 

43 """GridStyle with alignment columns produces non-empty formatted output. 

44 

45 Args: 

46 grid_style: The GridStyle formatter instance. 

47 """ 

48 result = grid_style.format( 

49 ["File", "Line", "Column", "Fixable"], 

50 [["src/main.py", "10", "5", "Yes"]], 

51 ) 

52 

53 assert_that(result).is_not_empty() 

54 

55 

56def test_grid_style_empty_columns_handles_gracefully(grid_style: GridStyle) -> None: 

57 """GridStyle handles empty columns list without error. 

58 

59 Args: 

60 grid_style: The GridStyle formatter instance. 

61 """ 

62 result = grid_style.format([], [["data"]]) 

63 

64 assert_that(result).is_not_none()