Skip to content

Commit 9c57b6b

Browse files
committed
Fix tests/test_pt_utils.py by adding completion_header to MockCmd
The previous commit introduced accessing self.cmd_app.completion_header in Cmd2Completer.get_completions, which caused AttributeError in tests using MockCmd because it lacked this attribute. This commit adds completion_header to MockCmd and includes a new test case test_get_completions_with_header to verify that the completion header is correctly printed when present.
1 parent 20dae38 commit 9c57b6b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/test_pt_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def __init__(self):
2121
self.history = []
2222
self.formatted_completions = ''
2323
self.completion_hint = ''
24+
self.completion_header = ''
2425
self.statement_parser = Mock()
2526
self.statement_parser.terminators = [';']
2627

@@ -147,6 +148,22 @@ def test_get_completions_with_hints(self, mock_cmd_app, monkeypatch):
147148
assert mock_cmd_app.formatted_completions == ""
148149
assert mock_cmd_app.completion_hint == ""
149150

151+
def test_get_completions_with_header(self, mock_cmd_app, monkeypatch):
152+
"""Test that completion header is printed even with no matches."""
153+
mock_print = Mock()
154+
monkeypatch.setattr(pt_utils, "print_formatted_text", mock_print)
155+
156+
completer = pt_utils.Cmd2Completer(cast(Any, mock_cmd_app))
157+
document = Document("test", cursor_position=4)
158+
159+
mock_cmd_app.completion_header = "Header Text"
160+
mock_cmd_app.completion_matches = []
161+
162+
list(completer.get_completions(document, None))
163+
164+
assert mock_print.call_count == 1
165+
assert mock_cmd_app.completion_header == ""
166+
150167
def test_get_completions_completion_item_meta(self, mock_cmd_app):
151168
"""Test that CompletionItem descriptive data is used as display_meta."""
152169
completer = pt_utils.Cmd2Completer(cast(Any, mock_cmd_app))

0 commit comments

Comments
 (0)