Skip to content

Commit f5a19ea

Browse files
authored
bpo-41818: Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0. (GH-23526)
1 parent c8aaf71 commit f5a19ea

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

Lib/test/test_pty.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import_module('termios')
66

77
import errno
8-
import pathlib
98
import pty
109
import os
1110
import sys
@@ -75,20 +74,7 @@ def _readline(fd):
7574
return reader.readline()
7675

7776
def expectedFailureIfStdinIsTTY(fun):
78-
# avoid isatty() for now
79-
PLATFORM = platform.system()
80-
if PLATFORM == "Linux":
81-
os_release = pathlib.Path("/etc/os-release")
82-
if os_release.exists():
83-
# Actually the file has complex multi-line structure,
84-
# these is no need to parse it for Gentoo check
85-
if 'gentoo' in os_release.read_text().lower():
86-
# bpo-41818:
87-
# Gentoo passes the test,
88-
# all other tested Linux distributions fail.
89-
# Should not apply @unittest.expectedFailure() on Gentoo
90-
# to keep the buildbot fleet happy.
91-
return fun
77+
# avoid isatty()
9278
try:
9379
tty.tcgetattr(pty.STDIN_FILENO)
9480
return unittest.expectedFailure(fun)
@@ -165,11 +151,16 @@ def test_openpty(self):
165151
new_stdin_winsz = None
166152
if self.stdin_rows != None and self.stdin_cols != None:
167153
try:
154+
# Modify pty.STDIN_FILENO window size; we need to
155+
# check if pty.openpty() is able to set pty slave
156+
# window size accordingly.
168157
debug("Setting pty.STDIN_FILENO window size")
169-
# Set number of columns and rows to be the
170-
# floors of 1/5 of respective original values
171-
target_stdin_winsz = struct.pack("HHHH", self.stdin_rows//5,
172-
self.stdin_cols//5, 0, 0)
158+
debug(f"original size: (rows={self.stdin_rows}, cols={self.stdin_cols})")
159+
target_stdin_rows = self.stdin_rows + 1
160+
target_stdin_cols = self.stdin_cols + 1
161+
debug(f"target size: (rows={target_stdin_rows}, cols={target_stdin_cols})")
162+
target_stdin_winsz = struct.pack("HHHH", target_stdin_rows,
163+
target_stdin_cols, 0, 0)
173164
_set_term_winsz(pty.STDIN_FILENO, target_stdin_winsz)
174165

175166
# Were we able to set the window size
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make test_openpty() avoid unexpected success due to number of rows and/or number of columns being == 0.

0 commit comments

Comments
 (0)