本文整理汇总了Python中fs.tempfs.TempFS.setcontents方法的典型用法代码示例。如果您正苦于以下问题:Python TempFS.setcontents方法的具体用法?Python TempFS.setcontents怎么用?Python TempFS.setcontents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.tempfs.TempFS
的用法示例。
在下文中一共展示了TempFS.setcontents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestImporter
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
class TestImporter (TestCase):
def setUp(self):
TestCase.setUp(self)
self.fs = TempFS()
self.importer = Importer()
def test_finds_index_file_in_a_subdirectory(self):
self.fs.makedir("directory")
self.fs.setcontents("directory/file.txt", "test")
index_file = self.importer._find_index_file(self.fs, ["*.txt"])
assert_equals("directory/file.txt", index_file)
示例2: test_remove_all
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
def test_remove_all(self):
"""Test remove_all function"""
fs = TempFS()
fs.setcontents("f1", "file 1")
fs.setcontents("f2", "file 2")
fs.setcontents("f3", "file 3")
fs.makedir("foo/bar", recursive=True)
fs.setcontents("foo/bar/fruit", "apple")
fs.setcontents("foo/baz", "baz")
utils.remove_all(fs, "foo/bar")
self.assert_(not fs.exists("foo/bar/fruit"))
self.assert_(fs.exists("foo/bar"))
self.assert_(fs.exists("foo/baz"))
utils.remove_all(fs, "")
self.assert_(not fs.exists("foo/bar/fruit"))
self.assert_(not fs.exists("foo/bar/baz"))
self.assert_(not fs.exists("foo/baz"))
self.assert_(not fs.exists("foo"))
self.assert_(not fs.exists("f1"))
self.assert_(fs.isdirempty('/'))
示例3: TestCacheFS
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
class TestCacheFS(unittest.TestCase,FSTestCases,ThreadingTestCases):
"""Test simple operation of CacheFS"""
def setUp(self):
self._check_interval = sys.getcheckinterval()
sys.setcheckinterval(10)
self.wrapped_fs = TempFS()
self.fs = CacheFS(self.wrapped_fs,cache_timeout=0.01)
def tearDown(self):
self.fs.close()
sys.setcheckinterval(self._check_interval)
def test_values_are_used_from_cache(self):
old_timeout = self.fs.cache_timeout
self.fs.cache_timeout = None
try:
self.assertFalse(self.fs.isfile("hello"))
self.wrapped_fs.setcontents("hello","world")
self.assertTrue(self.fs.isfile("hello"))
self.wrapped_fs.remove("hello")
self.assertTrue(self.fs.isfile("hello"))
self.fs.clear_cache()
self.assertFalse(self.fs.isfile("hello"))
finally:
self.fs.cache_timeout = old_timeout
def test_values_are_updated_in_cache(self):
old_timeout = self.fs.cache_timeout
self.fs.cache_timeout = None
try:
self.assertFalse(self.fs.isfile("hello"))
self.wrapped_fs.setcontents("hello","world")
self.assertTrue(self.fs.isfile("hello"))
self.wrapped_fs.remove("hello")
self.assertTrue(self.fs.isfile("hello"))
self.wrapped_fs.setcontents("hello","world")
self.assertTrue(self.fs.isfile("hello"))
self.fs.remove("hello")
self.assertFalse(self.fs.isfile("hello"))
finally:
self.fs.cache_timeout = old_timeout
示例4: wrap_error
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
#write(wrap_prefix(prefix[:-1] + ' ') + wrap_error('max recursion levels reached'))
else:
print_dir(fs, pathjoin(path, item), levels[:] + [is_last_item])
else:
write('%s %s' % (wrap_prefix(prefix + char_line), wrap_filename(item)))
return len(dir_listing)
print_dir(fs, path)
return dircount[0], filecount[0]
if __name__ == "__main__":
from fs.tempfs import TempFS
from six import b
t1 = TempFS()
t1.setcontents("foo", b("test"))
t1.makedir("bar")
t1.setcontents("bar/baz", b("another test"))
t1.tree()
t2 = TempFS()
print t2.listdir()
movedir(t1, t2)
print t2.listdir()
t1.tree()
t2.tree()
示例5: wrap_error
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
#write(wrap_prefix(prefix[:-1] + ' ') + wrap_error('max recursion levels reached'))
else:
print_dir(fs, pathjoin(path, item), levels[:] + [is_last_item])
else:
write('%s %s' % (wrap_prefix(prefix + char_line), wrap_filename(item)))
return len(dir_listing)
print_dir(fs, path)
return dircount[0], filecount[0]
if __name__ == "__main__":
from fs.tempfs import TempFS
t1 = TempFS()
t1.setcontents("foo", "test")
t1.makedir("bar")
t1.setcontents("bar/baz", "another test")
t1.tree()
t2 = TempFS()
print t2.listdir()
movedir(t1, t2)
print t2.listdir()
t1.tree()
t2.tree()
示例6: TestSuperMemoQAImport
# 需要导入模块: from fs.tempfs import TempFS [as 别名]
# 或者: from fs.tempfs.TempFS import setcontents [as 别名]
class TestSuperMemoQAImport (TestCase):
def setUp(self):
TestCase.setUp(self)
self.fs = TempFS()
factory = m.ImportedInstanceFactory(self, field_types={
'question': 'html',
'answer': 'html'
})
self.importer = SuperMemoQAImporter(self.fs, factory, m.HTMLMarkupImporter(self))
self.cos = []
self.images = []
self.sounds = []
def test_single_card(self):
data = u"Q: question 1\nA: answer 1"
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(1, len(self.cos))
assert_equals(unicode, type(self.cos[0]['question']))
assert_equals(unicode, type(self.cos[0]['answer']))
assert_equals(u"question 1", self.cos[0]['question'])
assert_equals(u"answer 1", self.cos[0]['answer'])
def test_windows_line_endings(self):
data = u"Q: question 1\r\nA: answer 1"
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(1, len(self.cos))
assert_equals(u"question 1", self.cos[0]['question'])
assert_equals(u"answer 1", self.cos[0]['answer'])
def test_multiple_cards(self):
data = """Q: question
A: answer
Q: question 2
A: answer 2"""
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(2, len(self.cos))
assert_equals(u"question", self.cos[0]['question'])
assert_equals(u"answer", self.cos[0]['answer'])
assert_equals(u"question 2", self.cos[1]['question'])
assert_equals(u"answer 2", self.cos[1]['answer'])
def test_content_is_right_trimmed(self):
data = u"Q: question \nA: answer \n"
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(1, len(self.cos))
assert_equals(u"question", self.cos[0]['question'])
assert_equals(u"answer", self.cos[0]['answer'])
def test_multiline_question_and_answer(self):
data = """Q: question
Q: end of question
A: answer
A: end of answer"""
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(1, len(self.cos))
assert_equals(u"question\nend of question", self.cos[0]['question'])
assert_equals(u"answer\nend of answer", self.cos[0]['answer'])
def test_multiline_question_and_answer_lines_are_rtrimmed(self):
data = "Q: question \nQ: end of question \nA: answer \nA: end of answer "
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(1, len(self.cos))
assert_equals(u"question\nend of question", self.cos[0]['question'])
assert_equals(u"answer\nend of answer", self.cos[0]['answer'])
def test_custom_encoding(self):
data = (u"Q: być szczerym\nA: to be frank").encode('cp1250')
self.fs.setcontents('cards.txt', data)
self.importer.encoding = 'cp1250'
self.importer()
assert_equals(1, len(self.cos))
assert_equals(unicode, type(self.cos[0]['question']))
assert_equals(unicode, type(self.cos[0]['answer']))
assert_equals(u"być szczerym", self.cos[0]['question'])
assert_equals(u"to be frank", self.cos[0]['answer'])
def test_html_tags_are_preserved(self):
data = """Q: hist: When did we <b>land on the moon</b>?
A: 1969 <i>(July 20)</i>"""
self.fs.setcontents('cards.txt', data)
self.importer()
assert_equals(u"hist: When did we <b>land on the moon</b>?", self.cos[0]['question'])
assert_equals(u"1969 <i>(July 20)</i>", self.cos[0]['answer'])
def test_card_with_image(self):
data = u"""Q: <img src="image.jpg" />
A: answer"""
self.fs.setcontents('index.txt', data)
image_data = self.data.getcontents('small.jpg')
self.fs.setcontents('image.jpg', image_data)
self.importer()
#.........这里部分代码省略.........