Skip to content

Commit 3ddb49b

Browse files
committed
Moving to pytest (wip)
1 parent febe630 commit 3ddb49b

12 files changed

+51
-65
lines changed

test/test_attributes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# Boston, MA 02110-1301, USA.
2525

2626
# Standard Library
27-
import unittest
2827
from os.path import join
2928
from pathlib import Path
3029

@@ -52,7 +51,7 @@ def test_no_attr(self):
5251
assert not self.repo.get_attr('file.jpg', 'text')
5352
assert "lf" == self.repo.get_attr('file.sh', 'eol')
5453

55-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
54+
@utils.fspath
5655
def test_no_attr_aspath(self):
5756
with open(join(self.repo.workdir, '.gitattributes'), 'w+') as f:
5857
print('*.py text\n', file=f)

test/test_blob.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"""Tests for Blob objects."""
2727

2828
import io
29-
import unittest
3029
from pathlib import Path
3130

3231
import pytest
@@ -128,7 +127,7 @@ def test_create_blob_fromworkdir(self):
128127
assert len(BLOB_FILE_CONTENT) == blob.size
129128
assert BLOB_FILE_CONTENT == blob.read_raw()
130129

131-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
130+
@utils.fspath
132131
def test_create_blob_fromworkdir_aspath(self):
133132

134133
blob_oid = self.repo.create_blob_fromworkdir(Path("bye.txt"))

test/test_commit.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,20 @@
2525

2626
"""Tests for Commit objects."""
2727

28-
import unittest
2928
import sys
3029

3130
import pytest
3231

3332
from pygit2 import GIT_OBJ_COMMIT, Signature, Oid
3433
from . import utils
3534

36-
# pypy (in python2 mode) raises TypeError on writing to read-only, so
37-
# we need to check and change the test accordingly
38-
try:
39-
import __pypy__
40-
except ImportError:
41-
__pypy__ = None
42-
4335

4436
COMMIT_SHA = '5fe808e8953c12735680c257f56600cb0de44b10'
4537

4638

4739
class CommitTest(utils.BareRepoTestCase):
4840

49-
@unittest.skipIf(__pypy__ is not None, "skip refcounts checks in pypy")
41+
@utils.refcount
5042
def test_commit_refcount(self):
5143
commit = self.repo[COMMIT_SHA]
5244
start = sys.getrefcount(commit)

test/test_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# Boston, MA 02110-1301, USA.
2525

2626
import os
27-
import unittest
2827
from pathlib import Path
2928

3029
import pytest
@@ -91,7 +90,7 @@ def test_add(self):
9190
assert 'something.other.here' in config
9291
assert not config.get_bool('something.other.here')
9392

94-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
93+
@utils.fspath
9594
def test_add_aspath(self):
9695
config = Config()
9796

test/test_credentials.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
"""Tests for credentials"""
2727

28-
import unittest
2928
from pathlib import Path
3029

3130
import pytest
@@ -67,7 +66,7 @@ def test_ssh_key():
6766
cred = Keypair(username, pubkey, privkey, passphrase)
6867
assert (username, pubkey, privkey, passphrase) == cred.credential_tuple
6968

70-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
69+
@utils.fspath
7170
def test_ssh_key_aspath():
7271
username = "git"
7372
pubkey = Path("id_rsa.pub")
@@ -105,7 +104,7 @@ def credentials(self, url, username, allowed):
105104
remote = self.repo.remotes.create("github", url)
106105
with pytest.raises(Exception): remote.fetch(callbacks=MyCallbacks())
107106

108-
@unittest.skipIf(utils.no_network(), "Requires network")
107+
@utils.network
109108
def test_bad_cred_type(self):
110109
class MyCallbacks(pygit2.RemoteCallbacks):
111110
def credentials(self, url, username, allowed):
@@ -116,7 +115,7 @@ def credentials(self, url, username, allowed):
116115
remote = self.repo.remotes.create("github", url)
117116
with pytest.raises(TypeError): remote.fetch(callbacks=MyCallbacks())
118117

119-
@unittest.skipIf(utils.no_network(), "Requires network")
118+
@utils.network
120119
def test_fetch_certificate_check(self):
121120
class MyCallbacks(pygit2.RemoteCallbacks):
122121
def certificate_check(self, certificate, valid, host):
@@ -142,7 +141,7 @@ def certificate_check(self, certificate, valid, host):
142141

143142
class CallableCredentialTest(utils.RepoTestCase):
144143

145-
@unittest.skipIf(utils.no_network(), "Requires network")
144+
@utils.network
146145
def test_user_pass(self):
147146
credentials = UserPass("libgit2", "libgit2")
148147
callbacks = pygit2.RemoteCallbacks(credentials=credentials)

test/test_index.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"""Tests for Index files."""
2727

2828
import os
29-
import unittest
3029
from pathlib import Path
3130

3231
import pytest
@@ -72,7 +71,7 @@ def test_add(self):
7271
assert len(index) == 3
7372
assert index['bye.txt'].hex == sha
7473

75-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
74+
@utils.fspath
7675
def test_add_aspath(self):
7776
index = self.repo.index
7877

@@ -116,7 +115,7 @@ def test_add_all(self):
116115
assert index['bye.txt'].hex == sha_bye
117116
assert index['hello.txt'].hex == sha_hello
118117

119-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
118+
@utils.fspath
120119
def test_add_all_aspath(self):
121120
self.test_clear()
122121

@@ -202,14 +201,14 @@ def test_remove_all(self):
202201

203202
index.remove_all(['not-existing']) # this doesn't error
204203

205-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
204+
@utils.fspath
206205
def test_remove_aspath(self):
207206
index = self.repo.index
208207
assert 'hello.txt' in index
209208
index.remove(Path('hello.txt'))
210209
assert 'hello.txt' not in index
211210

212-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
211+
@utils.fspath
213212
def test_remove_all_aspath(self):
214213
index = self.repo.index
215214
assert 'hello.txt' in index
@@ -246,7 +245,7 @@ def test_create_entry(self):
246245
tree_id = index.write_tree()
247246
assert '60e769e57ae1d6a2ab75d8d253139e6260e1f912' == str(tree_id)
248247

249-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
248+
@utils.fspath
250249
def test_create_entry_aspath(self):
251250
index = self.repo.index
252251
hello_entry = index[Path('hello.txt')]

test/test_odb_backend.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import binascii
3030
import gc
3131
import os
32-
import unittest
3332

3433
import pytest
3534

test/test_refdb_backend.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"""Tests for Refdb objects."""
2727

2828
import os
29-
import unittest
3029

3130
from pygit2 import Refdb, RefdbBackend, RefdbFsBackend, Repository
3231
from pygit2 import Reference

test/test_remote.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
from pygit2 import Oid
3838
from . import utils
3939

40-
try:
41-
import __pypy__
42-
except ImportError:
43-
__pypy__ = None
4440

4541
REMOTE_NAME = 'origin'
4642
REMOTE_URL = 'git://github.com/libgit2/pygit2.git'
@@ -173,7 +169,7 @@ def test_remote_list(self):
173169
remote = self.repo.remotes.create(name, url)
174170
assert remote.name in [x.name for x in self.repo.remotes]
175171

176-
@unittest.skipIf(utils.no_network(), "Requires network")
172+
@utils.network
177173
def test_ls_remotes(self):
178174
assert 1 == len(self.repo.remotes)
179175
remote = self.repo.remotes[0]
@@ -198,7 +194,7 @@ def test_remote_collection(self):
198194
remote = self.repo.remotes.create(name, url)
199195
assert remote.name in [x.name for x in self.repo.remotes]
200196

201-
@unittest.skipIf(__pypy__ is not None, "skip refcounts checks in pypy")
197+
@utils.refcount
202198
def test_remote_refcount(self):
203199
start = sys.getrefcount(self.repo)
204200
remote = self.repo.remotes[0]

