[Python-checkins] bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694)

miss-islington webhook-mailer at python.org
Tue Aug 10 10:31:08 EDT 2021


https://github.com/python/cpython/commit/4e0147ec50aa62315c5a9aa7c88c181f57aadf42
commit: 4e0147ec50aa62315c5a9aa7c88c181f57aadf42
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-08-10T07:31:00-07:00
summary:

bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694)

(cherry picked from commit 8ed183391241f0c73e7ba7f42b1d49fc02985f7b)

Co-authored-by: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>

files:
M Lib/test/test_file.py

diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py
index fbfba64759a1e..1ec756f334d28 100644
--- a/Lib/test/test_file.py
+++ b/Lib/test/test_file.py
@@ -154,6 +154,22 @@ def testModeStrings(self):
                 f.close()
                 self.fail('%r is an invalid file mode' % mode)
 
+    def testStdin(self):
+        if sys.platform == 'osf1V5':
+            # This causes the interpreter to exit on OSF1 v5.1.
+            self.skipTest(
+                ' sys.stdin.seek(-1) may crash the interpreter on OSF1.'
+                ' Test manually.')
+
+        if not sys.stdin.isatty():
+            # Issue 14853: stdin becomes seekable when redirected to a file
+            self.skipTest('stdin must be a TTY in this test')
+
+        with self.assertRaises((IOError, ValueError)):
+            sys.stdin.seek(-1)
+        with self.assertRaises((IOError, ValueError)):
+            sys.stdin.truncate()
+
     def testBadModeArgument(self):
         # verify that we get a sensible error message for bad mode argument
         bad_mode = "qwerty"



More information about the Python-checkins mailing list