コード例 #1
0
 def test_write_csv_with_limit(self):
     table = Table([
         ["Alice", 33],
         ["Bob", 44],
         ["Carol", 55],
         ["Dave", 66],
     ], keys=["name", "age"])
     out = StringIO()
     table.write_csv(out, limit=2)
     self.assertEqual(out.getvalue(), u'Alice,33\r\n'
                                      u'Bob,44\r\n')
コード例 #2
0
 def test_write_csv_with_none_in_value(self):
     table = Table([
         ["Alice", 33],
         ["Bob", 44],
         ["Carol", 55],
         ["Dave", None],
     ], keys=["name", "age"])
     out = StringIO()
     table.write_csv(out)
     self.assertEqual(out.getvalue(), u'Alice,33\r\n'
                                      u'Bob,44\r\n'
                                      u'Carol,55\r\n'
                                      u'Dave,\r\n')
コード例 #3
0
 def test_write_csv_with_quotes_in_value(self):
     table = Table([
         ["Alice", 33],
         ["Bob", 44],
         ["Carol", 55],
         ["Dave \"Nordberg\" Smith", 66],
     ], keys=["name", "age"])
     out = StringIO()
     table.write_csv(out)
     self.assertEqual(out.getvalue(), u'Alice,33\r\n'
                                      u'Bob,44\r\n'
                                      u'Carol,55\r\n'
                                      u'"Dave ""Nordberg"" Smith",66\r\n')
コード例 #4
0
 def test_write_csv_with_header_style(self):
     table = Table([
         ["Alice", 33],
         ["Bob", 44],
         ["Carol", 55],
         ["Dave", 66],
     ], keys=["name", "age"])
     out = StringIO()
     table.write_csv(out, header={"fg": "cyan"})
     self.assertEqual(out.getvalue(), u'name,age\r\n'
                                      u'Alice,33\r\n'
                                      u'Bob,44\r\n'
                                      u'Carol,55\r\n'
                                      u'Dave,66\r\n')