本文整理汇总了Python中fs.tempfs.TempFS.getcontents方法的典型用法代码示例。如果您正苦于以下问题:Python TempFS.getcontents方法的具体用法?Python TempFS.getcontents怎么用?Python TempFS.getcontents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.tempfs.TempFS
的用法示例。
在下文中一共展示了TempFS.getcontents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCSVExport
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import getcontents [as 别名]
class TestCSVExport (TestCase):
def setUp(self):
TestCase.setUp(self)
self.fs = TempFS()
self.exporter = CSVExporter(self.fs, m.HTMLMarkupExporter(self))
def test_single_card(self):
card = m.ContentObject()
card['question'] = u'Question'
card['answer'] = u'Answer'
self.exporter([card])
expected = '"Question","Answer"\r\n'
assert_equals(expected, self.fs.getcontents('index.csv'))
def test_multiple_cards(self):
card = m.ContentObject()
card['question'] = u'Question'
card['answer'] = u'Answer'
card2 = m.ContentObject()
card2['question'] = u'Question 2'
card2['answer'] = u'Answer 2'
self.exporter([card, card2])
expected = '"Question","Answer"\r\n"Question 2","Answer 2"\r\n'
assert_equals(expected, self.fs.getcontents('index.csv'))
def test_multiline_question_and_answer(self):
card = m.ContentObject()
card['question'] = u"Question\nend of question"
card['answer'] = u"Answer\nend of answer"
self.exporter([card])
expected = '"Question\r\nend of question","Answer\r\nend of answer"\r\n'
assert_equals(expected, self.fs.getcontents('index.csv'))
def test_custom_encoding(self):
card = m.ContentObject()
card['question'] = u"chrząszcz brzmi w trzcinie"
card['answer'] = u"zażółć gęślą jaźń"
self.exporter.encoding = 'cp1250'
self.exporter([card])
expected = u'"chrząszcz brzmi w trzcinie","zażółć gęślą jaźń"\r\n'.encode('cp1250')
assert_equals(expected, self.fs.getcontents('index.csv'))
def test_card_with_image(self):
self.images = [m.Image(filename='img2'), m.Image(filename='img1')]
card = m.ContentObject()
card['question'] = u'Question <img src="img2" />'
card['answer'] = u'Answer <img src="img1" />'
self.exporter([card])
expected = '"Question <img src=""images/img2.jpg""/>","Answer <img src=""images/img1.jpg""/>"\r\n'
assert_equals(expected, self.fs.getcontents('index.csv'))
示例2: TestSuperMemoQAExport
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import getcontents [as 别名]
class TestSuperMemoQAExport (TestCase):
def setUp(self):
TestCase.setUp(self)
self.fs = TempFS()
self.exporter = SuperMemoQAExporter(self.fs)
self.exporter.index_file = 'out.txt'
def test_single_card(self):
card = m.ContentObject()
card['question'] = u'Question'
card['answer'] = u'Answer'
self.exporter([card])
expected = "Q: Question\r\nA: Answer\r\n"
assert_equals(expected, self.fs.getcontents('out.txt'))
def test_multiple_cards(self):
card = m.ContentObject()
card['question'] = u'Question'
card['answer'] = u'Answer'
card2 = m.ContentObject()
card2['question'] = u'Question 2'
card2['answer'] = u'Answer 2'
self.exporter([card, card2])
expected = "Q: Question\r\nA: Answer\r\n\r\nQ: Question 2\r\nA: Answer 2\r\n"
assert_equals(expected, self.fs.getcontents('out.txt'))
def test_multiline_question_and_answer(self):
card = m.ContentObject()
card['question'] = u"Question\nend of question"
card['answer'] = u"Answer\nend of answer"
self.exporter([card])
expected = "Q: Question\r\nQ: end of question\r\nA: Answer\r\nA: end of answer\r\n"
assert_equals(expected, self.fs.getcontents('out.txt'))
def test_custom_encoding(self):
card = m.ContentObject()
card['question'] = u"chrząszcz brzmi w trzcinie"
card['answer'] = u"zażółć gęślą jaźń"
self.exporter.encoding = 'cp1250'
self.exporter([card])
expected = u'Q: chrząszcz brzmi w trzcinie\r\nA: zażółć gęślą jaźń\r\n'.encode('cp1250')
assert_equals(expected, self.fs.getcontents('out.txt'))