Coverage for tests / unit / parsers / test_pydoclint_parser.py: 100%

34 statements  

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

1"""Unit tests for pydoclint parser.""" 

2 

3from __future__ import annotations 

4 

5from assertpy import assert_that 

6 

7from lintro.parsers.pydoclint.pydoclint_parser import parse_pydoclint_output 

8 

9 

10def test_parse_pydoclint_output_empty() -> None: 

11 """Handle empty and None output.""" 

12 assert_that(parse_pydoclint_output(None)).is_empty() 

13 assert_that(parse_pydoclint_output("")).is_empty() 

14 assert_that(parse_pydoclint_output(" \n\n ")).is_empty() 

15 

16 

17def test_parse_pydoclint_output_single_file_single_issue() -> None: 

18 """Parse single file with single issue.""" 

19 output = """/path/to/file.py 

20 10: DOC101: Function `foo` has 1 argument(s) missing""" 

21 issues = parse_pydoclint_output(output) 

22 assert_that(issues).is_length(1) 

23 assert_that(issues[0].file).is_equal_to("/path/to/file.py") 

24 assert_that(issues[0].line).is_equal_to(10) 

25 assert_that(issues[0].code).is_equal_to("DOC101") 

26 assert_that(issues[0].message).contains("argument(s)") 

27 # pydoclint doesn't provide column info 

28 assert_that(issues[0].column).is_equal_to(0) 

29 

30 

31def test_parse_pydoclint_output_single_file_multiple_issues() -> None: 

32 """Parse single file with multiple issues.""" 

33 output = """/path/to/file.py 

34 10: DOC101: Missing argument 

35 15: DOC102: Missing return""" 

36 issues = parse_pydoclint_output(output) 

37 assert_that(issues).is_length(2) 

38 assert_that(issues[0].line).is_equal_to(10) 

39 assert_that(issues[1].line).is_equal_to(15) 

40 

41 

42def test_parse_pydoclint_output_multiple_files() -> None: 

43 """Parse multiple files with issues.""" 

44 output = """/path/to/file1.py 

45 10: DOC101: Issue in file1 

46/path/to/file2.py 

47 20: DOC102: Issue in file2""" 

48 issues = parse_pydoclint_output(output) 

49 assert_that(issues).is_length(2) 

50 assert_that(issues[0].file).is_equal_to("/path/to/file1.py") 

51 assert_that(issues[1].file).is_equal_to("/path/to/file2.py") 

52 

53 

54def test_parse_pydoclint_output_ansi_codes_stripped() -> None: 

55 """Strip ANSI escape codes from output for consistent CI/local parsing.""" 

56 # Output with ANSI color codes (common in CI environments) 

57 output = """\x1b[1m/path/to/file.py\x1b[0m 

58 \x1b[31m10: DOC101: Function `foo` has 1 argument(s) missing\x1b[0m""" 

59 issues = parse_pydoclint_output(output) 

60 assert_that(issues).is_length(1) 

61 assert_that(issues[0].file).is_equal_to("/path/to/file.py") 

62 assert_that(issues[0].code).is_equal_to("DOC101")