summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-10 13:26:04 (GMT)
committerGitHub <noreply@github.com>2024-01-10 13:26:04 (GMT)
commit59a7b9495b64f0be8992564d30217137f0f0a662 (patch)
treeca1be13377b9c4230bb32e8b52e363414d35e8e3 /Lib/test
parent84677ff19c0ffdc328203cdb25d16053e9c5a910 (diff)
downloadcpython-59a7b9495b64f0be8992564d30217137f0f0a662.zip
cpython-59a7b9495b64f0be8992564d30217137f0f0a662.tar.gz
cpython-59a7b9495b64f0be8992564d30217137f0f0a662.tar.bz2
[3.12] gh-70835: Clarify error message for CSV file opened with wrong newline (GH-113786) (GH-113905)
Based on patch by SilentGhost. (cherry picked from commit 568d220993fa9b4b812ff1b425edd80dbe17dda9) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_csv.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index bc9961e..3038369 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -309,13 +309,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', '']])