summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_csv.py
diff options
context:
space:
mode:
authorAndrew McNamara <andrewm@object-craft.com.au>2005-01-12 11:17:16 (GMT)
committerAndrew McNamara <andrewm@object-craft.com.au>2005-01-12 11:17:16 (GMT)
commit7f2053eff3ec1ee9084a3a550ae363a804368322 (patch)
tree8ae5c4d637feab5886fca99be4486653ce4a3b7d /Lib/test/test_csv.py
parent0f0599ddc1ad02f392fe0be58479f34c57a80c8d (diff)
downloadcpython-7f2053eff3ec1ee9084a3a550ae363a804368322.zip
cpython-7f2053eff3ec1ee9084a3a550ae363a804368322.tar.gz
cpython-7f2053eff3ec1ee9084a3a550ae363a804368322.tar.bz2
Add counting of source iterator lines to the reader object - handy for
user error messages (otherwise difficult to do without instrumenting the source).
Diffstat (limited to 'Lib/test/test_csv.py')
-rw-r--r--Lib/test/test_csv.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index d458332..21bd8d7 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -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)