gh-127349: Add check for correct resizing in REPL#127387
gh-127349: Add check for correct resizing in REPL#127387pablogsal merged 4 commits intopython:mainfrom
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
4cf7509 to
54cfe14
Compare
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
@ZeroIntensity sorry, but I can't make a test case |
|
Why not? Take a look here for some examples: https://github.com/python/cpython/blob/main/Lib/test/test_pyrepl/test_unix_console.py#L244 |
|
@ZeroIntensity I know, but unfortunately I couldn't create a similar test that would pass. I tried using the following test case but it seems that when changing the width the lines are formed differently def test_resize_smaller_than_5_width(self, _os_write):
# fmt: off
code = (
"def f():\n"
" foo"
)
# fmt: on
events = itertools.chain(code_to_events(code))
reader, console = handle_events_unix_console(events)
console.width = 2
console.getheightwidth = MagicMock(lambda _: (25, 4))
def same_reader(_):
return reader
def same_console(events):
console.get_event = MagicMock(side_effect=events)
return console
_, con = handle_all_events(
[Event(evt="resize", data=None)],
prepare_reader=same_reader,
prepare_console=same_console,
)
_os_write.assert_has_calls(
[
call(ANY, TERM_CAPABILITIES["ri"] + b":"),
call(ANY, TERM_CAPABILITIES["cup"] + b":0,0"),
call(ANY, b"def f():"),
]
)
console.restore()
con.restore()i got this: Expected: [call(<ANY>, b'\x1bM:'),
call(<ANY>, b'\x1b[%i%p1%d;%p2%dH:0,0'),
call(<ANY>, b'def f():')]
Actual: [call(1, b'\x1b[?2004h'),
call(1, b'\x1b[?1h\x1b=:'),
call(1, b'\x1b[?25l:'),
call(1, b'\x1b[%p1%dA:1'),
call(1, b'\n'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'd'),
call(1, b'\x1b[?12l\x1b[?25h:'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'e'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'f'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b' '),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'f'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'('),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b')'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b':'),
call(1, b'\x1b[?25l:'),
call(1, b'\x1b[%p1%dD:8'),
call(1, b'\n'),
call(1, b'\x1b[?12l\x1b[?25h:'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b' '),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b' '),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'f'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'o'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'o'),
call(1, b'\x1b[?25l:'),
call(1, b'\x1b[%p1%dD:5'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\n'),
call(1, b'\x1b[%p1%dC:1'),
call(1, b'\x1b[%p1%dA:12'),
call(1, b'\x1b[K:'),
call(1, b'\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'\x1b[K:'),
call(1, b'e\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'f\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b' \\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'f\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'(\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b')\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b':'),
call(1, b'\x1b[%p1%dD:1'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b' \\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b' \\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'f\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'o\\'),
call(1, b'\x1b[%p1%dD:2'),
call(1, b'\x1b[%p1%dB:1'),
call(1, b'\x1b[%p1%d@:1:'),
call(1, b'o'),
call(1, b'\x1b[?12l\x1b[?25h:')] |
|
Did you forget |
What do you mean? Sorry but I don't get it. |
|
It looks like there's plenty of ANSI color garbage in the output. Are you sure it's not screwing up your test case? |
|
@ZeroIntensity, Yes, I'm sure. And also checked, there is no difference. The thing is that these tests are aimed at checking how the code shifts after resize and do NOT even catch errors that REPL shows like in our issue #127349 (I checked this too) |
|
If the test APIs don't catch the exception, then we'll need to do something more exotic. How about spinning up a subprocess, mocking things there, and then actually starting the REPL? We're generally very hesitant to accept bugfixes without proper tests. |
|
I have added a small test for this. Thanks a lot for your contribution @donbarbos! |
fa3650b to
e67d76d
Compare
|
Thanks @donbarbos for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
|
Sorry, @donbarbos and @pablogsal, I could not cleanly backport this to |
(cherry picked from commit 510fefd)
|
GH-129484 is a backport of this pull request to the 3.13 branch. |
|
GH-129485 is a backport of this pull request to the 3.13 branch. |
|
An additional demo
demo.webm