classification
Title: Errors in tests and C implementation of raw FileIO
Type: behavior Stage: test needed
Components: IO, Tests Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, haypo, pakal, pitrou
Priority: normal Keywords:

Created on 2010-01-16 21:46 by pakal, last changed 2010-01-21 01:21 by haypo.

Messages (3)
msg97910 - (view) Author: Pascal Chambon (pakal) Date: 2010-01-16 21:45
My own fileio implementation fails against the latests versions of the io test suite, under python2.6, because these now require FileIO objects to accept unicode strings in their write methods, whereas the doc mentions raw streams only deal with bytes/bytearrays.

Below is the faulty test (unicode literals or ON). The unicode "xxx" is written to the io.FileIO instance, and the stdlib implementation indeed accepts unicode args (in _fileio.c : "if (!PyArg_ParseTuple(args, "s*", &pbuf)...").

In test_io.py :

   def test_destructor(self):
        record = []
        class MyFileIO(io.FileIO):
            def __del__(self):
                record.append(1)
                io.FileIO.__del__(self)
            def close(self):
                record.append(2)
                io.FileIO.close(self)
            def flush(self):
                record.append(3)
                io.FileIO.flush(self)
        f = MyFileIO(test_support.TESTFN, "w")
        f.write("xxx")
        del f
        self.assertEqual(record, [1, 2, 3])
msg97976 - (view) Author: Pascal Chambon (pakal) Date: 2010-01-17 21:28
Hum, it seems that in python2.6, the C API for PyArg_ParseTuple isn't yet ready for bytes and bytearrays, is it ? "y"-like argument parsers don't exist, so I guess we can't easily patch the C api on this, only tests (replacing "xxx" by b"xxx")...
msg98089 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2010-01-21 01:21
IOTest.test_destructor() is already fixed in Python trunk (future 2.7) by r73394 (Issue #6215: backport the 3.1 io lib).

I don't think that it would be possible to backport the 3.1 io lib in Python 2.6. Would it possible to backport only the io tests?
History
Date User Action Args
2010-01-21 01:21:07hayposetnosy: + haypo
messages: + msg98089
2010-01-18 05:33:53ezio.melottisetnosy: + pitrou, benjamin.peterson
2010-01-18 03:35:28brian.curtinsetpriority: normal
type: behavior
components: + Tests
stage: test needed
2010-01-17 21:28:48pakalsetmessages: + msg97976
2010-01-16 21:46:00pakalcreate