classification
Title: test_file.py depends on sys.stdin being unseekable
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: iritkatriel Nosy List: Elena.Oat, ezio.melotti, gregory.p.smith, iritkatriel, lukasz.langa, martin.panter, miss-islington, pitrou, python-dev, vstinner
Priority: normal Keywords: easy, patch

Created on 2012-05-18 18:50 by gregory.p.smith, last changed 2021-08-10 14:47 by lukasz.langa. This issue is now closed.

Files
File name Uploaded Description Edit
14853.diff Elena.Oat, 2013-07-06 16:42 review
test_file.patch vstinner, 2015-01-06 11:43 review
Pull Requests
URL Status Linked Edit
PR 27694 merged iritkatriel, 2021-08-09 21:51
PR 27697 merged miss-islington, 2021-08-09 22:38
PR 27698 merged miss-islington, 2021-08-09 22:38
Messages (12)
msg161073 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2012-05-18 18:50
./python Lib/test/test_file.py    # passes
./python Lib/test/test_file.py </dev/null   # fails
nohup ./python Lib/test/test_file.py   # fails


======================================================================
FAIL: testStdin (__main__.COtherFileTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_file.py", line 160, in testStdin
    self.assertRaises((IOError, ValueError), sys.stdin.seek, -1)
AssertionError: (<type 'exceptions.IOError'>, <type 'exceptions.ValueError'>) not raised

======================================================================
FAIL: testStdin (__main__.PyOtherFileTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "Lib/test/test_file.py", line 160, in testStdin
    self.assertRaises((IOError, ValueError), sys.stdin.seek, -1)
AssertionError: (<type 'exceptions.IOError'>, <type 'exceptions.ValueError'>) not raised


2.7 only; works fine in 3.2.
msg192464 - (view) Author: Elena Oat (Elena.Oat) * Date: 2013-07-06 16:42
testStdin test is useless, it expects that stdin is always unseekable, but since sys.stdin could be any file, i.e. it can be seekable.  

The patch removes the test.
msg192465 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-07-06 16:51
FTR Python 3 raises "io.UnsupportedOperation: underlying stream is not seekable" on unseekable files and "ValueError: negative seek position -1" on seekable ones, whereas Python 2 raises "IOError: [Errno 29] Illegal seek" on unseekable files and doesn't raise anything for seekable ones.
msg193619 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-07-23 21:11
Elena, your patch looks ok to me, thank you.
Could you sign a contributor's agreement? http://www.python.org/psf/contrib/
(or have you already done so?)
msg193683 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-25 03:25
New changeset 17542d36effd by Ezio Melotti in branch '2.7':
#14853: remove test that was making too many assumptions about stdin.  Patch by Elena Oat.
http://hg.python.org/cpython/rev/17542d36effd

New changeset c5d847ee354a by Ezio Melotti in branch '3.3':
#14853: remove test that was making too many assumptions about stdin.  Patch by Elena Oat.
http://hg.python.org/cpython/rev/c5d847ee354a

New changeset 1d0ff57e392e by Ezio Melotti in branch 'default':
#14853: merge with 3.3.
http://hg.python.org/cpython/rev/1d0ff57e392e
msg193684 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-07-25 03:25
Fixed, thanks for the patch!
msg233527 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-01-06 11:43
The same issue was reported for test_file2k: issue #23168.

I modified test_file2k to skip sys.stdin.seek() test if stdin is not a TTY. I prefer to skip a test in a specific case, instead of removing it completly.

I propose to add again the test in test_file, with the skip. See test_file.patch for Python 2.7 (I will addapt it to Python 3 if the patch is accepted for Python 2).
msg273259 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-08-21 02:22
Long story short: Don’t change Python 2, and just restore the seek(-1) test in 3.

I agree in general it is better to skip a test than completely remove it. However, in Python 2, the test that Victor proposes to restore is redundant with test_file2k. Sys.stdin is always a Python-2-style file object, which for some reason or other can allow seek(-1).

Also, this bug was opened for Python 2, with the comment “works fine in 3.2”. I do not understand why the test was removed from Python 3.

For the Python 3 version of the test, the OSF/1 skip should not be necessary. Also, the truncate() test is probably redundant with the test_optional_abilities() method that I added in revision dc9e5f09ac0c (Issue 22854).
msg399294 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-08-09 22:38
New changeset 8ed183391241f0c73e7ba7f42b1d49fc02985f7b by Irit Katriel in branch 'main':
bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694)
https://github.com/python/cpython/commit/8ed183391241f0c73e7ba7f42b1d49fc02985f7b
msg399321 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-10 13:10
New changeset 897c87045c7435254fd330c6ea48204f056e4afc by Miss Islington (bot) in branch '3.9':
bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694) (GH-27698)
https://github.com/python/cpython/commit/897c87045c7435254fd330c6ea48204f056e4afc
msg399330 - (view) Author: miss-islington (miss-islington) Date: 2021-08-10 14:31
New changeset 4e0147ec50aa62315c5a9aa7c88c181f57aadf42 by Miss Islington (bot) in branch '3.10':
bpo-14853: add back the stdin test, skip if stdin is redirected (GH-27694)
https://github.com/python/cpython/commit/4e0147ec50aa62315c5a9aa7c88c181f57aadf42
msg399331 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-08-10 14:47
Thanks, Irit! ✨ 🍰 ✨
History
Date User Action Args
2021-08-10 14:47:45lukasz.langasetstatus: open -> closed
messages: + msg399331

assignee: ezio.melotti -> iritkatriel
resolution: fixed
stage: patch review -> resolved
2021-08-10 14:31:07miss-islingtonsetmessages: + msg399330
2021-08-10 13:10:01lukasz.langasetnosy: + lukasz.langa
messages: + msg399321
2021-08-09 22:38:40miss-islingtonsetpull_requests: + pull_request26184
2021-08-09 22:38:35miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26183
2021-08-09 22:38:29iritkatrielsetmessages: + msg399294
2021-08-09 21:52:38iritkatrielsetversions: + Python 3.9, Python 3.10, Python 3.11, - Python 2.7, Python 3.3, Python 3.4
2021-08-09 21:51:18iritkatrielsetnosy: + iritkatriel
pull_requests: + pull_request26180
2016-08-21 02:22:06martin.pantersetnosy: + martin.panter

messages: + msg273259
stage: resolved -> patch review
2015-01-06 11:43:40vstinnersetfiles: + test_file.patch
2015-01-06 11:43:33vstinnersetstatus: closed -> open

nosy: + vstinner
messages: + msg233527

resolution: fixed -> (no value)
2013-07-25 03:25:51ezio.melottisetstatus: open -> closed
versions: + Python 3.3, Python 3.4
messages: + msg193684

assignee: ezio.melotti
resolution: fixed
stage: patch review -> resolved
2013-07-25 03:25:06python-devsetnosy: + python-dev
messages: + msg193683
2013-07-23 21:11:37pitrousetmessages: + msg193619
2013-07-06 16:51:40ezio.melottisetnosy: + ezio.melotti
messages: + msg192465

components: + Tests
stage: patch review
2013-07-06 16:42:25Elena.Oatsetfiles: + 14853.diff

nosy: + pitrou, Elena.Oat
messages: + msg192464

keywords: + patch
2012-05-18 18:50:06gregory.p.smithcreate