summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_pyrepl/support.py
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2024-07-13 10:54:10 (GMT)
committerGitHub <noreply@github.com>2024-07-13 10:54:10 (GMT)
commit4b9e10d0ea352592049c1f2a00318d7274143fa4 (patch)
tree1c2c4a8484e656db28fd88dac57702c69bcf60da /Lib/test/test_pyrepl/support.py
parente745996b2d24b9234f896bdc2f3320e49287dcd0 (diff)
downloadcpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.zip
cpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.tar.gz
cpython-4b9e10d0ea352592049c1f2a00318d7274143fa4.tar.bz2
gh-121499: Fix multi-line history rendering in the REPL (#121531)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Diffstat (limited to 'Lib/test/test_pyrepl/support.py')
-rw-r--r--Lib/test/test_pyrepl/support.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_pyrepl/support.py b/Lib/test/test_pyrepl/support.py
index 70e1228..58b1a92 100644
--- a/Lib/test/test_pyrepl/support.py
+++ b/Lib/test/test_pyrepl/support.py
@@ -38,6 +38,20 @@ def code_to_events(code: str):
yield Event(evt="key", data=c, raw=bytearray(c.encode("utf-8")))
+def clean_screen(screen: Iterable[str]):
+ """Cleans color and console characters out of a screen output.
+
+ This is useful for screen testing, it increases the test readability since
+ it strips out all the unreadable side of the screen.
+ """
+ output = []
+ for line in screen:
+ if line.startswith(">>>") or line.startswith("..."):
+ line = line[3:]
+ output.append(line)
+ return "\n".join(output).strip()
+
+
def prepare_reader(console: Console, **kwargs):
config = ReadlineConfig(readline_completer=kwargs.pop("readline_completer", None))
reader = ReadlineAlikeReader(console=console, config=config)