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