当前位置: 首页>>代码示例>>Python>>正文


Python FileViewer.extract方法代码示例

本文整理汇总了Python中files.helpers.FileViewer.extract方法的典型用法代码示例。如果您正苦于以下问题:Python FileViewer.extract方法的具体用法?Python FileViewer.extract怎么用?Python FileViewer.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在files.helpers.FileViewer的用法示例。


在下文中一共展示了FileViewer.extract方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSearchEngineHelper

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class TestSearchEngineHelper(amo.tests.TestCase):
    fixtures = ["base/addon_4594_a9"]

    def setUp(self):
        self.left = File.objects.get(pk=25753)
        self.viewer = FileViewer(self.left)

        if not os.path.exists(os.path.dirname(self.viewer.src)):
            os.makedirs(os.path.dirname(self.viewer.src))
            open(self.viewer.src, "w")

    def tearDown(self):
        self.viewer.cleanup()

    def test_is_search_engine(self):
        assert self.viewer.is_search_engine()

    def test_extract_search_engine(self):
        self.viewer.extract()
        assert os.path.exists(self.viewer.dest)

    def test_default(self):
        self.viewer.extract()
        eq_(self.viewer.get_default(None), "a9.xml")

    def test_default_no_files(self):
        self.viewer.extract()
        os.remove(os.path.join(self.viewer.dest, "a9.xml"))
        eq_(self.viewer.get_default(None), None)
开发者ID:ryandoherty,项目名称:zamboni,代码行数:31,代码来源:test_helpers.py

示例2: TestSearchEngineHelper

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class TestSearchEngineHelper(amo.tests.TestCase):
    fixtures = ['base/addon_4594_a9']

    def setUp(self):
        self.left = File.objects.get(pk=25753)
        self.viewer = FileViewer(self.left)

        if not os.path.exists(os.path.dirname(self.viewer.src)):
            os.makedirs(os.path.dirname(self.viewer.src))
            with storage.open(self.viewer.src, 'w') as f:
                f.write('some data\n')

    def tearDown(self):
        self.viewer.cleanup()

    def test_is_search_engine(self):
        assert self.viewer.is_search_engine()

    def test_extract_search_engine(self):
        self.viewer.extract()
        assert os.path.exists(self.viewer.dest)

    def test_default(self):
        self.viewer.extract()
        eq_(self.viewer.get_default(None), 'a9.xml')

    def test_default_no_files(self):
        self.viewer.extract()
        os.remove(os.path.join(self.viewer.dest, 'a9.xml'))
        eq_(self.viewer.get_default(None), None)
开发者ID:abhiii5459,项目名称:olympia,代码行数:32,代码来源:test_helpers.py

