本文整理汇总了Python中spreadsheetresponsemixin.SpreadsheetResponseMixin.generate_csv方法的典型用法代码示例。如果您正苦于以下问题:Python SpreadsheetResponseMixin.generate_csv方法的具体用法?Python SpreadsheetResponseMixin.generate_csv怎么用?Python SpreadsheetResponseMixin.generate_csv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spreadsheetresponsemixin.SpreadsheetResponseMixin
的用法示例。
在下文中一共展示了SpreadsheetResponseMixin.generate_csv方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GenerateCsvTests
# 需要导入模块: from spreadsheetresponsemixin import SpreadsheetResponseMixin [as 别名]
# 或者: from spreadsheetresponsemixin.SpreadsheetResponseMixin import generate_csv [as 别名]
class GenerateCsvTests(TestCase):
def setUp(self):
self.data = (('row1col1', 'row1col2'), ('row2col1', 'row2col2'))
self.mixin = SpreadsheetResponseMixin()
def test_if_no_file_passed_in_stringio_is_returned(self):
generated_csv = self.mixin.generate_csv(self.data)
assert type(generated_csv) == type(StringIO())
def test_if_file_is_passed_it_is_returned_with_content_added(self):
given_content = mock.MagicMock()
returned_file = self.mixin.generate_csv(self.data, file=given_content)
assert returned_file == given_content
def test_adds_row_of_data(self):
expected_string = \
'row1col1,row1col2\r\nrow2col1,row2col2\r\n'
generated_csv = self.mixin.generate_csv(self.data)
assert generated_csv.getvalue() == expected_string
def test_inserts_headers_if_provided(self):
headers = ('ColA', 'ColB')
expected_string = \
'ColA,ColB\r\nrow1col1,row1col2\r\nrow2col1,row2col2\r\n'
generated_csv = self.mixin.generate_csv(self.data, headers)
assert generated_csv.getvalue() == expected_string
def test_handles_data_with_commas_correctly_by_putting_quotes(self):
data = (('Title is, boo', '2'), )
expected_string = \
'"Title is, boo",2\r\n'
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string
def test_handles_data_with_quotes_correctly(self):
data = (('Title is, "boo"', '2'), )
expected_string = \
'"Title is, ""boo""",2\r\n'
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string
def test_handles_data_in_unicode_correctly(self):
data = ((u'Bumblebee is čmrlj', '2'), )
expected_string = u'Bumblebee is čmrlj,2\r\n'.encode('utf-8')
generated_csv = self.mixin.generate_csv(data)
assert generated_csv.getvalue() == expected_string