本文整理匯總了Python中olympia.files.helpers.FileViewer.read_file方法的典型用法代碼示例。如果您正苦於以下問題:Python FileViewer.read_file方法的具體用法?Python FileViewer.read_file怎麽用?Python FileViewer.read_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類olympia.files.helpers.FileViewer
的用法示例。
在下文中一共展示了FileViewer.read_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestFileHelper
# 需要導入模塊: from olympia.files.helpers import FileViewer [as 別名]
# 或者: from olympia.files.helpers.FileViewer import read_file [as 別名]
#.........這裏部分代碼省略.........
assert not files['install.js']['binary']
assert files['__MACOSX']['directory']
assert not files['__MACOSX']['binary']
def test_url_file(self):
self.viewer.extract()
files = self.viewer.get_files()
url = reverse('files.list', args=[self.viewer.file.id,
'file', 'install.js'])
file_url = files['install.js']['url']
assert file_url == url
assert file_url.startswith('/en-US')
# Make sure that the locale is properly used (see bug 1168794).
with self.activate('fr'):
self.viewer._files = {} # Reset the viewer's internal cache.
files = self.viewer.get_files()
url = reverse('files.list', args=[self.viewer.file.id,
'file', 'install.js'])
file_url = files['install.js']['url']
assert file_url == url
assert file_url.startswith('/fr')
def test_get_files_depth(self):
self.viewer.extract()
files = self.viewer.get_files()
assert files['dictionaries/license.txt']['depth'] == 1
def test_bom(self):
dest = os.path.join(settings.TMP_PATH, 'test_bom')
open(dest, 'w').write('foo'.encode('utf-16'))
self.viewer.select('foo')
self.viewer.selected = {'full': dest, 'size': 1}
assert self.viewer.read_file() == u'foo'
os.remove(dest)
def test_syntax(self):
for filename, syntax in [('foo.rdf', 'xml'),
('foo.xul', 'xml'),
('foo.json', 'js'),
('foo.jsm', 'js'),
('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)