本文整理汇总了Python中pootle_fs.finder.TranslationFileFinder类的典型用法代码示例。如果您正苦于以下问题:Python TranslationFileFinder类的具体用法?Python TranslationFileFinder怎么用?Python TranslationFileFinder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TranslationFileFinder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finder_regex
def test_finder_regex(finder_regexes):
dir_path = os.sep.join(['', 'some', 'path'])
translation_mapping = os.path.join(dir_path, finder_regexes)
finder = TranslationFileFinder(translation_mapping)
path = translation_mapping
for k, v in TranslationFileFinder.path_mapping:
path = path.replace(k, v)
path = os.path.splitext(path)
path = "%s%s" % (path[0], finder._ext_re())
assert finder.regex.pattern == "%s$" % path
示例2: test_finder_exclude_langs
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_stores
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("/")
示例4: test_finder_match_reverse
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"
示例5: test_finder_match
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
示例6: test_finder_match_reverse_directory
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"
示例7: test_finder_match_reverse_ext
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"
示例8: test_finder_filters
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")
示例9: test_finder_lang_codes
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]"
示例10: test_finder_match_filepath
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")