From 81a1fa5c778c4b33ca71fcf25155189545870aab Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 9 Feb 2012 00:11:00 +0100 Subject: [PATCH] get_terminal_size() can also fail with ENOTTY if the fd is not connected to a terminal. --- Lib/test/test_os.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index b9eb2902b8..c5dbb95629 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1851,7 +1851,7 @@ class TermsizeTests(unittest.TestCase): try: size = os.get_terminal_size() except OSError as e: - if e.errno == errno.EINVAL or sys.platform == "win32": + if sys.platform == "win32" or e.errno in (errno.EINVAL, errno.ENOTTY): # Under win32 a generic OSError can be thrown if the # handle cannot be retrieved self.skipTest("failed to query terminal size") @@ -1873,7 +1873,14 @@ class TermsizeTests(unittest.TestCase): self.skipTest("stty invocation failed") expected = (int(size[1]), int(size[0])) # reversed order - actual = os.get_terminal_size(sys.__stdin__.fileno()) + try: + actual = os.get_terminal_size(sys.__stdin__.fileno()) + except OSError as e: + if sys.platform == "win32" or e.errno in (errno.EINVAL, errno.ENOTTY): + # Under win32 a generic OSError can be thrown if the + # handle cannot be retrieved + self.skipTest("failed to query terminal size") + raise self.assertEqual(expected, actual) -- 2.40.0