def test_matcher_relative_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.relative_path("/foo/bar") is "/foo/bar" assert ( matcher.relative_path(os.path.join(matcher.root_directory, "foo/bar")) == "/foo/bar") assert ( matcher.relative_path( os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) == os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) assert ( matcher.relative_path( os.path.join( matcher.root_directory, "foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) == os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar"))
def test_matcher_relative_path(settings): settings.POOTLE_FS_WORKING_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.relative_path("/foo/bar") is "/foo/bar" assert ( matcher.relative_path(os.path.join(matcher.root_directory, "foo/bar")) == "/foo/bar") assert ( matcher.relative_path( os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) == os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) assert ( matcher.relative_path( os.path.join( matcher.root_directory, "foo/bar", matcher.root_directory.lstrip("/"), "foo/bar")) == os.path.join( "/foo/bar", matcher.root_directory.lstrip("/"), "foo/bar"))
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))
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))