Skip to content

Commit

Permalink
pythongh-119205: Improve unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi committed May 20, 2024
1 parent e5f1575 commit b2f1b02
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions Lib/test/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
readline = import_module("readline")

from _pyrepl.console import Console, Event
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig, multiline_input as readline_multiline_input
from _pyrepl.simple_interact import _strip_final_indent
from _pyrepl.unix_eventqueue import EventQueue
from _pyrepl.input import KeymapTranslator
Expand Down Expand Up @@ -633,7 +633,8 @@ def test_updown_arrow_with_completion_menu(self):
self.assertEqual(output, "os.")

@patch("_pyrepl.readline._ReadlineWrapper.get_reader")
def test_completion_with_warnings(self, mock_get_reader):
@patch("sys.stderr", new_callable=io.StringIO)
def test_completion_with_warnings(self, mock_stderr, mock_get_reader):
class Dummy:
@property
def test_func(self):
Expand All @@ -645,13 +646,10 @@ def test_func(self):
events = code_to_events("dummy.test_func.\t\n\n")
namespace = {"dummy": dummy}
reader = self.prepare_reader(events, namespace)
from _pyrepl.readline import multiline_input as readline_multiline_input
with patch("_pyrepl.readline._ReadlineWrapper.get_reader", lambda _: reader), \
patch("sys.stderr", new_callable=io.StringIO) as f:
output = readline_multiline_input(more_lines, ">>>", "...")

mock_get_reader.return_value = reader
output = readline_multiline_input(more_lines, ">>>", "...")
self.assertEqual(output[0], "dummy.test_func.")
self.assertEqual(f.getvalue(), "")
self.assertEqual(mock_stderr.getvalue(), "")


@patch("_pyrepl.curses.tigetstr", lambda x: b"")
Expand Down

0 comments on commit b2f1b02

Please sign in to comment.