当前位置: 首页>>代码示例>>Python>>正文


Python TempFS.getcontents方法代码示例

本文整理汇总了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'))                  
开发者ID:rblinzler,项目名称:openmemo,代码行数:52,代码来源:test_csv_export.py

示例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'))              
开发者ID:rblinzler,项目名称:openmemo,代码行数:44,代码来源:test_sm_qa_export.py


注:本文中的fs.tempfs.TempFS.getcontents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。