mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Add counting of source iterator lines to the reader object - handy for
user error messages (otherwise difficult to do without instrumenting the source).
This commit is contained in:
parent
0f0599ddc1
commit
7f2053eff3
3 changed files with 21 additions and 1 deletions
|
|
@ -242,7 +242,7 @@ class Test_Csv(unittest.TestCase):
|
|||
self._read_test(['1,",3,",5'], [['1', '"', '3', '"', '5']],
|
||||
quoting=csv.QUOTE_NONE, escapechar='\\')
|
||||
# will this fail where locale uses comma for decimals?
|
||||
self._read_test([',3,"5",7.3'], [['', 3, '5', 7.3]],
|
||||
self._read_test([',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]],
|
||||
quoting=csv.QUOTE_NONNUMERIC)
|
||||
self.assertRaises(ValueError, self._read_test,
|
||||
['abc,3'], [[]],
|
||||
|
|
@ -267,6 +267,18 @@ class Test_Csv(unittest.TestCase):
|
|||
finally:
|
||||
csv.field_size_limit(limit)
|
||||
|
||||
def test_read_linenum(self):
|
||||
r = csv.reader(['line,1', 'line,2', 'line,3'])
|
||||
self.assertEqual(r.line_num, 0)
|
||||
r.next()
|
||||
self.assertEqual(r.line_num, 1)
|
||||
r.next()
|
||||
self.assertEqual(r.line_num, 2)
|
||||
r.next()
|
||||
self.assertEqual(r.line_num, 3)
|
||||
self.assertRaises(StopIteration, r.next)
|
||||
self.assertEqual(r.line_num, 3)
|
||||
|
||||
class TestDialectRegistry(unittest.TestCase):
|
||||
def test_registry_badargs(self):
|
||||
self.assertRaises(TypeError, csv.list_dialects, None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue