Skip to content

Commit 00dd78b

Browse files
committed
Fix windows tests
1 parent e2393a5 commit 00dd78b

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

pygit2/errors.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ def check_error(err, io=False):
6464
raise GitError(message)
6565

6666
# Indicate that we want libgit2 to pretend a function was not set
67-
Passthrough = Exception("The function asked for pass-through")
67+
class Passthrough(Exception):
68+
def __init__(self):
69+
super(Passthrough, self).__init__( "The function asked for pass-through")

pygit2/remote.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,9 @@ def _credentials_cb(cred_out, url, username, allowed, data):
278278
try:
279279
ccred = get_credentials(credentials, url, username, allowed)
280280
cred_out[0] = ccred[0]
281-
281+
except Passthrough as e:
282+
return C.GIT_PASSTHROUGH
282283
except Exception as e:
283-
if e is Passthrough:
284-
return C.GIT_PASSTHROUGH
285-
286284
self._stored_exception = e
287285
return C.GIT_EUSER
288286

@@ -308,15 +306,14 @@ def _certificate_cb(cert_i, valid, host, data):
308306
val = certificate_check(None, bool(valid), ffi.string(host))
309307
if not val:
310308
return C.GIT_ECERTIFICATE
309+
except Passthrough as e:
310+
if is_ssh:
311+
return 0
312+
elif valid:
313+
return 0
314+
else:
315+
return C.GIT_ECERTIFICATE
311316
except Exception as e:
312-
if e is Passthrough:
313-
if is_ssh:
314-
return 0
315-
elif valid:
316-
return 0
317-
else:
318-
return C.GIT_ECERTIFICATE
319-
320317
self._stored_exception = e
321318
return C.GIT_EUSER
322319

test/test_remote.py

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import sys
3434
from pygit2 import Oid
3535
from . import utils
36+
import gc
3637

3738
try:
3839
import __pypy__
@@ -238,6 +239,11 @@ def setUp(self):
238239
self.remote = self.clone.create_remote('origin', self.origin.path)
239240

240241
def tearDown(self):
242+
self.origin = None
243+
self.clone = None
244+
self.remote = None
245+
gc.collect()
246+
241247
self.origin_ctxtmgr.__exit__(None, None, None)
242248
self.clone_ctxtmgr.__exit__(None, None, None)
243249

test/test_repository.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141

4242
import six
4343

44+
if six.PY2:
45+
from urllib import pathname2url
46+
47+
if six.PY3:
48+
from urllib.request import pathname2url
49+
4450
# Import from pygit2
4551
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
4652
from pygit2 import init_repository, clone_repository, discover_repository
@@ -192,8 +198,8 @@ def test_hash(self):
192198

193199
def test_hashfile(self):
194200
data = "bazbarfoo"
195-
tempfile_path = tempfile.mkstemp()[1]
196-
with open(tempfile_path, 'w') as fh:
201+
handle, tempfile_path = tempfile.mkstemp()
202+
with os.fdopen(handle, 'w') as fh:
197203
fh.write(data)
198204
hashed_sha1 = hashfile(tempfile_path)
199205
os.unlink(tempfile_path)
@@ -513,7 +519,7 @@ def test_clone_bare_repository(self):
513519
def test_clone_repository_and_remote_callbacks(self):
514520
src_repo_relpath = "./test/data/testrepo.git/"
515521
repo_path = os.path.join(self._temp_dir, "clone-into")
516-
url = 'file://' + os.path.realpath(src_repo_relpath)
522+
url = 'file:' + pathname2url(os.path.realpath(src_repo_relpath))
517523

518524
def create_repository(path, bare):
519525
return init_repository(path, bare)

0 commit comments

Comments
 (0)