本文整理汇总了Python中olympia.files.helpers.FileViewer._cache_key方法的典型用法代码示例。如果您正苦于以下问题:Python FileViewer._cache_key方法的具体用法?Python FileViewer._cache_key怎么用?Python FileViewer._cache_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olympia.files.helpers.FileViewer
的用法示例。
在下文中一共展示了FileViewer._cache_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFileViewer
# 需要导入模块: from olympia.files.helpers import FileViewer [as 别名]
# 或者: from olympia.files.helpers.FileViewer import _cache_key [as 别名]
class TestFileViewer(TestCase):
def setUp(self):
super(TestFileViewer, self).setUp()
self.viewer = FileViewer(make_file(1, get_file('dictionary-test.xpi')))
def tearDown(self):
self.viewer.cleanup()
super(TestFileViewer, self).tearDown()
def test_files_not_extracted(self):
assert not self.viewer.is_extracted()
def test_files_extracted(self):
self.viewer.extract()
assert self.viewer.is_extracted()
def test_recurse_extract(self):
self.viewer.src = get_file('recurse.xpi')
self.viewer.extract()
assert self.viewer.is_extracted()
def test_recurse_contents(self):
self.viewer.src = get_file('recurse.xpi')
self.viewer.extract()
files = self.viewer.get_files()
file_list = [
'recurse/recurse.xpi/chrome/test-root.txt',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar/test'
]
for name in file_list:
assert name in files
def test_recurse_contents_of_zip(self):
self.viewer.src = get_file('recurse.zip')
self.viewer.extract()
files = self.viewer.get_files()
file_list = [
'recurse/recurse.xpi/chrome/test-root.txt',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar',
'recurse/somejar.jar/recurse/recurse.xpi/chrome/test.jar/test'
]
for name in file_list:
assert name in files
def test_locked(self):
self.viewer.src = get_file('dictionary-test.xpi')
# Lock was successfully attained
assert self.viewer.extract()
msg = Message(self.viewer._cache_key(LOCKED))
msg.save(True)
# Not extracting, the viewer is locked, lock could not be attained
assert not self.viewer.extract()
def test_extract_file_locked_message(self):
self.viewer.src = get_file('dictionary-test.xpi')
assert not self.viewer.is_extracted()
msg = Message(self.viewer._cache_key(LOCKED))
msg.save(True)
msg = extract_file(self.viewer)
assert str(msg.get()).startswith(u'File viewer is locked')
msg.delete()
def test_cleanup(self):
self.viewer.extract()
self.viewer.cleanup()
assert not self.viewer.is_extracted()
def test_isbinary(self):
binary = self.viewer._is_binary
for f in ['foo.rdf', 'foo.xml', 'foo.js', 'foo.py'
'foo.html', 'foo.txt', 'foo.dtd', 'foo.xul', 'foo.sh',
'foo.properties', 'foo.json', 'foo.src', 'CHANGELOG']:
m, encoding = mimetypes.guess_type(f)
assert not binary(m, f), '%s should not be binary' % f
for f in ['foo.png', 'foo.gif', 'foo.exe', 'foo.swf']:
m, encoding = mimetypes.guess_type(f)
assert binary(m, f), '%s should be binary' % f
filename = os.path.join(settings.TMP_PATH, 'test_isbinary')
for txt in ['#!/usr/bin/python', '#python', u'\0x2']:
open(filename, 'w').write(txt)
m, encoding = mimetypes.guess_type(filename)
assert not binary(m, filename), '%s should not be binary' % txt
for txt in ['MZ']:
open(filename, 'w').write(txt)
m, encoding = mimetypes.guess_type(filename)
assert binary(m, filename), '%s should be binary' % txt
os.remove(filename)
def test_truncate(self):
truncate = self.viewer.truncate
#.........这里部分代码省略.........