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


Python FileViewer.get_syntax方法代码示例

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


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

示例1: TestFileHelper

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

#.........这里部分代码省略.........
        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)
    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')
开发者ID:Alien426,项目名称:addons-server,代码行数:69,代码来源:test_helpers.py


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