示例#1
0
    def test_clone_does_not_alter_existing_dirs(self, with_student_repos,
                                                tmpdir):
        """Test that clone does not clobber existing directories."""
        team_with_local_repos = STUDENT_TEAMS[0]
        teams_without_local_repos = STUDENT_TEAMS[1:]

        expected_dir_hashes = []
        for template_repo_name in assignment_names:
            new_dir = plug.fileutils.generate_repo_path(
                str(tmpdir), team_with_local_repos.name, template_repo_name)
            new_dir.mkdir(parents=True)
            new_file = new_dir / "file"
            new_file.write_text(str(new_dir), encoding="utf-8")
            expected_dir_hashes.append((new_dir, hash_directory(new_dir)))
            repobee_testhelpers.funcs.initialize_repo(new_dir)

        command = " ".join([
            *repobee_plug.cli.CoreCommand.repos.clone.as_name_tuple(),
            *BASE_ARGS,
            *MASTER_REPOS_ARG,
            *STUDENTS_ARG,
        ])

        run_repobee(command, workdir=tmpdir, plugins=[_repobee.ext.gitlab])

        assert_cloned_repos(teams_without_local_repos, assignment_names,
                            tmpdir)
        for dirpath, expected_hash in expected_dir_hashes:
            dirhash = hash_directory(dirpath)
            assert dirhash == expected_hash, "hash mismatch for " + dirpath
示例#2
0
def create_local_repo(
    path: pathlib.Path,
    files: Iterable[Tuple[str, str]],
    default_branch: str = "master",
) -> str:
    """Create a local repository in the provided basedir and return a
    hash of the contents.

    Args:
        path: Path to put the repository at. Parent directories are created if
            they don't exist.
        files: Files to add to the repository. Should be tuples on the form
            (relpath, content), where relpath is a filepath relative to the
            root of the repository.
        default_branch: The default branch to use for the repository.
    Returns:
        The sha1 hash of the repository.
    """
    path.mkdir(parents=True)
    for filename, content in files:
        file = path / filename
        file.parent.mkdir(parents=True, exist_ok=True)
        (path / filename).write_text(content, encoding="utf8")
    sha = funcs.hash_directory(path)
    funcs.initialize_repo(path, default_branch)
    return sha
示例#3
0
def assert_cloned_repos(
    student_teams: List[plug.StudentTeam],
    template_repo_names: List[str],
    tmpdir: pathlib.Path,
) -> None:
    """Check that the cloned repos have the expected contents.

    NOTE: Only checks the contents of the root of the project.
    """
    # group by master repo name, all of which have the same length
    root = pathlib.Path(tmpdir).resolve()
    for student_team, template_repo_name in itertools.product(
            student_teams, template_repo_names):
        path = plug.fileutils.generate_repo_path(root, student_team.name,
                                                 template_repo_name)
        expected_sha = templates.TASK_CONTENTS_SHAS[template_repo_name]
        sha = hash_directory(path)
        assert sha == expected_sha
        assert (path / ".git").is_dir()
示例#4
0
"""Constants related to template repos."""
import pathlib

from repobee_testhelpers.funcs import hash_directory

TEMPLATE_REPOS_DIR = pathlib.Path(__file__).parent / "template-repos"
TASK_CONTENTS_SHAS = {
    dir_.name: hash_directory(dir_) for dir_ in TEMPLATE_REPOS_DIR.iterdir()
}
TEMPLATE_REPO_NAMES = tuple(
    template.name
    for template in TEMPLATE_REPOS_DIR.iterdir()
    if template.is_dir()
)