diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2007-11-19 21:20:21 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2007-11-19 21:20:21 (GMT) |
commit | 10c476db2ca3052d537553c38881e5ceefdab9df (patch) | |
tree | f6f7bce0ab1bb637a34b103d0f0c68fe46bc2e94 | |
parent | a2d1d7e3b23f6fef0651df1b8fd697aa15ae97c0 (diff) | |
download | cpython-10c476db2ca3052d537553c38881e5ceefdab9df.zip cpython-10c476db2ca3052d537553c38881e5ceefdab9df.tar.gz cpython-10c476db2ca3052d537553c38881e5ceefdab9df.tar.bz2 |
Correct test_cvs on Windows, as suggested by Raghuram Devarakonda
in issue1395. All other places in this file already use newline=''...
Also check that csv.reader is given an iterable returning strings.
-rw-r--r-- | Lib/test/test_csv.py | 8 | ||||
-rw-r--r-- | Modules/_csv.c | 12 |
2 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 6c1c542..f53c5ea 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -6,7 +6,7 @@ import io import sys import os import unittest -from io import StringIO +from io import StringIO, BytesIO from tempfile import TemporaryFile import csv import gc @@ -211,6 +211,10 @@ class Test_Csv(unittest.TestCase): ['ab\0c'], None, strict = 1) self._read_test(['"ab"c'], [['abc']], doublequote = 0) + self.assertRaises(csv.Error, self._read_test, + [b'ab\0c'], None) + + def test_read_eol(self): self._read_test(['a,b'], [['a','b']]) self._read_test(['a,b\n'], [['a','b']]) @@ -375,7 +379,7 @@ class TestDialectRegistry(unittest.TestCase): class TestCsvBase(unittest.TestCase): def readerAssertEqual(self, input, expected_result): - with TemporaryFile("w+") as fileobj: + with TemporaryFile("w+", newline='') as fileobj: fileobj.write(input) fileobj.seek(0) reader = csv.reader(fileobj, dialect = self.dialect) diff --git a/Modules/_csv.c b/Modules/_csv.c index 10cf96f..75cafb2 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -270,7 +270,7 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt) *target = NULL; else if (!IS_BASESTRING(src)) { PyErr_Format(PyExc_TypeError, - "\"%s\" must be an string", name); + "\"%s\" must be a string", name); return -1; } else { @@ -793,6 +793,16 @@ Reader_iternext(ReaderObj *self) "newline inside string"); return NULL; } + if (!PyUnicode_Check(lineobj)) + { + PyErr_Format(error_obj, + "Iterator should return strings, " + "not %.200s " + "(did you open the file in text mode?)", + lineobj->ob_type->tp_name + ); + return NULL; + } ++self->line_num; line = PyUnicode_AsUnicode(lineobj); linelen = PyUnicode_GetSize(lineobj); |