test/test_repository.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
# Import from the Standard Library
2929
import binascii
30-
import unittest
3130
import shutil
3231
import tempfile
3332
import os
@@ -47,11 +46,6 @@
4746
import pygit2
4847
from . import utils
4948

50-
try:
51-
import __pypy__
52-
except ImportError:
53-
__pypy__ = None
54-
5549

5650
HEAD_SHA = '784855caf26449a1914d2cf62d12b9374d76ae78'
5751
PARENT_SHA = 'f5e5aa4e36ab0fe62ee1ccc6eb8f79b866863b87' # HEAD^
@@ -159,7 +153,7 @@ def test_expand_id(self):
159153
expanded = self.repo.expand_id(commit_sha[:7])
160154
assert commit_sha == expanded.hex
161155

162-
@unittest.skipIf(__pypy__ is not None, "skip refcounts checks in pypy")
156+
@utils.refcount
163157
def test_lookup_commit_refcount(self):
164158
start = sys.getrefcount(self.repo)
165159
commit_sha = '5fe808e8953c12735680c257f56600cb0de44b10'
@@ -516,7 +510,7 @@ def test_no_arg(tmp_path):
516510
repo = init_repository(tmp_path)
517511
assert not repo.is_bare
518512

519-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
513+
@utils.fspath
520514
def test_no_arg_aspath(tmp_path):
521515
repo = init_repository(Path(tmp_path))
522516
assert not repo.is_bare
@@ -544,7 +538,7 @@ def test_discover_repo(tmp_path):
544538
os.makedirs(subdir)
545539
assert repo.path == discover_repository(subdir)
546540

547-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
541+
@utils.fspath
548542
def test_discover_repo_aspath(tmp_path):
549543
repo = init_repository(Path(tmp_path), False)
550544
subdir = Path(tmp_path) / "test1" / "test2"
@@ -577,7 +571,7 @@ def test_unicode_string():
577571
repo_path = './test/data/testrepo.git/'
578572
pygit2.Repository(repo_path)
579573

580-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
574+
@utils.fspath
581575
def test_aspath():
582576
repo_path = Path('./test/data/testrepo.git/')
583577
pygit2.Repository(repo_path)
@@ -589,7 +583,7 @@ def test_clone_repository(tmp_path):
589583
assert not repo.is_empty
590584
assert not repo.is_bare
591585

592-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
586+
@utils.fspath
593587
def test_clone_repository_aspath(tmp_path):
594588
repo_path = Path("./test/data/testrepo.git/")
595589
repo = clone_repository(repo_path, Path(tmp_path))
@@ -624,7 +618,8 @@ def create_remote(repo, name, url):
624618
assert 'refs/remotes/custom_remote/master' in repo.listall_references()
625619
assert repo.remotes["custom_remote"] is not None
626620

627-
@unittest.skipIf(utils.no_network(), "Requires network")
621+
622+
@utils.network
628623
def test_clone_with_credentials(tmp_path):
629624
url = 'https://github.com/libgit2/TestGitRepository'
630625
credentials = pygit2.UserPass("libgit2", "libgit2")
@@ -633,7 +628,7 @@ def test_clone_with_credentials(tmp_path):
633628

634629
assert not repo.is_empty
635630

636-
@unittest.skipIf(utils.no_network(), "Requires network")
631+
@utils.network
637632
def test_clone_bad_credentials(tmp_path):
638633
class MyCallbacks(pygit2.RemoteCallbacks):
639634
def credentials(self, url, username, allowed):
@@ -738,7 +733,7 @@ def _check_worktree(worktree):
738733
worktree.prune(True)
739734
assert self.repo.list_worktrees() == []
740735

741-
@unittest.skipIf(not utils.has_fspath, "Requires PEP-519 (FSPath) support")
736+
@utils.fspath
742737
def test_worktree_aspath(self):
743738
worktree_name = 'foo'
744739
worktree_dir = Path(tempfile.mkdtemp())

0 commit comments

Comments
 (0)