Ejemplo n.º 1
0
 def test_slash_append_path_with_slash(self):
     """
     If the path passed in already has a slash at the end, no extra slash should be appended, regardless of the
     `append_slash` flag.
     """
     self.assertEqual("some/path/", normalise_path("some/path/", False))
     self.assertEqual("some/path/", normalise_path("some/path/", True))
Ejemplo n.º 2
0
def strip_directory(path: str, directory: str) -> str:
    path = normalise_path(path)
    directory = normalise_path(directory, True)

    if path_is_in_directory(path, directory):
        return path[len(directory):]

    raise ValueError("Path {} is not in directory {}".format(path, directory))
Ejemplo n.º 3
0
def iterate_github_source(directory: str, source: GithubSource,
                          facade: GitHubFacade):
    if normalise_path(source.path, True) == normalise_path(directory, True):
        directory = ""
    elif path_is_in_directory(directory, source.path):
        directory = strip_directory(directory, source.path)
    else:
        raise IncorrectDirectoryException

    try:
        yield from list_linked_source_directory(source, directory, facade)
    except GithubException as e:
        if e.status == 404:
            return DirectoryListEntry(
                directory.split("/")[0], directory,
                DirectoryEntryType.DIRECTORY, source)
        else:
            raise
Ejemplo n.º 4
0
 def test_slash_append_path_without_slash(self):
     """If the path passed in has no slash at the end, add an extra slash based on the `append_slash` flag."""
     self.assertEqual("some/path", normalise_path("some/path", False))
     self.assertEqual("some/path/", normalise_path("some/path", True))
Ejemplo n.º 5
0
 def test_normalise_empty_path(self):
     """Passing in `` should always return '' regardless of `append_slash` flag."""
     self.assertEqual("", normalise_path("", False))
     self.assertEqual("", normalise_path("", True))
Ejemplo n.º 6
0
 def test_normalise_current_directory(self):
     """Passing in `.` should always return '' regardless of `append_slash` flag."""
     self.assertEqual("", normalise_path(".", False))
     self.assertEqual("", normalise_path(".", True))