Esempio n. 1
0
 def test_alternate_quotes(self):
     p1 = CsvSingleQuotedProtocol() # old style
     p2 = CsvProtocol(quotechar="'") # new style
     line = "'foo',  'bar',  'baz',  1,  2,  3.333"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p1.read(line), (None, res))
     self.assertEqual(p2.read(line), (None, res))
Esempio n. 2
0
 def test_format_strings(self):
     p = CsvProtocol()
     io = [('Benoit Mandelbrot', u'"Benoit Mandelbrot"'),
           (u'Paul Erdős', u'"Paul Erdős"'), (101, u'101'),
           (2.718281, u'2.718281')]
     for t in io:
         self.assertEqual(p.fmt(t[0]), t[1])
Esempio n. 3
0
 def test_alternate_quotes(self):
     p1 = CsvSingleQuotedProtocol()  # old style
     p2 = CsvProtocol(quotechar="'")  # new style
     line = "'foo',  'bar',  'baz',  1,  2,  3.333"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p1.read(line), (None, res))
     self.assertEqual(p2.read(line), (None, res))
Esempio n. 4
0
 def test_format_strings(self):
     p = CsvProtocol()
     io = [('Benoit Mandelbrot',  u'"Benoit Mandelbrot"'),
           (u'Paul Erdős',  u'"Paul Erdős"'),
           (101,  u'101'),
           (2.718281,  u'2.718281')]
     for t in io:
         self.assertEqual(p.fmt(t[0]), t[1])
Esempio n. 5
0
 def test_alternate_delimiter(self):
     p = CsvProtocol(delimiter='|')
     line = "foo|bar|baz|1|2|3.333\n"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 6
0
 def test_write_line(self):
     p = CsvProtocol()
     data = ['foo', 'bar', 'baz', 1, 2, 3.333]
     res = u"\"foo\",\"bar\",\"baz\",1,2,3.333"
     self.assertEqual(p.write(None, data), res)
Esempio n. 7
0
 def test_trailing_separator(self):
     p = CsvProtocol()
     line = '"foo",  "bar",  "baz",  1,  2,  3.333, '
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333', u'']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 8
0
 def test_read_unicode(self):
     p = CsvProtocol()
     line = '"Paul",  "Erdős",  "foo",  1,  2,  3.333'
     res = [u'Paul', u'Erdős', u'foo', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 9
0
 def test_drop_quotes(self):
     p = CsvProtocol()
     line = "\"foo\",  \"bar\",  \"baz\",  1,  2,  3.333"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 10
0
 def test_read_one_line(self):
     p = CsvProtocol()
     line = "foo,  bar,  baz,  1,  2,  3.333\n"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 11
0
 def test_alternate_delimiter(self):
     p = CsvProtocol(delimiter='|')
     line = "foo|bar|baz|1|2|3.333\n"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 12
0
 def test_write_line(self):
     p = CsvProtocol()
     data = ['foo', 'bar', 'baz',  1,  2,  3.333]
     res = u"\"foo\",\"bar\",\"baz\",1,2,3.333"
     self.assertEqual(p.write(None, data), six.b(res))
Esempio n. 13
0
 def test_trailing_separator(self):
     p = CsvProtocol()
     line = '"foo",  "bar",  "baz",  1,  2,  3.333, '
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333', u'']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 14
0
 def test_read_unicode(self):
     p = CsvProtocol()
     line = '"Paul",  "Erdős",  "foo",  1,  2,  3.333'
     res = [u'Paul', u'Erdős', u'foo', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 15
0
 def test_drop_quotes(self):
     p = CsvProtocol()
     line = "\"foo\",  \"bar\",  \"baz\",  1,  2,  3.333"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))
Esempio n. 16
0
 def test_read_one_line(self):
     p = CsvProtocol()
     line = "foo,  bar,  baz,  1,  2,  3.333\n"
     res = [u'foo', u'bar', u'baz', u'1', u'2', u'3.333']
     self.assertEqual(p.read(line), (None, res))