]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694) (GH-27698)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 10 Aug 2021 13:09:42 +0000 (06:09 -0700)
committerGitHub <noreply@github.com>
Tue, 10 Aug 2021 13:09:42 +0000 (15:09 +0200)
(cherry picked from commit 8ed183391241f0c73e7ba7f42b1d49fc02985f7b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Lib/test/test_file.py

index cd642e7aaf8bb8634a14f751c924585369b355bc..6504aa0707053b65db9a85ee6137573cd4c1a9d4 100644 (file)
@@ -153,6 +153,22 @@ class OtherFileTests:
                 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"