本文整理汇总了Python中files.helpers.FileViewer.is_extracted方法的典型用法代码示例。如果您正苦于以下问题:Python FileViewer.is_extracted方法的具体用法?Python FileViewer.is_extracted怎么用?Python FileViewer.is_extracted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files.helpers.FileViewer
的用法示例。
在下文中一共展示了FileViewer.is_extracted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFileHelper
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import is_extracted [as 别名]
class TestFileHelper(amo.tests.TestCase):
def setUp(self):
self.viewer = FileViewer(make_file(1, get_file('dictionary-test.xpi')))
def tearDown(self):
self.viewer.cleanup()
def test_files_not_extracted(self):
eq_(self.viewer.is_extracted(), False)
def test_files_extracted(self):
self.viewer.extract()
eq_(self.viewer.is_extracted(), True)
def test_recurse_extract(self):
self.viewer.src = get_file('recurse.xpi')
self.viewer.extract()
eq_(self.viewer.is_extracted(), True)
def test_recurse_contents(self):
self.viewer.src = get_file('recurse.xpi')
self.viewer.extract()
files = self.viewer.get_files()
nm = ['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 nm:
eq_(name in files, True, 'File %r not extracted' % name)
def test_cleanup(self):
self.viewer.extract()
self.viewer.cleanup()
eq_(self.viewer.is_extracted(), False)
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
for x, y in (['foo.rdf', 'foo.rdf'],
['somelongfilename.rdf', 'somelongfilenam...rdf'],
[u'unicode삮.txt', u'unicode\uc0ae.txt'],
[u'unicodesomelong삮.txt', u'unicodesomelong...txt'],
['somelongfilename.somelongextension',
'somelongfilenam...somelonge..'],):
eq_(truncate(x), y)
def test_get_files_not_extracted(self):
assert not self.viewer.get_files()
def test_get_files_size(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(len(files), 14)
def test_get_files_directory(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files['install.js']['directory'], False)
eq_(files['install.js']['binary'], False)
eq_(files['__MACOSX']['directory'], True)
eq_(files['__MACOSX']['binary'], False)
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'])
assert files['install.js']['url'].endswith(url)
def test_get_files_depth(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(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'))
#.........这里部分代码省略.........
示例2: TestFileHelper
# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import is_extracted [as 别名]
class TestFileHelper(amo.tests.TestCase):
def setUp(self):
self.viewer = FileViewer(make_file(1, get_file("dictionary-test.xpi")))
def tearDown(self):
self.viewer.cleanup()
def test_files_not_extracted(self):
eq_(self.viewer.is_extracted(), False)
def test_files_extracted(self):
self.viewer.extract()
eq_(self.viewer.is_extracted(), True)
def test_recurse_extract(self):
self.viewer.src = get_file("recurse.xpi")
self.viewer.extract()
eq_(self.viewer.is_extracted(), True)
def test_recurse_contents(self):
self.viewer.src = get_file("recurse.xpi")
self.viewer.extract()
files = self.viewer.get_files()
nm = [
"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 nm:
eq_(name in files, True, "File %r not extracted" % name)
def test_cleanup(self):
self.viewer.extract()
self.viewer.cleanup()
eq_(self.viewer.is_extracted(), False)
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
for x, y in (
["foo.rdf", "foo.rdf"],
["somelongfilename.rdf", "somelongfilenam...rdf"],
[u"unicode삮.txt", u"unicode\uc0ae.txt"],
[u"unicodesomelong삮.txt", u"unicodesomelong...txt"],
["somelongfilename.somelongextension", "somelongfilenam...somelonge.."],
):
eq_(truncate(x), y)
def test_get_files_not_extracted(self):
assert not self.viewer.get_files()
def test_get_files_size(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(len(files), 14)
def test_get_files_directory(self):
self.viewer.extract()
files = self.viewer.get_files()
eq_(files["install.js"]["directory"], False)
eq_(files["install.js"]["binary"], False)
eq_(files["__MACOSX"]["directory"], True)
eq_(files["__MACOSX"]["binary"], False)
def test_url_file(self):
self.viewer.extract()
#.........这里部分代码省略.........