Exemple #1
0
def test_matcher_matches(settings):
    settings.POOTLE_FS_PATH = "/path/to"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.translation_paths"] = dict(
        default="/some/other/path/<language_code>/<dir_path>/<filename>.<ext>")
    matcher = FSPathMatcher(DummyContext(project))
    finder = matcher.get_finder()
    matches = []
    for file_path, matched in finder.dummy_paths:
        language = matcher.get_language(matched["language_code"])
        matched["language_code"] = language.code
        matches.append((matcher.match_pootle_path(**matched),
                        matcher.relative_path(file_path)))
    assert matches == list(matcher.matches(None, None))
Exemple #2
0
def test_matcher_matches(settings):
    settings.POOTLE_FS_PATH = "/path/to"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.translation_paths"] = dict(
        default="/some/other/path/<language_code>/<dir_path>/<filename>.<ext>"
    )
    matcher = FSPathMatcher(DummyContext(project))
    finder = matcher.get_finder()
    matches = []
    for file_path, matched in finder.dummy_paths:
        language = matcher.get_language(matched["language_code"])
        matched["language_code"] = language.code
        matches.append((matcher.match_pootle_path(**matched), matcher.relative_path(file_path)))
    assert matches == list(matcher.matches(None, None))
Exemple #3
0
def test_matcher_match_pootle_path(settings):
    settings.POOTLE_FS_WORKING_PATH = "/path/to"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.translation_mappings"] = dict(
        default="/path/to/<language_code>/<dir_path>/<filename>.<ext>")
    matcher = FSPathMatcher(DummyContext(project))

    assert matcher.match_pootle_path(language_code="foo") is None
    assert (
        matcher.match_pootle_path(language_code="foo", filename="bar")
        is None)
    assert (
        matcher.match_pootle_path(language_code="foo", ext="baz")
        is None)
    assert (
        matcher.match_pootle_path(
            language_code="foo", filename="bar", ext="baz")
        == "/foo/%s/bar.baz" % project.code)
    assert (
        matcher.match_pootle_path(
            language_code="foo", filename="bar", ext="baz", dir_path="sub/dir")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            language_code="foo", filename="bar", ext="baz", dir_path="sub/dir/")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            language_code="foo", filename="bar", ext="baz", dir_path="/sub/dir")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            pootle_path_match="/foo*",
            language_code="foo", filename="bar", ext="baz", dir_path="/sub/dir")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            pootle_path_match="*sub/dir/*",
            language_code="foo", filename="bar", ext="baz", dir_path="/sub/dir")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            pootle_path_match="*/bar.baz",
            language_code="foo", filename="bar", ext="baz", dir_path="/sub/dir")
        == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (
        matcher.match_pootle_path(
            pootle_path_match="/foo",
            language_code="foo", filename="bar", ext="baz", dir_path="/sub/dir")
        is None)
Exemple #4
0
def test_matcher_match_pootle_path(settings):
    settings.POOTLE_FS_PATH = "/path/to"
    project = Project.objects.get(code="project0")
    project.config["pootle_fs.translation_paths"] = dict(
        default="/path/to/<language_code>/<dir_path>/<filename>.<ext>")
    matcher = FSPathMatcher(DummyContext(project))

    assert matcher.match_pootle_path(language_code="foo") is None
    assert (matcher.match_pootle_path(language_code="foo", filename="bar") is
            None)
    assert (matcher.match_pootle_path(language_code="foo", ext="baz") is None)
    assert (matcher.match_pootle_path(language_code="foo",
                                      filename="bar",
                                      ext="baz") == "/foo/%s/bar.baz" %
            project.code)
    assert (matcher.match_pootle_path(
        language_code="foo", filename="bar", ext="baz",
        dir_path="sub/dir") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(
        language_code="foo", filename="bar", ext="baz",
        dir_path="sub/dir/") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(
        language_code="foo", filename="bar", ext="baz",
        dir_path="/sub/dir") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(
        pootle_path_match="/foo*",
        language_code="foo",
        filename="bar",
        ext="baz",
        dir_path="/sub/dir") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(
        pootle_path_match="*sub/dir/*",
        language_code="foo",
        filename="bar",
        ext="baz",
        dir_path="/sub/dir") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(
        pootle_path_match="*/bar.baz",
        language_code="foo",
        filename="bar",
        ext="baz",
        dir_path="/sub/dir") == u'/foo/%s/sub/dir/bar.baz' % project.code)
    assert (matcher.match_pootle_path(pootle_path_match="/foo",
                                      language_code="foo",
                                      filename="bar",
                                      ext="baz",
                                      dir_path="/sub/dir") is None)