8000 bpo-41818: Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0. by 8vasu · Pull Request #23526 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-41818: Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0. #23526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions Lib/test/test_pty.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import_module('termios')

import errno
import pathlib
import pty
import os
import sys
Expand Down Expand Up @@ -75,20 +74,7 @@ def _readline(fd):
return reader.readline()

def expectedFailureIfStdinIsTTY(fun):
# avoid isatty() for now
PLATFORM = platform.system()
if PLATFORM == "Linux":
os_release = pathlib.Path("/etc/os-release")
if os_release.exists():
# Actually the file has complex multi-line structure,
# these is no need to parse it for Gentoo check
if 'gentoo' in os_release.read_text().lower():
# bpo-41818:
# Gentoo passes the test,
# all other tested Linux distributions fail.
# Should not apply @unittest.expectedFailure() on Gentoo
# to keep the buildbot fleet happy.
return fun
# avoid isatty()
try:
tty.tcgetattr(pty.STDIN_FILENO)
return unittest.expectedFailure(fun)
Expand Down Expand Up @@ -165,11 +151,16 @@ def test_openpty(self):
new_stdin_winsz = None
if self.stdin_rows != None and self.stdin_cols != None:
try:
# Modify pty.STDIN_FILENO window size; we need to
# check if pty.openpty() is able to set pty slave
# window size accordingly.
debug("Setting pty.STDIN_FILENO window size")
# Set number of columns and rows to be the
# floors of 1/5 of respective original values
target_stdin_winsz = struct.pack("HHHH", self.stdin_rows//5,
self.stdin_cols//5, 0, 0)
debug(f"original size: (rows={self.stdin_rows}, cols={self.stdin_cols})")
target_stdin_rows = self.stdin_rows + 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a few words to describe the resize trick and why it is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added some comments. Please let me know if this looks good.

target_stdin_cols = self.stdin_cols + 1
debug(f"target size: (rows={target_stdin_rows}, cols={target_stdin_cols})")
target_stdin_winsz = struct.pack("HHHH", target_stdin_rows,
target_stdin_cols, 0, 0)
_set_term_winsz(pty.STDIN_FILENO, target_stdin_winsz)

# Were we able to set the window size
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0.
0