mirror of https://github.com/python/cpython
gh-70835: Clarify error message for CSV file opened with wrong newline (GH-113786)
Based on patch by SilentGhost.
This commit is contained in:
parent
aef4a1203c
commit
568d220993
|
@ -297,13 +297,18 @@ class Test_Csv(unittest.TestCase):
|
|||
[b'abc'], None)
|
||||
|
||||
def test_read_eol(self):
|
||||
self._read_test(['a,b'], [['a','b']])
|
||||
self._read_test(['a,b\n'], [['a','b']])
|
||||
self._read_test(['a,b\r\n'], [['a','b']])
|
||||
self._read_test(['a,b\r'], [['a','b']])
|
||||
self.assertRaises(csv.Error, self._read_test, ['a,b\rc,d'], [])
|
||||
self.assertRaises(csv.Error, self._read_test, ['a,b\nc,d'], [])
|
||||
self.assertRaises(csv.Error, self._read_test, ['a,b\r\nc,d'], [])
|
||||
self._read_test(['a,b', 'c,d'], [['a','b'], ['c','d']])
|
||||
self._read_test(['a,b\n', 'c,d\n'], [['a','b'], ['c','d']])
|
||||
self._read_test(['a,b\r\n', 'c,d\r\n'], [['a','b'], ['c','d']])
|
||||
self._read_test(['a,b\r', 'c,d\r'], [['a','b'], ['c','d']])
|
||||
|
||||
errmsg = "with newline=''"
|
||||
with self.assertRaisesRegex(csv.Error, errmsg):
|
||||
next(csv.reader(['a,b\rc,d']))
|
||||
with self.assertRaisesRegex(csv.Error, errmsg):
|
||||
next(csv.reader(['a,b\nc,d']))
|
||||
with self.assertRaisesRegex(csv.Error, errmsg):
|
||||
next(csv.reader(['a,b\r\nc,d']))
|
||||
|
||||
def test_read_eof(self):
|
||||
self._read_test(['a,"'], [['a', '']])
|
||||
|
|
|
@ -837,7 +837,8 @@ parse_process_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
|
|||
self->state = START_RECORD;
|
||||
else {
|
||||
PyErr_Format(module_state->error_obj,
|
||||
"new-line character seen in unquoted field - do you need to open the file in universal-newline mode?");
|
||||
"new-line character seen in unquoted field - "
|
||||
"do you need to open the file with newline=''?");
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue