예제 #1
0
def init_source_repo(init_chm_test_session):
    """Sets up and tears down a non-bare git repo.

    Yields:
        tuple: (
            source_workdir_path,
            parent_dir_path,
            commits_from_json,

    """
    parent_dir_path = init_chm_test_session

    # Create source workdir
    source_workdir_path = create_dir(
        full_path=os.path.join(parent_dir_path, SOURCE_WORKDIR),
        on_conflict="replace",
    )

    # Create and initiallize source repo
    repo = Repo.init(source_workdir_path)

    # Make the commits
    commits = make_commits(repo=repo, commits_data=load_commit_data())

    yield (
        source_workdir_path,
        parent_dir_path,
        commits,
    )

    # Delete the source repo directory
    delete_dir(source_workdir_path)
예제 #2
0
 def test_create_resolve_on_conflict(self, init_dummy_dir, mock_dir_ops):
     existing_path, _ = init_dummy_dir
     result_dir = create_dir(existing_path, on_conflict="resolve")
     assert result_dir != existing_path
     assert os.makedirs.called_once_with(result_dir)
     assert re.search(fr"{existing_path}-\d{{14}}", result_dir) is not None
     assert not shutil.rmtree.called
예제 #3
0
def init_chm_test_session():
    """Creates and removes the main directory for the test session."""
    tmp_dir = tempfile.gettempdir()

    # Create the main directory
    parent_dir_path = create_dir(full_path=os.path.join(tmp_dir, PARENT_DIR),
                                 on_conflict="replace")
    yield parent_dir_path

    # Delete the entire main directory
    delete_dir(parent_dir_path)
예제 #4
0
def non_git_repo(init_source_repo):
    """Sets up and tears down a directory that is not a git repo."""
    _, parent_dir, _ = init_source_repo

    # Create
    non_git_dir_path = create_dir(
        full_path=os.path.join(tempfile.gettempdir(), "non-git-repo"),
        on_conflict="replace",
    )

    yield non_git_dir_path

    # Delete the non-git repo
    delete_dir(non_git_dir_path)
예제 #5
0
    def _init_empty_dest_repo(self) -> None:
        """Creates and initializes empty destination repo."""
        logger.debug("Creating new destination directory and repo")

        # Create the destination workdir
        dest_repo_name = f"{self.dest_prefix}-{self.source_repo_name}"
        self.dest_workdir = create_dir(
            full_path=os.path.join(self.parent_dir, dest_repo_name),
            on_conflict="resolve",
        )

        # Get dest repo name (to get modified name, as appropriate)
        self.dest_repo_name = os.path.split(self.dest_workdir)[-1]

        # Initialize empty git repo
        self.dest_repo = Repo.init(self.dest_workdir)
        logger.info(f"Initialized destination repo at {self.dest_workdir}")
예제 #6
0
 def test_create_replace_on_conflict(self, init_dummy_dir, mock_dir_ops):
     existing_path, _ = init_dummy_dir
     result_dir = create_dir(existing_path, on_conflict="replace")
     assert result_dir == existing_path
     assert os.makedirs.called_once_with(existing_path)
     assert shutil.rmtree.called_once_with(existing_path)
예제 #7
0
 def test_create_raise_on_conflict(self, init_dummy_dir, mock_dir_ops):
     existing_path, _ = init_dummy_dir
     with pytest.raises(ValueError):
         create_dir(existing_path)
     assert not os.makedirs.called
     assert not shutil.rmtree.called
예제 #8
0
 def test_create_new_dir(self, init_chm_test_session, mock_dir_ops):
     new_path = os.path.join(init_chm_test_session, "a-very-new-directory")
     result_dir = create_dir(new_path)
     assert result_dir == new_path
     assert os.makedirs.called_once_with(new_path)
     assert not shutil.rmtree.called