[Python-checkins] python/nondist/sandbox/csv/test test_csv.py,1.10,1.11

montanaro@users.sourceforge.net montanaro@users.sourceforge.net
2003年2月03日 09:24:21 -0800


Update of /cvsroot/python/python/nondist/sandbox/csv/test
In directory sc8-pr-cvs1:/tmp/cvs-serv31512
Modified Files:
	test_csv.py 
Log Message:
replicate Excel tests with a dialect using TABs as the delimiter and colons
as the quotechar. All this duplication probably isn't needed. Hopefully it
helps cover a few more lines in _csv.c though.
Index: test_csv.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/csv/test/test_csv.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_csv.py	3 Feb 2003 06:45:59 -0000	1.10
--- test_csv.py	3 Feb 2003 17:24:18 -0000	1.11
***************
*** 112,115 ****
--- 112,212 ----
 self.writerAssertEqual([[1, 2, 'a\nbc', 3, 4]], '1,2,"a\nbc",3,4\r\n')
 
+ class MyWeirdDialect(csv.excel):
+ quotechar = ':'
+ delimiter = '\t'
+ 
+ class TestExcelTabsColons(TestCsvBase):
+ dialect = MyWeirdDialect()
+ 
+ def test_single(self):
+ self.readerAssertEqual('abc', [['abc']])
+ 
+ def test_simple(self):
+ self.readerAssertEqual('1\t2\t3\t4\t5', [['1','2','3','4','5']])
+ 
+ def test_blankline(self):
+ self.readerAssertEqual('', [])
+ 
+ def test_empty_fields(self):
+ self.readerAssertEqual('\t', [['', '']])
+ 
+ def test_singlequoted(self):
+ self.readerAssertEqual('::', [['']])
+ 
+ def test_singlequoted_left_empty(self):
+ self.readerAssertEqual('::\t', [['','']])
+ 
+ def test_singlequoted_right_empty(self):
+ self.readerAssertEqual('\t::', [['','']])
+ 
+ def test_single_quoted_quote(self):
+ self.readerAssertEqual('::::', [[':']])
+ 
+ def test_quoted_quotes(self):
+ self.readerAssertEqual('::::::', [['::']])
+ 
+ def test_inline_quote(self):
+ self.readerAssertEqual('a::b', [['a::b']])
+ 
+ def test_inline_quotes(self):
+ self.readerAssertEqual('a:b:c', [['a:b:c']])
+ 
+ def test_quotes_and_more(self):
+ self.readerAssertEqual(':a:b', [['ab']])
+ 
+ def test_lone_quote(self):
+ self.readerAssertEqual('a:b', [['a:b']])
+ 
+ def test_quote_and_quote(self):
+ self.readerAssertEqual(':a: :b:', [['a :b:']])
+ 
+ def test_space_and_quote(self):
+ self.readerAssertEqual(' :a:', [[' :a:']])
+ 
+ def test_quoted(self):
+ self.readerAssertEqual('1\t2\t3\t:I think,\ttherefore I am:\t5\t6', 
+ [['1', '2', '3', 
+ 'I think,\ttherefore I am', 
+ '5', '6']])
+ 
+ def test_quoted_quote(self):
+ self.readerAssertEqual('1\t2\t3\t:"I see,"\tsaid the blind man:\t:as he picked up his hammer and saw:',
+ [['1', '2', '3', 
+ '"I see,"\tsaid the blind man', 
+ 'as he picked up his hammer and saw']])
+ 
+ def test_quoted_nl(self):
+ input = '''\
+ 1\t2\t3\t:"I see,"
+ \tsaid the blind man:\t:as he picked up his
+ hammer and saw:
+ 9\t8\t7\t6'''
+ self.readerAssertEqual(input,
+ [['1', '2', '3', 
+ '"I see,"\n\tsaid the blind man', 
+ 'as he picked up his\nhammer and saw'],
+ ['9','8','7','6']])
+ 
+ def test_dubious_quote(self):
+ self.readerAssertEqual('12\t12\t1:\t', [['12', '12', '1:', '']])
+ 
+ def test_null(self):
+ self.writerAssertEqual([], '')
+ 
+ def test_single(self):
+ self.writerAssertEqual([['abc']], 'abc\r\n')
+ 
+ def test_simple(self):
+ self.writerAssertEqual([[1, 2, 'abc', 3, 4]], '1\t2\tabc\t3\t4\r\n')
+ 
+ def test_quotes(self):
+ self.writerAssertEqual([[1, 2, 'a:bc:', 3, 4]], '1\t2\t:a::bc:::\t3\t4\r\n')
+ 
+ def test_quote_fieldsep(self):
+ self.writerAssertEqual([['abc\tdef']], ':abc\tdef:\r\n')
+ 
+ def test_newlines(self):
+ self.writerAssertEqual([[1, 2, 'a\nbc', 3, 4]], '1\t2\t:a\nbc:\t3\t4\r\n')
+ 
 class TestDictFields(unittest.TestCase):
 def test_simple_dict(self):

AltStyle によって変換されたページ (->オリジナル) /