Skip to content

Commit 4ab391a

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

File tree

10 files changed

+249
-160
lines changed

10 files changed

+249
-160
lines changed

test/test_commit.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -135,41 +135,3 @@ def test_modify_commit(self):
135135
with pytest.raises(AttributeError): setattr(commit, 'author', author)
136136
with pytest.raises(AttributeError): setattr(commit, 'tree', None)
137137
with pytest.raises(AttributeError): setattr(commit, 'parents', None)
138-
139-
140-
class GpgSignatureTestCase(utils.GpgSignedRepoTestCase):
141-
signed_hash = 'a00b212d5455ad8c4c1779f778c7d2a81bb5da23'
142-
unsigned_hash = 'a84938d1d885e80dae24b86b06621cec47ff6edd'
143-
144-
def test_get_gpg_signature_when_signed(self):
145-
expected_signature = (
146-
'-----BEGIN PGP SIGNATURE-----\n\n'
147-
'iQFGBAABCgAwFiEEQZu9JtePgJbDk7VC0+mlK74z13oFAlpzXykSHG1hcmtAbWFy\n'
148-
'a2FkYW1zLm1lAAoJENPppSu+M9d6FRoIAJXeQRRT1V47nnHITiel6426loYkeij7\n'
149-
'66doGNIyll95H92SwH4LAjPyEEByIG1VsA6NztzUoNgnEvAXI0iAz3LyI7N16M4b\n'
150-
'dPDkC72pp8tu280H5Qt5b2V5hmlKKSgtOS5iNhdU/FbWVS8MlHsqzQTZfoTdi6ch\n'
151-
'KWUsjzudVd3F/H/AU+1Jsxt8Iz/oK4T/puUQLnJZKjKlljGP994FA3JIpnZpZmbG\n'
152-
'FybYJEDXnng7uhx3Fz/Mo3KBJoQfAExTtaToY0n0hSjOe6GN9rEsRSMK3mWdysf2\n'
153-
'wOdtYMMcT16hG5tAwnD/myZ4rIIpyZJ/9mjymdUsj6UKf7D+vJuqfsI=\n=IyYy\n'
154-
'-----END PGP SIGNATURE-----'
155-
).encode('ascii')
156-
157-
expected_payload = (
158-
'tree c36c20831e43e5984c672a714661870b67ab1d95\nauthor Mark Adams '
159-
'<madams@atlassian.com> 1517510299 -0600\ncommitter Mark Adams <ma'
160-
'dams@atlassian.com> 1517510441 -0600\n\nMaking a GPG signed commi'
161-
't\n'
162-
).encode('ascii')
163-
164-
commit = self.repo.get(self.signed_hash)
165-
signature, payload = commit.gpg_signature
166-
167-
assert signature == expected_signature
168-
assert payload == expected_payload
169-
170-
def test_get_gpg_signature_when_unsigned(self):
171-
commit = self.repo.get(self.unsigned_hash)
172-
signature, payload = commit.gpg_signature
173-
174-
assert signature is None
175-
assert payload is None

test/test_commit_gpg.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright 2010-2020 The pygit2 contributors
2+
#
3+
# This file is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2,
5+
# as published by the Free Software Foundation.
6+
#
7+
# In addition to the permissions in the GNU General Public License,
8+
# the authors give you unlimited permission to link the compiled
9+
# version of this file into combinations with other programs,
10+
# and to distribute those combinations without any restriction
11+
# coming from the use of this file. (The General Public License
12+
# restrictions do apply in other respects; for example, they cover
13+
# modification of the file, and distribution when not linked into
14+
# a combined executable.)
15+
#
16+
# This file is distributed in the hope that it will be useful, but
17+
# WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
# General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; see the file COPYING. If not, write to
23+
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24+
# Boston, MA 02110-1301, USA.
25+
26+
import pygit2
27+
import pytest
28+
29+
from . import utils
30+
31+
32+
@pytest.fixture(scope='module')
33+
def repo():
34+
repo_spec = 'tar', 'gpgsigned'
35+
with utils.TemporaryRepository(repo_spec) as path:
36+
yield pygit2.Repository(path)
37+
38+
39+
def test_get_gpg_signature_when_signed(repo):
40+
signed_hash = 'a00b212d5455ad8c4c1779f778c7d2a81bb5da23'
41+
expected_signature = (
42+
'-----BEGIN PGP SIGNATURE-----\n\n'
43+
'iQFGBAABCgAwFiEEQZu9JtePgJbDk7VC0+mlK74z13oFAlpzXykSHG1hcmtAbWFy\n'
44+
'a2FkYW1zLm1lAAoJENPppSu+M9d6FRoIAJXeQRRT1V47nnHITiel6426loYkeij7\n'
45+
'66doGNIyll95H92SwH4LAjPyEEByIG1VsA6NztzUoNgnEvAXI0iAz3LyI7N16M4b\n'
46+
'dPDkC72pp8tu280H5Qt5b2V5hmlKKSgtOS5iNhdU/FbWVS8MlHsqzQTZfoTdi6ch\n'
47+
'KWUsjzudVd3F/H/AU+1Jsxt8Iz/oK4T/puUQLnJZKjKlljGP994FA3JIpnZpZmbG\n'
48+
'FybYJEDXnng7uhx3Fz/Mo3KBJoQfAExTtaToY0n0hSjOe6GN9rEsRSMK3mWdysf2\n'
49+
'wOdtYMMcT16hG5tAwnD/myZ4rIIpyZJ/9mjymdUsj6UKf7D+vJuqfsI=\n=IyYy\n'
50+
'-----END PGP SIGNATURE-----'
51+
).encode('ascii')
52+
53+
expected_payload = (
54+
'tree c36c20831e43e5984c672a714661870b67ab1d95\nauthor Mark Adams '
55+
'<madams@atlassian.com> 1517510299 -0600\ncommitter Mark Adams <ma'
56+
'dams@atlassian.com> 1517510441 -0600\n\nMaking a GPG signed commi'
57+
't\n'
58+
).encode('ascii')
59+
60+
commit = repo.get(signed_hash)
61+
signature, payload = commit.gpg_signature
62+
63+
assert signature == expected_signature
64+
assert payload == expected_payload
65+
66+
67+
def test_get_gpg_signature_when_unsigned(repo):
68+
unsigned_hash = 'a84938d1d885e80dae24b86b06621cec47ff6edd'
69+
commit = repo.get(unsigned_hash)
70+
signature, payload = commit.gpg_signature
71+
72+
assert signature is None
73+
assert payload is None

test/test_diff.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import pygit2
3434
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
3535
from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL
36-
from pygit2 import GIT_DIFF_SHOW_BINARY
3736
from pygit2 import GIT_DELTA_RENAMED
3837
from . import utils
3938

@@ -65,22 +64,6 @@
6564

6665
PATCHID = 'f31412498a17e6c3fbc635f2c5f9aa3ef4c1a9b7'
6766

