classification
Title: test_file.py depends on sys.stdin being unseekable
Type: behavior Stage: patch review
Components: Tests Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: Elena.Oat, ezio.melotti, gregory.p.smith, martin.panter, pitrou, python-dev, vstinner
Priority: normal Keywords: easy, patch

Created on 2012-05-18 18:50 by gregory.p.smith, last changed 2016-08-21 02:22 by martin.panter.

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
Messages (8)
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).
History
Date User Action Args
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 ->
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