本文整理汇总了Python中pootle_fs.finder.TranslationFileFinder.match方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationFileFinder.match方法的具体用法?Python TranslationFileFinder.match怎么用?Python TranslationFileFinder.match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pootle_fs.finder.TranslationFileFinder
的用法示例。
在下文中一共展示了TranslationFileFinder.match方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finder_filters
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import match [as 别名]
def test_finder_filters():
finder = TranslationFileFinder(
"/path/to/<dir_path>/<language_code>.<ext>",
path_filters=["/path/to/*"])
# doesnt filter anything
assert finder.match("/path/to/any.po")
assert finder.match("/path/to/some/other.po")
assert finder.match("/path/to/and/any/other.po")
finder = TranslationFileFinder(
"/path/to/<dir_path>/<language_code>.<ext>",
path_filters=["/path/to/some/*"])
# these dont match
assert not finder.match("/path/to/any.po")
assert not finder.match("/path/to/and/any/other.po")
# but this does
assert finder.match("/path/to/some/other.po")
# filter_paths are `and` matches
finder = TranslationFileFinder(
"/path/to/<dir_path>/<language_code>.<ext>",
path_filters=["/path/to/this/*", "/path/to/this/other/*"])
# so this doesnt match
assert not finder.match("/path/to/this/file.po")
# but these do
assert finder.match("/path/to/this/other/file.po")
assert finder.match("/path/to/this/other/file2.po")
assert finder.match("/path/to/this/other/in/subdir/file2.po")
示例2: test_finder_exclude_langs
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import 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")
示例3: test_finder_match
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import match [as 别名]
def test_finder_match(finder_matches):
dir_path = "/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.match(os.path.join(dir_path, path))
assert match
named = match.groupdict()
for k in ["lang", "directory_path", "filename", "ext"]:
if k in expected:
assert named[k].strip("/") == expected[k]
else:
assert k not in named
reverse = finder.reverse_match(
named['lang'],
named.get('filename', os.path.splitext(os.path.basename(path))[0]),
named['ext'],
directory_path=named.get('directory_path'))
assert os.path.join(dir_path, path) == reverse
示例4: test_finder_match_stores
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import 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("/")
示例5: test_finder_lang_codes
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import match [as 别名]
def test_finder_lang_codes():
finder = TranslationFileFinder(
"/path/to/<dir_path>/<language_code>.<ext>")
match = finder.match("/path/to/foo/[email protected]")
assert match[1]["language_code"] == "[email protected]"
示例6: test_finder_match_filepath
# 需要导入模块: from pootle_fs.finder import TranslationFileFinder [as 别名]
# 或者: from pootle_fs.finder.TranslationFileFinder import match [as 别名]
def test_finder_match_filepath():
finder = TranslationFileFinder("/path/to/<language_code>.<ext>")
assert finder.match("/foo/baz/lang.po") is None
assert finder.match("/path/to/lang.xliff") is None
assert finder.match("/path/to/lang.po")