Message11916

Author jeff.allen
Recipients amit, fwierzbicki, jeff.allen, psykiatris, santa4nt, zyasoft
Date 2018-04-19.06:56:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1524121014.86.0.682650639539.issue2363@psf.upfronthosting.co.za>
In-reply-to
Content
This would be better as a distinct test, and maybe in test_file_jy. We always aim *not* to have a special Jython variant of a CPython test (under the same file name). We do here already, but it would be nice not to make it diverge further.

I think that earlier you demonstrated the bug only when the start position of the readline was not the start of the file. Using essentially your code and CPython 2.7.14 I get:

testSeekTell (__main__.AutoFileTests2) ... FAIL

======================================================================
FAIL: testSeekTell (__main__.AutoFileTests2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "dist\Lib\test\test_fileio.py", line 63, in testSeekTell
    self.assertEqual(self.f.tell(), 31)
AssertionError: 10L != 31

The first line of the file is terminated by the \x0a byte, that was inserted by self.f.write(bytes(range(20))). If we keep the file, instead of tidying up, we can see (CPython):

>>> f = open('$test_1_tmp', 'r')
>>> f.readline()
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n'
>>> f.readline()
'\x0b\x0c\r\x0eJython is great\n'
>>> f.close()

I was surprised the \r is not also a line end, but that's a thing you have to ask for explicitly:
>>> f = open('$test_1_tmp', 'rU') # U = universal newlines mode
>>> f.readline()
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n'
>>> f.readline()
'\x0b\x0c\n'
>>> f.readline()
'\x0eJython is great\n'
>>> f.close()

We perhaps have a bone to pick with CPython. Since this byte is at index 10 in the file, and the return from readline includes that byte, I think Jython is correct to return 11 and CPython is off by one!
History
Date User Action Args
2018-04-19 06:56:54jeff.allensetmessageid: <1524121014.86.0.682650639539.issue2363@psf.upfronthosting.co.za>
2018-04-19 06:56:54jeff.allensetrecipients: + jeff.allen, fwierzbicki, zyasoft, santa4nt, amit, psykiatris
2018-04-19 06:56:54jeff.allenlinkissue2363 messages
2018-04-19 06:56:54jeff.allencreate