Skip to content

Commit

Permalink
Add unit test for issue #996
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavid committed Apr 14, 2020
1 parent 3379f61 commit a92a453
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.cache/
/.eggs/
/.envrc
/.tox/
/build/
/dist/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build
.PHONY: build html

build:
python setup.py build_ext --inplace -g
Expand Down
4 changes: 4 additions & 0 deletions pygit2/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def check_error(err, io=False):
if err >= 0:
return

# These are special error codes, they should never reach here
test = err != C.GIT_EUSER and err != C.GIT_PASSTHROUGH
assert test, f'Unexpected error code {err}'

# Error message
giterr = C.git_error_last()
if giterr != ffi.NULL:
Expand Down
11 changes: 11 additions & 0 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,17 @@ def test_clone_with_credentials(self):

assert not repo.is_empty

@unittest.skipIf(utils.no_network(), "Requires network")
def test_clone_bad_credentials(self):
class MyCallbacks(pygit2.RemoteCallbacks):
def credentials(self, url, username, allowed):
raise RuntimeError('Unexpected error')

url = "https://github.com/github/github"
with pytest.raises(RuntimeError) as exc:
clone_repository(url, self._temp_dir, callbacks=MyCallbacks())
assert str(exc.value) == 'Unexpected error'

def test_clone_with_checkout_branch(self):
# create a test case which isolates the remote
test_repo = clone_repository('./test/data/testrepo.git',
Expand Down

0 comments on commit a92a453

Please sign in to comment.