示例3: login_as_editor

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class FilesBase:

    def login_as_editor(self):
        assert self.client.login(username='[email protected]',
                                 password='password')

    def setUp(self):
        self.addon = Addon.objects.get(pk=3615)
        self.dev = self.addon.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.addon.versions.latest()
        self.file = self.version.all_files[0]

        p = [amo.PLATFORM_LINUX.id, amo.PLATFORM_WIN.id, amo.PLATFORM_MAC.id]

        self.file.update(platform=p[0])

        self.files = [self.file,
                      File.objects.create(version=self.version,
                                          platform=p[1],
                                          hash='abc123',
                                          filename='dictionary-test.xpi'),
                      File.objects.create(version=self.version,
                                          platform=p[2],
                                          hash='abc123',
                                          filename='dictionary-test.xpi')]

        self.login_as_editor()

        for file_obj in self.files:
            src = os.path.join(settings.ROOT, dictionary)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file)
        # Setting this to True, so we are delaying the extraction of files,
        # in the tests, the files won't be extracted.
        # Most of these tests extract as needed to.
        Switch.objects.get_or_create(name='delay-file-viewer', active=True)

    def tearDown(self):
        self.file_viewer.cleanup()

    def files_redirect(self, file):
        return reverse('files.redirect', args=[self.file.pk, file])

    def files_serve(self, file):
        return reverse('files.serve', args=[self.file.pk, file])

    def test_view_access_anon(self):
        self.client.logout()
        self.check_urls(403)

    def test_view_access_anon_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()
        self.check_urls(200)

    def test_view_access_editor(self):
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_editor_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_developer(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_reviewed(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()

        for status in amo.UNREVIEWED_STATUSES:
            self.addon.update(status=status)
            self.check_urls(403)

        for status in amo.REVIEWED_STATUSES:
            self.addon.update(status=status)
            self.check_urls(200)

    def test_view_access_developer_view_source(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_another_developer(self):
        self.client.logout()
        assert self.client.login(username=self.regular.email,
#.........这里部分代码省略.........
开发者ID:srachit,项目名称:olympia,代码行数:103,代码来源:test_views.py

示例4: TestFileHelper

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [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'))
#.........这里部分代码省略.........
开发者ID:abhiii5459,项目名称:olympia,代码行数:103,代码来源:test_helpers.py

示例5: FilesBase

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class FilesBase(object):

    def login_as_editor(self):
        assert self.client.login(username='[email protected]',
                                 password='password')

    def setUp(self):
        self.app = Webapp.objects.get(pk=337141)
        self.app.update(is_packaged=True, status=amo.WEBAPPS_UNREVIEWED_STATUS)
        self.dev = self.app.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.app.versions.latest()
        self.file = self.version.all_files[0]

        self.versions = [self.version,
                         self.app.versions.create(
                             version='%s.1' % self.version.version)]

        self.files = [self.file,
                      File.objects.create(version=self.versions[1],
                                          filename='webapp.zip')]

        self.login_as_editor()

        for file_obj in self.files:
            src = os.path.join(settings.ROOT, packaged_app)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file, is_webapp=True)
        # Setting this to True, so we are delaying the extraction of files,
        # in the tests, the files won't be extracted.
        # Most of these tests extract as needed to.
        self.create_switch(name='delay-file-viewer')

    def tearDown(self):
        self.file_viewer.cleanup()

    def files_redirect(self, file):
        return reverse('mkt.files.redirect', args=[self.file.pk, file])

    def files_serve(self, file):
        return reverse('mkt.files.serve', args=[self.file.pk, file])

    def test_view_access_anon(self):
        self.client.logout()
        self.check_urls(403)

    def test_view_access_anon_view_unreviewed_source(self):
        self.app.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()
        self.check_urls(403)

    def test_view_access_anon_view_source(self):
        self.app.update(view_source=True, status=amo.STATUS_PUBLIC)
        self.file_viewer.extract()
        self.client.logout()
        self.check_urls(200)

    def test_view_access_editor(self):
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_editor_view_source(self):
        self.app.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_developer(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_reviewed(self):
        self.app.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()

        for status in amo.UNREVIEWED_STATUSES:
            self.app.update(status=status)
            self.check_urls(403)

        for status in amo.REVIEWED_STATUSES:
            self.app.update(status=status)
            self.check_urls(200)

    def test_view_access_developer_view_source(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.app.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_another_developer(self):
        self.client.logout()
#.........这里部分代码省略.........
开发者ID:KryDos,项目名称:zamboni,代码行数:103,代码来源:test_views.py

示例6: TestFileHelper

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class TestFileHelper(test_utils.TestCase):

    def setUp(self):
        dictionary = 'apps/files/fixtures/files/dictionary-test.xpi'
        src = os.path.join(settings.ROOT, dictionary)

        file_obj = Mock()
        file_obj.id = file_obj.pk = 1
        file_obj.file_path = src

        self.viewer = FileViewer(file_obj)

        self.old_tmp = settings.TMP_PATH
        settings.TMP_PATH = tempfile.mkdtemp()

    def tearDown(self):
        self.viewer.cleanup()
        settings.TMP_PATH = self.old_tmp

    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_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.properties']:
            m, encoding = mimetypes.guess_type(f)
            assert not binary(m, f), '%s should not be binary' % f

        for f in ['foo.dtd', 'foo.xul', 'foo.properties']:
            m, encoding = mimetypes.guess_type(f)
            assert not binary(None, f), '%s should not be binary' % f

        for f in ['foo.png', 'foo.gif', 'foo.xls', 'foo.dic']:
            m, encoding = mimetypes.guess_type(f)
            assert binary(m, f), '%s should be binary' % f

    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'], True)

    def test_url_file(self):
        self.viewer.extract()
        files = self.viewer.get_files()
        url = reverse('files.list', args=[self.viewer.file.id,
                                           '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)
        eq_(files['dictionaries/license.txt']['parent'], 'dictionaries')
开发者ID:LittleForker,项目名称:zamboni,代码行数:77,代码来源:test_helpers.py

示例7: test_default_package_json

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
 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'
开发者ID:peterkinalex,项目名称:olympia,代码行数:6,代码来源:test_helpers.py

示例8: test_default_webextension

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
 def test_default_webextension(self):
     viewer = FileViewer(make_file(2, get_file('webextension.xpi')))
     viewer.extract()
     assert viewer.get_default(None) == 'manifest.json'
开发者ID:peterkinalex,项目名称:olympia,代码行数:6,代码来源:test_helpers.py

示例9: login_as_editor

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class FilesBase:

    def login_as_editor(self):
        assert self.client.login(username='[email protected]',
                                 password='password')

    def setUp(self):
        self.addon = Addon.objects.get(pk=3615)
        self.dev = self.addon.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.addon.versions.latest()
        self.file = self.version.all_files[0]

        self.file_two = File()
        self.file_two.version = self.version
        self.file_two.filename = 'dictionary-test.xpi'
        self.file_two.save()

        self.login_as_editor()

        self.old_tmp = settings.TMP_PATH
        self.old_addon = settings.ADDONS_PATH
        settings.TMP_PATH = tempfile.mkdtemp()
        settings.ADDONS_PATH = tempfile.mkdtemp()

        for file_obj in [self.file, self.file_two]:
            src = os.path.join(settings.ROOT, dictionary)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file)
        # Setting this to True, so we are delaying the extraction of files,
        # in the tests, the files won't be extracted.
        # Most of these tests extract as needed to.
        Switch.objects.create(name='delay-file-viewer', active=True)

    def tearDown(self):
        self.file_viewer.cleanup()
        settings.TMP_PATH = self.old_tmp
        settings.ADDONS_PATH = self.old_addon

    def files_redirect(self, file):
        return reverse('files.redirect', args=[self.file.pk, file])

    def files_serve(self, file):
        return reverse('files.serve', args=[self.file.pk, file])

    def test_view_access_anon(self):
        self.client.logout()
        self.check_urls(403)

    def test_view_access_anon_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()
        self.check_urls(200)

    def test_view_access_editor(self):
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_editor_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_developer(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_reviewed(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()

        for status in amo.UNREVIEWED_STATUSES:
            self.addon.update(status=status)
            self.check_urls(403)

        for status in amo.REVIEWED_STATUSES:
            self.addon.update(status=status)
            self.check_urls(200)

    def test_view_access_developer_view_source(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_another_developer(self):
        self.client.logout()
        assert self.client.login(username=self.regular.email,
                                 password='password')
        self.file_viewer.extract()
#.........这里部分代码省略.........
开发者ID:AutomatedTester,项目名称:zamboni,代码行数:103,代码来源:test_views.py

示例10: login_as_editor

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [as 别名]
class FilesBase:

    def login_as_editor(self):
        assert self.client.login(username='[email protected]',
                                 password='password')

    def setUp(self):
        self.addon = Addon.objects.get(pk=3615)
        self.dev = self.addon.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.addon.versions.latest()
        self.file = self.version.all_files[0]

        self.file_two = File()
        self.file_two.version = self.version
        self.file_two.filename = 'dictionary-test.xpi'
        self.file_two.save()

        self.login_as_editor()

        self.old_tmp = settings.TMP_PATH
        self.old_addon = settings.ADDONS_PATH
        settings.TMP_PATH = tempfile.mkdtemp()
        settings.ADDONS_PATH = tempfile.mkdtemp()

        dictionary = 'apps/files/fixtures/files/dictionary-test.xpi'
        for file_obj in [self.file, self.file_two]:
            src = os.path.join(settings.ROOT, dictionary)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file)

    def tearDown(self):
        self.file_viewer.cleanup()
        settings.TMP_PATH = self.old_tmp
        settings.ADDONS_PATH = self.old_addon

    def test_view_access_anon(self):
        self.client.logout()
        self.check_urls(403)

    def test_view_access_anon_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.client.logout()
        self.check_urls(200)

    def test_view_access_editor(self):
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_editor_view_source(self):
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_developer(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_developer_view_source(self):
        self.client.logout()
        assert self.client.login(username=self.dev.email, password='password')
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_view_access_another_developer(self):
        self.client.logout()
        assert self.client.login(username=self.regular.email,
                                 password='password')
        self.file_viewer.extract()
        self.check_urls(403)

    def test_view_access_another_developer_view_source(self):
        self.client.logout()
        assert self.client.login(username=self.regular.email,
                                 password='password')
        self.addon.update(view_source=True)
        self.file_viewer.extract()
        self.check_urls(200)

    def test_poll_extracted(self):
        self.file_viewer.extract()
        res = self.client.get(self.poll_url())
        eq_(res.status_code, 200)
        eq_(json.loads(res.content)['status'], True)

    def test_poll_not_extracted(self):
        res = self.client.get(self.poll_url())
        eq_(res.status_code, 200)
        eq_(json.loads(res.content)['status'], False)

    def test_poll_extracted_anon(self):
#.........这里部分代码省略.........
开发者ID:LittleForker,项目名称:zamboni,代码行数:103,代码来源:test_views.py

示例11: TestFileHelper

# 需要导入模块: from files.helpers import FileViewer [as 别名]
# 或者: from files.helpers.FileViewer import extract [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()
#.........这里部分代码省略.........
开发者ID:ryandoherty,项目名称:zamboni,代码行数:103,代码来源:test_helpers.py


注:本文中的files.helpers.FileViewer.extract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。