68-
PATCH_BINARY = """diff --git a/binary_file b/binary_file
69-
index 86e5c10..b835d73 100644
70-
Binary files a/binary_file and b/binary_file differ
71-
"""
72-
73-
PATCH_BINARY_SHOW = """diff --git a/binary_file b/binary_file
74-
index 86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6..b835d73543244b6694f36a8c5dfdffb71b153db7 100644
75-
GIT binary patch
76-
literal 8
77-
Pc${NM%FIhFs^kIy3n&7R
78-
79-
literal 8
80-
Pc${NM&PdElPvrst3ey5{
81-
82-
"""
83-
8467
DIFF_HEAD_TO_INDEX_EXPECTED = [
8568
'staged_changes',
8669
'staged_changes_file_deleted',
@@ -370,12 +353,3 @@ def test_parse_diff_bad(self):
370353
""")
371354
with pytest.raises(Exception):
372355
self.repo.parse_diff(diff)
373-
374-
375-
class BinaryDiffTest(utils.BinaryFileRepoTestCase):
376-
def test_binary_diff(self):
377-
repo = self.repo
378-
diff = repo.diff('HEAD', 'HEAD^')
379-
assert PATCH_BINARY == diff.patch
380-
diff = repo.diff('HEAD', 'HEAD^', flags=GIT_DIFF_SHOW_BINARY)
381-
assert PATCH_BINARY_SHOW == diff.patch

test/test_diff_binary.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2010-2020 The pygit2 contributors
2+
#
3+
# This file is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2,
5+
# as published by the Free Software Foundation.
6+
#
7+
# In addition to the permissions in the GNU General Public License,
8+
# the authors give you unlimited permission to link the compiled
9+
# version of this file into combinations with other programs,
10+
# and to distribute those combinations without any restriction
11+
# coming from the use of this file. (The General Public License
12+
# restrictions do apply in other respects; for example, they cover
13+
# modification of the file, and distribution when not linked into
14+
# a combined executable.)
15+
#
16+
# This file is distributed in the hope that it will be useful, but
17+
# WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
# General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; see the file COPYING. If not, write to
23+
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24+
# Boston, MA 02110-1301, USA.
25+
26+
import pygit2
27+
import pytest
28+
29+
from . import utils
30+
31+
32+
@pytest.fixture(scope='module')
33+
def repo():
34+
repo_spec = 'tar', 'binaryfilerepo'
35+
with utils.TemporaryRepository(repo_spec) as path:
36+
yield pygit2.Repository(path)
37+
38+
39+
PATCH_BINARY = """diff --git a/binary_file b/binary_file
40+
index 86e5c10..b835d73 100644
41+
Binary files a/binary_file and b/binary_file differ
42+
"""
43+
44+
PATCH_BINARY_SHOW = """diff --git a/binary_file b/binary_file
45+
index 86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6..b835d73543244b6694f36a8c5dfdffb71b153db7 100644
46+
GIT binary patch
47+
literal 8
48+
Pc${NM%FIhFs^kIy3n&7R
49+
50+
literal 8
51+
Pc${NM&PdElPvrst3ey5{
52+
53+
"""
54+
55+
def test_binary_diff(repo):
56+
diff = repo.diff('HEAD', 'HEAD^')
57+
assert PATCH_BINARY == diff.patch
58+
diff = repo.diff('HEAD', 'HEAD^', flags=pygit2.GIT_DIFF_SHOW_BINARY)
59+
assert PATCH_BINARY_SHOW == diff.patch

test/test_refdb_backend.py

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

2828
import os
2929

30-
from pygit2 import Refdb, RefdbBackend, RefdbFsBackend, Repository
30+
from pygit2 import RefdbBackend, RefdbFsBackend
3131
from pygit2 import Reference
3232

3333
from . import utils
@@ -105,7 +105,7 @@ def test_delete(self):
105105

106106
def test_compress(self):
107107
repo = self.repo
108-
packed_refs_file = os.path.join(self.repo_path, '.git', 'packed-refs')
108+
packed_refs_file = os.path.join(repo.path, 'packed-refs')
109109
assert not os.path.exists(packed_refs_file)
110110
self.backend.compress()
111111
assert os.path.exists(packed_refs_file)

test/test_refs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_equality(self):
242242

243243
def test_compress(self):
244244
repo = self.repo
245-
packed_refs_file = os.path.join(self.repo_path, '.git', 'packed-refs')
245+
packed_refs_file = os.path.join(repo.path, 'packed-refs')
246246
assert not os.path.exists(packed_refs_file)
247247
old_refs = [(ref.name, ref.target.hex)
248248
for ref in repo.references.objects]

test/test_remote.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,11 @@ def update_tips(self, name, old, new):
247247
class PruneTestCase(utils.RepoTestCase):
248248
def setUp(self):
249249
super().setUp()
250+
repo = self.repo
250251
cloned_repo_path = os.path.join(self.repo_ctxtmgr.temp_dir, 'test_remote_prune')
251-
pygit2.clone_repository(self.repo_path, cloned_repo_path)
252+
pygit2.clone_repository(repo.workdir, cloned_repo_path)
252253
self.clone_repo = pygit2.Repository(cloned_repo_path)
253-
self.repo.branches.delete('i18n')
254+
repo.branches.delete('i18n')
254255

255256
def tearDown(self):
256257
self.clone_repo = None
@@ -284,11 +285,6 @@ def update_tips(self, name, old, new):
284285
assert pruned == ['refs/remotes/origin/i18n']
285286
assert 'origin/i18n' not in self.clone_repo.branches
286287

287-
class Utf8BranchTest(utils.Utf8BranchRepoTestCase):
288-
def test_fetch(self):
289-
remote = self.repo.remotes.create('origin', self.repo.workdir)
290-
remote.fetch()
291-
292288

293289
class PushTestCase(unittest.TestCase):
294290
def setUp(self):

test/test_remote_utf8.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2010-2020 The pygit2 contributors
2+
#
3+
# This file is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License, version 2,
5+
# as published by the Free Software Foundation.
6+
#
7+
# In addition to the permissions in the GNU General Public License,
8+
# the authors give you unlimited permission to link the compiled
9+
# version of this file into combinations with other programs,
10+
# and to distribute those combinations without any restriction
11+
# coming from the use of this file. (The General Public License
12+
# restrictions do apply in other respects; for example, they cover
13+
# modification of the file, and distribution when not linked into
14+
# a combined executable.)
15+
#
16+
# This file is distributed in the hope that it will be useful, but
17+
# WITHOUT ANY WARRANTY; without even the implied warranty of
18+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
# General Public License for more details.
20+
#
21+
# You should have received a copy of the GNU General Public License
22+
# along with this program; see the file COPYING. If not, write to
23+
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24+
# Boston, MA 02110-1301, USA.
25+
26+
import pygit2
27+
import pytest
28+
from . import utils
29+
30+
31+
@pytest.fixture(scope='module')
32+
def repo():
33+
repo_spec = 'tar', 'utf8branchrepo'
34+
with utils.TemporaryRepository(repo_spec) as path:
35+
yield pygit2.Repository(path)
36+
37+
def test_fetch(repo):
38+
remote = repo.remotes.create('origin', repo.workdir)
39+
remote.fetch()

0 commit comments

Comments
 (0)