[Python-checkins] r68557 - in sandbox/trunk/io-c: _textio.c test_io.py

antoine.pitrou python-checkins at python.org
Mon Jan 12 23:06:58 CET 2009


Author: antoine.pitrou
Date: Mon Jan 12 23:06:58 2009
New Revision: 68557

Log:
add tests for TextIOWrapper.__init__



Modified:
   sandbox/trunk/io-c/_textio.c
   sandbox/trunk/io-c/test_io.py

Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c	(original)
+++ sandbox/trunk/io-c/_textio.c	Mon Jan 12 23:06:58 2009
@@ -516,6 +516,12 @@
         return -1;
     }
 
+    Py_CLEAR(self->buffer);
+    Py_CLEAR(self->encoding);
+    Py_CLEAR(self->encoder);
+    Py_CLEAR(self->decoder);
+    Py_CLEAR(self->readnl);
+
     if (encoding == NULL) {
         /* Try os.device_encoding(fileno) */
         PyObject *os = PyImport_ImportModule("os");

Modified: sandbox/trunk/io-c/test_io.py
==============================================================================
--- sandbox/trunk/io-c/test_io.py	(original)
+++ sandbox/trunk/io-c/test_io.py	Mon Jan 12 23:06:58 2009
@@ -1103,6 +1103,18 @@
     def tearDown(self):
         support.unlink(support.TESTFN)
 
+    def testConstructor(self):
+        r = io.BytesIO(b"\xc3\xa9\n\n")
+        b = io.BufferedReader(r, 1000)
+        t = io.TextIOWrapper(b)
+        t.__init__(b, encoding="latin1", newline="\r\n")
+        t.__init__(b, encoding="utf8")
+        self.assertEquals("\xe9\n", t.readline())
+        self.assertRaises(TypeError, t.__init__, b, newline=42)
+        self.assertRaises(ValueError, t.read)
+        self.assertRaises(ValueError, t.__init__, b, newline='xyzzy')
+        self.assertRaises(ValueError, t.read)
+
     def testLineBuffering(self):
         r = io.BytesIO()
         b = io.BufferedWriter(r, 1000)


More information about the Python-checkins mailing list