[Python-checkins] python/nondist/sandbox/csv/test test_csv.py,1.1,1.2
andrewmcnamara@users.sourceforge.net
andrewmcnamara@users.sourceforge.net
Thu, 30 Jan 2003 20:53:51 -0800
Update of /cvsroot/python/python/nondist/sandbox/csv/test
In directory sc8-pr-cvs1:/tmp/cvs-serv889
Modified Files:
test_csv.py
Log Message:
Added some "writer" tests.
Index: test_csv.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/csv/test/test_csv.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** test_csv.py 31 Jan 2003 04:08:18 -0000 1.1
--- test_csv.py 31 Jan 2003 04:53:49 -0000 1.2
***************
*** 13,16 ****
--- 13,22 ----
self.assertEqual(fields, expected_result)
+ def writerAssertEqual(self, input, expected_result):
+ fileobj = StringIO()
+ writer = csv.writer(fileobj, dialect = self.dialect)
+ writer.writelines(input)
+ self.assertEqual(fileobj.getvalue(), expected_result)
+
class TestDialectExcel(TestCsvBase):
dialect = 'excel'
***************
*** 63,75 ****
def test_quoted(self):
self.readerAssertEqual('1,2,3,"I think, therefore I am",5,6',
! [['1', '2', '3',
! 'I think, therefore I am',
! '5', '6']])
def test_quoted_quote(self):
self.readerAssertEqual('1,2,3,"""I see,"" said the blind man","as he picked up his hammer and saw"',
! [['1', '2', '3',
! '"I see," said the blind man',
! 'as he picked up his hammer and saw']])
def test_quoted_nl(self):
--- 69,81 ----
def test_quoted(self):
self.readerAssertEqual('1,2,3,"I think, therefore I am",5,6',
! [['1', '2', '3',
! 'I think, therefore I am',
! '5', '6']])
def test_quoted_quote(self):
self.readerAssertEqual('1,2,3,"""I see,"" said the blind man","as he picked up his hammer and saw"',
! [['1', '2', '3',
! '"I see," said the blind man',
! 'as he picked up his hammer and saw']])
def test_quoted_nl(self):
***************
*** 80,90 ****
9,8,7,6'''
self.readerAssertEqual(input,
! [['1', '2', '3',
! '"I see,"\nsaid the blind man',
! 'as he picked up his\nhammer and saw'],
! ['9','8','7','6']])
def test_dubious_quote(self):
self.readerAssertEqual('12,12,1",', [['12', '12', '1"', '']])
def _testclasses():
--- 86,114 ----
9,8,7,6'''
self.readerAssertEqual(input,
! [['1', '2', '3',
! '"I see,"\nsaid the blind man',
! 'as he picked up his\nhammer and saw'],
! ['9','8','7','6']])
def test_dubious_quote(self):
self.readerAssertEqual('12,12,1",', [['12', '12', '1"', '']])
+
+ def test_null(self):
+ self.writerAssertEqual([], '')
+
+ def test_single(self):
+ self.writerAssertEqual([['abc']], 'abc\n')
+
+ def test_simple(self):
+ self.writerAssertEqual([[1, 2, 'abc', 3, 4]], '1,2,abc,3,4\n')
+
+ def test_quotes(self):
+ self.writerAssertEqual([[1, 2, 'a"bc"', 3, 4]], '1,2,"a""bc""",3,4\n')
+
+ def test_quote_fieldsep(self):
+ self.writerAssertEqual([['abc,def']], '"abc,def"\n')
+
+ def test_newlines(self):
+ self.writerAssertEqual([[1, 2, 'a\nbc', 3, 4]], '1,2,"a\nbc",3,4\n')
def _testclasses():