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


Python TranslationFileFinder.reverse_match方法代码示例

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


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

示例1: test_finder_match_reverse

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_match_reverse():
    finder = TranslationFileFinder("/path/to/<language_code>.<ext>")
    assert finder.reverse_match("foo") == "/path/to/foo.po"

    finder = TranslationFileFinder("/path/to/<language_code>/<filename>.<ext>")
    assert finder.reverse_match("foo") == "/path/to/foo/foo.po"

    finder = TranslationFileFinder("/path/to/<language_code>/<filename>.<ext>")
    assert finder.reverse_match("foo", filename="bar") == "/path/to/foo/bar.po"
开发者ID:arky,项目名称:pootle,代码行数:11,代码来源:finder.py

示例2: test_finder_match_reverse_directory

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_match_reverse_directory():
    finder = TranslationFileFinder("/path/to/<language_code>.<ext>")
    assert finder.reverse_match("foo", dir_path="bar") is None

    finder = TranslationFileFinder(
        "/path/to/<dir_path>/<language_code>.<ext>")
    assert finder.reverse_match("foo") == "/path/to/foo.po"
    assert finder.reverse_match(
        "foo", dir_path="bar") == "/path/to/bar/foo.po"
    assert finder.reverse_match(
        "foo", dir_path="some/other") == "/path/to/some/other/foo.po"
开发者ID:arky,项目名称:pootle,代码行数:13,代码来源:finder.py

示例3: test_finder_match_reverse_ext

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_match_reverse_ext():

    finder = TranslationFileFinder("/path/to/<language_code>.<ext>")

    # ext must be in list of exts
    with pytest.raises(ValueError):
        finder.reverse_match("foo", extension="abc")

    finder = TranslationFileFinder(
        "/foo/bar/<language_code>.<ext>", extensions=["abc", "xyz"])
    assert finder.reverse_match("foo") == "/foo/bar/foo.abc"
    assert finder.reverse_match("foo", extension="abc") == "/foo/bar/foo.abc"
    assert finder.reverse_match("foo", extension="xyz") == "/foo/bar/foo.xyz"
开发者ID:arky,项目名称:pootle,代码行数:15,代码来源:finder.py

示例4: test_finder_exclude_langs

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_exclude_langs():
    finder = TranslationFileFinder(
        "/path/to/<dir_path>/<language_code>.<ext>",
        exclude_languages=["foo", "bar"])
    assert not finder.match("/path/to/foo.po")
    assert not finder.match("/path/to/bar.po")
    match = finder.match("/path/to/baz.po")
    assert match[0] == "/path/to/baz.po"
    assert match[1]["language_code"] == "baz"

    assert not finder.reverse_match(language_code="foo")
    assert not finder.reverse_match(language_code="bar")
    assert (
        finder.reverse_match(language_code="baz")
        == "/path/to/baz.po")
开发者ID:arky,项目名称:pootle,代码行数:17,代码来源:finder.py

示例5: test_finder_match_stores

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_match_stores():
    TRANSLATION_PATH = "/path/to/<dir_path>/<language_code>/<filename>.<ext>"
    finder = TranslationFileFinder(TRANSLATION_PATH)
    stores = Store.objects.all()
    for store in stores:
        kwargs = resolve(store.pootle_path).kwargs
        kwargs["filename"] = os.path.splitext(kwargs["filename"])[0]
        del kwargs["project_code"]
        expected = TRANSLATION_PATH
        for k, v in kwargs.items():
            expected = expected.replace("<%s>" % k, v)
        # clean up if no dir_path
        expected = expected.replace("//", "/")
        expected = expected.replace(
            "<ext>", str(store.filetype.extension))
        assert finder.reverse_match(**kwargs) == expected
        matched = finder.match(expected)
        for k, v in kwargs.items():
            assert matched[1][k] == v.strip("/")
开发者ID:arky,项目名称:pootle,代码行数:21,代码来源:finder.py

示例6: test_finder_match

# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import reverse_match [as 别名]
def test_finder_match(finder_matches):
    dir_path = os.sep.join(['', 'some', 'path'])
    match_path, not_matching, matching = finder_matches
    finder = TranslationFileFinder(os.path.join(dir_path, match_path))

    for path in not_matching:
        assert not finder.match(
            os.path.join(dir_path, path))
    for path, expected in matching:
        match = finder.regex.match(os.path.join(dir_path, path))
        assert match
        named = match.groupdict()
        for k in ["lang", "dir_path", "filename", "ext"]:
            if k in expected:
                assert named[k].strip("/") == expected[k]
            else:
                assert k not in named
        reverse = finder.reverse_match(
            named['language_code'],
            named.get('filename', os.path.splitext(os.path.basename(path))[0]),
            named['ext'],
            dir_path=named.get('dir_path'))

        assert os.path.join(dir_path, path) == reverse
开发者ID:arky,项目名称:pootle,代码行数:26,代码来源:finder.py


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