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

21 statements  

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

1"""Unit tests for MarkdownStyle formatter. 

2 

3Tests verify MarkdownStyle correctly formats tabular data as valid 

4Markdown tables with proper escaping. 

5""" 

6 

7from __future__ import annotations 

8 

9from assertpy import assert_that 

10 

11from lintro.formatters.styles.markdown import MarkdownStyle 

12 

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

14 

15 

16def test_markdown_style_single_row_produces_valid_table( 

17 markdown_style: MarkdownStyle, 

18) -> None: 

19 """MarkdownStyle formats single row as valid markdown table. 

20 

21 Args: 

22 markdown_style: The MarkdownStyle formatter instance. 

23 """ 

24 result = markdown_style.format(STANDARD_COLUMNS, SINGLE_ROW_DATA) 

25 lines = result.split("\n") 

26 

27 assert_that(lines).is_length(3) # header, separator, data row 

28 assert_that(result).contains("| File | Line | Message |") 

29 assert_that(result).contains("| --- | --- | --- |") 

30 assert_that(result).contains("| src/main.py | 10 | Error found |") 

31 

32 

33def test_markdown_style_multiple_rows_produces_correct_line_count( 

34 markdown_style: MarkdownStyle, 

35) -> None: 

36 """MarkdownStyle formats multiple rows with correct number of lines. 

37 

38 Args: 

39 markdown_style: The MarkdownStyle formatter instance. 

40 """ 

41 result = markdown_style.format(TWO_COLUMNS, MULTI_ROW_DATA) 

42 lines = result.split("\n") 

43 

44 assert_that(lines).is_length(4) # header, separator, 2 data rows 

45 

46 

47def test_markdown_style_escapes_pipe_characters(markdown_style: MarkdownStyle) -> None: 

48 """MarkdownStyle escapes pipe characters in cell values. 

49 

50 Args: 

51 markdown_style: The MarkdownStyle formatter instance. 

52 """ 

53 result = markdown_style.format(["Message"], [["A | B"]]) 

54 

55 assert_that(result).contains("A \\| B") 

56 

57 

58def test_markdown_style_row_shorter_than_columns(markdown_style: MarkdownStyle) -> None: 

59 """MarkdownStyle handles row with fewer elements than columns. 

60 

61 Args: 

62 markdown_style: The MarkdownStyle formatter instance. 

63 """ 

64 result = markdown_style.format(STANDARD_COLUMNS, [["src/main.py"]]) 

65 

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