From a92a45365d4c17ae237b9038e163e7fdc1027d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Tue, 14 Apr 2020 17:42:08 +0200 Subject: [PATCH] Add unit test for issue #996 --- .gitignore | 1 + Makefile | 2 +- pygit2/errors.py | 4 ++++ test/test_repository.py | 11 +++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 425ce8968..6e37e8156 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.cache/ /.eggs/ +/.envrc /.tox/ /build/ /dist/ diff --git a/Makefile b/Makefile index b6a6dee4d..50104f2c1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build +.PHONY: build html build: python setup.py build_ext --inplace -g diff --git a/pygit2/errors.py b/pygit2/errors.py index d0f8e378f..f53b7ed9d 100644 --- a/pygit2/errors.py +++ b/pygit2/errors.py @@ -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: diff --git a/test/test_repository.py b/test/test_repository.py index fada7a3f6..54d23a8c9 100644 --- a/test/test_repository.py +++ b/test/test_repository.py @@ -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',