I have a python project that is using GitPython to perform clone and pull functions against a remote Git repository.
As a simple example:
import git
from git import Git
from git import Repo
def clone_and_checkout(self, full_dir, git_url, repo_ver):
repo = Repo.clone_from(
url=git_url,
to_path=full_dir
)
# Set origin and pull
origin = repo.remotes.origin
origin.pull()
# Check out desired version of repository
g = Git(self.fulldir)
g.checkout(repo_ver)
I want to be able to write a unit test for this function, but obviously this needs to reach out to an external system as it stands currently.
I am curious if anyone has experience mocking up this external interaction, in a manner similar to using Mock to mock up HTTP calls. I'd like to be able to perform these tasks in a way that can be mocked at test time without needing to call an actual Git remote.
How should I go about writing tests for this?
Aucun commentaire:
Enregistrer un commentaire