本文整理汇总了Python中olympia.files.helpers.FileViewer._verify_files方法的典型用法代码示例。如果您正苦于以下问题:Python FileViewer._verify_files方法的具体用法?Python FileViewer._verify_files怎么用?Python FileViewer._verify_files使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类olympia.files.helpers.FileViewer
的用法示例。
在下文中一共展示了FileViewer._verify_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFileViewer
# 需要导入模块: from olympia.files.helpers import FileViewer [as 别名]
# 或者: from olympia.files.helpers.FileViewer import _verify_files [as 别名]
#.........这里部分代码省略.........
('foo.bar', 'plain')]:
assert self.viewer.get_syntax(filename) == syntax
def test_file_order(self):
self.viewer.extract()
dest = self.viewer.dest
open(os.path.join(dest, 'chrome.manifest'), 'w')
subdir = os.path.join(dest, 'chrome')
os.mkdir(subdir)
open(os.path.join(subdir, 'foo'), 'w')
cache.clear()
files = self.viewer.get_files().keys()
rt = files.index(u'chrome')
assert files[rt:rt + 3] == [u'chrome', u'chrome/foo', u'dictionaries']
@patch.object(settings, 'FILE_VIEWER_SIZE_LIMIT', 5)
def test_file_size(self):
self.viewer.extract()
self.viewer.get_files()
self.viewer.select('install.js')
res = self.viewer.read_file()
assert res == ''
assert self.viewer.selected['msg'].startswith('File size is')
@patch.object(settings, 'FILE_VIEWER_SIZE_LIMIT', 5)
def test_file_size_unicode(self):
with self.activate(locale='he'):
self.viewer.extract()
self.viewer.get_files()
self.viewer.select('install.js')
res = self.viewer.read_file()
assert res == ''
assert self.viewer.selected['msg'].startswith('File size is')
@patch.object(settings, 'FILE_UNZIP_SIZE_LIMIT', 5)
def test_contents_size(self):
self.assertRaises(forms.ValidationError, self.viewer.extract)
def test_default(self):
self.viewer.extract()
assert self.viewer.get_default(None) == 'install.rdf'
def test_default_webextension(self):
viewer = FileViewer(make_file(2, get_file('webextension.xpi')))
viewer.extract()
assert viewer.get_default(None) == 'manifest.json'
def test_default_webextension_zip(self):
viewer = FileViewer(make_file(2, get_file('webextension_no_id.zip')))
viewer.extract()
assert viewer.get_default(None) == 'manifest.json'
def test_default_webextension_crx(self):
viewer = FileViewer(make_file(2, get_file('webextension.crx')))
viewer.extract()
assert viewer.get_default(None) == 'manifest.json'
def test_default_package_json(self):
viewer = FileViewer(make_file(3, get_file('new-format-0.0.1.xpi')))
viewer.extract()
assert viewer.get_default(None) == 'package.json'
def test_delete_mid_read(self):
self.viewer.extract()
self.viewer.select('install.js')
os.remove(os.path.join(self.viewer.dest, 'install.js'))
res = self.viewer.read_file()
assert res == ''
assert self.viewer.selected['msg'].startswith('That file no')
@patch('olympia.files.helpers.get_md5')
def test_delete_mid_tree(self, get_md5):
get_md5.side_effect = IOError('ow')
self.viewer.extract()
assert {} == self.viewer.get_files()
@patch('olympia.files.helpers.os.fsync')
def test_verify_files_doesnt_call_fsync_regularly(self, fsync):
self.viewer.extract()
assert not fsync.called
@patch('olympia.files.helpers.os.fsync')
def test_verify_files_calls_fsync_on_differences(self, fsync):
self.viewer.extract()
assert not fsync.called
files_to_verify = get_all_files(self.viewer.dest)
files_to_verify.pop()
with patch('olympia.files.helpers.get_all_files') as get_all_files_mck:
get_all_files_mck.return_value = files_to_verify
with pytest.raises(ValueError):
# We don't put things back into place after fsync
# so a `ValueError` is raised
self.viewer._verify_files(files_to_verify)
assert len(fsync.call_args_list) == len(files_to_verify) + 1