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


Python POHandler._get_copyright_from_line方法代码示例

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


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

示例1: TestPOFileCopyright

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import _get_copyright_from_line [as 别名]
class TestPOFileCopyright(FormatsBaseTestCase):
    """Test copyright lines for translators in po files."""

    def setUp(self):
        self.handler = POHandler("test.po")
        self.matched_lines = [
            '# John Doe, 2011.',
            '# John Doe <[email protected]>, 2011.',
            '# John Doe <[email protected]>, 2011, 2012.',
            '# Jogn Doe, 2011',
        ]
        self.unmatched_lines = [
            '#John Doe, 2011',
            '# John <john>, 20123',
            '# Copyright, 2011, John Doe.',
            'asdas, 2011',
        ]
        super(TestPOFileCopyright, self).setUp()

    def test_match_lines(self):
        for line in self.matched_lines:
            m = self.handler._get_copyright_from_line(line)
            self.assertTrue(m is not None)
        for line in self.unmatched_lines:
            m = self.handler._get_copyright_from_line(line)
            self.assertTrue(m is None)

    def test_copyright_on_save(self):
        handler = POHandler(os.path.join(
                os.path.dirname(__file__), 'copyright.po')
        )
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)
        handler.compile()
        self.assertTrue("AB" in handler.compiled_template)

    def test_headers_on_pot(self):
        handler = POHandler(os.path.join(
                os.path.dirname(__file__), 'tests.pot')
        )
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)
        handler.compile()
        self.assertFalse("FIRST AUTHOR" in handler.compiled_template)
        handler.compile_pot()
        self.assertTrue("FIRST AUTHOR" in handler.compiled_template)

    def test_order(self):
        handler = POHandler(os.path.join(
                os.path.dirname(__file__), 'copyright.po')
        )
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)
        cr = Copyright.objects.assign(
            language=self.language_en, resource=self.resource,
            owner='CC', year='2014')
        cr = Copyright.objects.assign(
            language=self.language_en, resource=self.resource,
            owner='ZZ', year='2014')
        cr = Copyright.objects.assign(
            language=self.language_en, resource=self.resource,
            owner='BA', year='2015')
        handler.compile()
        lines_iterator = handler.compiled_template.split("\n")
        for n, line in enumerate(lines_iterator):
            if line == "## Translators:":
                break
        line = lines_iterator[n + 1]
        self.assertTrue('AB' in line)
        line = lines_iterator[n + 3]
        self.assertTrue('BA' in line)
        line = lines_iterator[n + 4]
        self.assertTrue('CC' in line)
        line = lines_iterator[n + 6]
        self.assertTrue('ZZ' in line)
开发者ID:hfeeki,项目名称:transifex,代码行数:83,代码来源:__init__.py


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