14
14
from typing import TYPE_CHECKING
15
15
16
16
import pytest
17
+ from _pytest .recwarn import WarningsRecorder
17
18
18
19
from pylint import checkers
19
20
from pylint .interfaces import HIGH
@@ -88,16 +89,12 @@ def test_template_option_non_existing(linter) -> None:
88
89
"""
89
90
output = StringIO ()
90
91
linter .reporter .out = output
91
- linter .config .msg_template = (
92
- "{path}:{line}:{a_new_option}:({a_second_new_option:03d})"
93
- )
92
+ linter .config .msg_template = "{path}:{line}:{categ}:({a_second_new_option:03d})"
94
93
linter .open ()
95
94
with pytest .warns (UserWarning ) as records :
96
95
linter .set_current_module ("my_mod" )
97
96
assert len (records ) == 2
98
- assert (
99
- "Don't recognize the argument 'a_new_option'" in records [0 ].message .args [0 ]
100
- )
97
+ assert "Don't recognize the argument 'categ'" in records [0 ].message .args [0 ]
101
98
assert (
102
99
"Don't recognize the argument 'a_second_new_option'"
103
100
in records [1 ].message .args [0 ]
@@ -113,7 +110,24 @@ def test_template_option_non_existing(linter) -> None:
113
110
assert out_lines [2 ] == "my_mod:2::()"
114
111
115
112
116
- def test_deprecation_set_output (recwarn ):
113
+ def test_template_option_with_header (linter : PyLinter ) -> None :
114
+ output = StringIO ()
115
+ linter .reporter .out = output
116
+ linter .config .msg_template = '{{ "Category": "{category}" }}'
117
+ linter .open ()
118
+ linter .set_current_module ("my_mod" )
119
+
120
+ linter .add_message ("C0301" , line = 1 , args = (1 , 2 ))
121
+ linter .add_message (
122
+ "line-too-long" , line = 2 , end_lineno = 2 , end_col_offset = 4 , args = (3 , 4 )
123
+ )
124
+
125
+ out_lines = output .getvalue ().split ("\n " )
126
+ assert out_lines [1 ] == '{ "Category": "convention" }'
127
+ assert out_lines [2 ] == '{ "Category": "convention" }'
128
+
129
+
130
+ def test_deprecation_set_output (recwarn : WarningsRecorder ) -> None :
117
131
"""TODO remove in 3.0."""
118
132
reporter = BaseReporter ()
119
133
# noinspection PyDeprecation
0 commit comments