Skip to content

Commit

Permalink
tests for remote and repo clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Leah Wasser committed Nov 23, 2021
1 parent ab686ce commit 541f1ef
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion abcclassroom/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def init_and_commit(directory, custom_message=False):
# Running git init on an existing repo is safe, so no need
# to check anything first
git_init(directory)
print("running init", directory)
print("Initializing", directory, "directory for you now.")
_master_branch_to_main(directory)
if repo_changed(directory):
message = "Initial commit"
Expand Down
55 changes: 55 additions & 0 deletions abcclassroom/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ def example_student_repo(tmpdir):
return repo_dir


@pytest.fixture()
def example_student_repo_git(tmpdir, example_student_repo):
"""A fixture with an initialized git repo"""

import contextlib

# Create the repo dir
repo_path = example_student_repo
with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
# This just suppresses print messages so we aren't getting extra
# stdout to weed through
abcgit.init_and_commit(repo_path)
return repo_path


# TODO: add an actual check here for the standard out
def test_check_git_ssh_pass():
"""When ssh is setup correctly, the check should run and pass with no
Expand Down Expand Up @@ -177,6 +192,46 @@ def test_clone_repo_bad_repo(
)


# TODO: I'm not sure there is any point of failure here because this doesn't
# check
# that the remote is valid in the function. is that ok?
def test_add_remote(tmpdir, example_student_repo_git):
"""Function that tests the add remote correctly adds a new remote to a
git repo"""

repo_path = example_student_repo_git
abcgit.add_remote(
directory=repo_path,
organization="demo-org",
remote_repo="student-repo",
)
# Now check that setting the remote worked
ret = abcgit._call_git("remote", "-v", directory=repo_path)
assert ret.stdout.startswith(
"origin\tgit@github.com:demo-org/student-repo.git (fetch)"
)


# Test repo changed
def test_repo_changed(tmpdir, example_student_repo_git):
"""Should return True if the repo is dirty"""
repo_path = example_student_repo_git
# Make that puppy dirty / change stuff
a_file = Path(repo_path, "README.md")
a_file.write_text("Some new text in the readme")
ret = abcgit.repo_changed(directory=repo_path)
assert ret


# TODO this test and the above could be in the same test fun. not sure what
# best practice is here
def test_repo_clean(tmpdir, example_student_repo_git):
"""Should return True if the repo is dirty"""
repo_path = example_student_repo_git
ret = abcgit.repo_changed(directory=repo_path)
assert ret is False


# TODO here we are calling git and it works. This makes me think that call
# git doesn't need to be mocked at all and we can assume that the user has
# git setup.
Expand Down

0 comments on commit 541f1ef

Please sign in to comment.