Skip to content

Commit 9e16e68

Browse files
committed
fix: address commnets add tests and better news
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
1 parent f1eba0c commit 9e16e68

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

Lib/test/test_pydoc/test_pydoc.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,48 @@ def test_keywords(self):
21652165
self.assertEqual(sorted(pydoc.Helper.keywords),
21662166
sorted(keyword.kwlist))
21672167

2168+
def test_interact_empty_line_continues(self):
2169+
with captured_stdout() as output:
2170+
helper = pydoc.Helper(output=output)
2171+
input_sequence = ['', 'quit']
2172+
call_count = [0]
2173+
def mock_getline(prompt):
2174+
output.write(prompt)
2175+
result = input_sequence[call_count[0]]
2176+
call_count[0] += 1
2177+
return result
2178+
2179+
with unittest.mock.patch.object(helper, 'getline', side_effect=mock_getline):
2180+
helper.interact()
2181+
2182+
output_text = output.getvalue()
2183+
prompt_count = output_text.count('help> ')
2184+
self.assertEqual(prompt_count, 2)
2185+
2186+
def test_interact_quit_commands_exit(self):
2187+
quit_commands = ['quit', 'q', 'exit']
2188+
2189+
for quit_cmd in quit_commands:
2190+
with self.subTest(quit_command=quit_cmd):
2191+
with captured_stdout() as output:
2192+
helper = pydoc.Helper(output=output)
2193+
2194+
call_count = [0]
2195+
2196+
def mock_getline(prompt):
2197+
output.write(prompt)
2198+
call_count[0] += 1
2199+
return quit_cmd
2200+
2201+
with unittest.mock.patch.object(helper, 'getline', side_effect=mock_getline):
2202+
helper.interact()
2203+
2204+
# Should only be called once before exiting
2205+
self.assertEqual(call_count[0], 1)
2206+
output_text = output.getvalue()
2207+
prompt_count = output_text.count('help> ')
2208+
self.assertEqual(prompt_count, 1)
2209+
21682210

21692211
class PydocWithMetaClasses(unittest.TestCase):
21702212
def tearDown(self):
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
make the same exit behavior in repl help mode.
1+
In :mod:`pydoc` interactive help mode to handle empty input correctly.
2+
Empty lines (pressing Enter without input) now continue the help session
3+
instead of exiting, matching the documented behavior that only "q", "quit",
4+
or "exit" commands should terminate the help session.

0 commit comments

Comments
 (0)