Skip to content

Commit b1a072e

Browse files
committed
test: additional housekeeping
1 parent c8e5509 commit b1a072e

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

test/test_commit_gpg.py

+29-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2010-2021 The pygit2 contributors
1+
# Copyright 2010-2022 The pygit2 contributors
22
#
33
# This file is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2,
@@ -31,7 +31,8 @@
3131
author Ben Burkert <[email protected]> 1358451456 -0800
3232
committer Ben Burkert <[email protected]> 1358451456 -0800
3333
34-
a simple commit which works"""
34+
a simple commit which works\
35+
"""
3536

3637
gpgsig = """\
3738
-----BEGIN PGP SIGNATURE-----
@@ -50,7 +51,8 @@
5051
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc
5152
cpxtDQQMGYFpXK/71stq
5253
=ozeK
53-
-----END PGP SIGNATURE-----"""
54+
-----END PGP SIGNATURE-----\
55+
"""
5456

5557
gpgsig_content = """\
5658
tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
@@ -75,8 +77,10 @@
7577
=ozeK
7678
-----END PGP SIGNATURE-----
7779
78-
a simple commit which works"""
80+
a simple commit which works\
81+
"""
7982
# NOTE: ^^^ mind the gap (space must exist after GnuPG header) ^^^
83+
# XXX: seems macos wants the space while linux does not
8084

8185

8286
def test_commit_signing(gpgsigned):
@@ -103,36 +107,36 @@ def test_commit_signing(gpgsigned):
103107
)
104108
assert commit == content
105109

106-
# create signed commit
107-
signed_oid = repo.create_commit_with_signature(content, gpgsig)
108-
signed_commit = repo.get(signed_oid)
110+
# create/retrieve signed commit
111+
oid = repo.create_commit_with_signature(content, gpgsig)
112+
commit = repo.get(oid)
113+
signature, payload = commit.gpg_signature
109114

110-
# verify signed commit
111-
signature, payload = signed_commit.gpg_signature
112-
assert gpgsig == signature.decode("utf-8")
115+
# validate signed commit
113116
assert content == payload.decode("utf-8")
114-
assert signed_commit.read_raw().decode("utf-8") == gpgsig_content
117+
assert gpgsig == signature.decode("utf-8")
118+
assert gpgsig_content == commit.read_raw().decode("utf-8")
115119

116120
# perform sanity checks
117-
assert GIT_OBJ_COMMIT == signed_commit.type
118-
assert "6569fdf71dbd99081891154641869c537784a3ba" == signed_commit.hex
119-
assert signed_commit.message_encoding is None
120-
assert message == signed_commit.message
121-
assert 1358451456 == signed_commit.commit_time
122-
assert committer == signed_commit.committer
123-
assert author == signed_commit.author
124-
assert tree == signed_commit.tree.hex
125-
assert Oid(hex=tree) == signed_commit.tree_id
126-
assert 1 == len(signed_commit.parents)
127-
assert parents[0] == signed_commit.parents[0].hex
128-
assert Oid(hex=parents[0]) == signed_commit.parent_ids[0]
121+
assert GIT_OBJ_COMMIT == commit.type
122+
assert "6569fdf71dbd99081891154641869c537784a3ba" == commit.hex
123+
assert commit.message_encoding is None
124+
assert message == commit.message
125+
assert 1358451456 == commit.commit_time
126+
assert committer == commit.committer
127+
assert author == commit.author
128+
assert tree == commit.tree.hex
129+
assert Oid(hex=tree) == commit.tree_id
130+
assert 1 == len(commit.parents)
131+
assert parents[0] == commit.parents[0].hex
132+
assert Oid(hex=parents[0]) == commit.parent_ids[0]
129133

130134

131135
def test_get_gpg_signature_when_unsigned(gpgsigned):
132-
unsigned_hash = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
136+
unhash = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
133137

134138
repo = gpgsigned
135-
commit = repo.get(unsigned_hash)
139+
commit = repo.get(unhash)
136140
signature, payload = commit.gpg_signature
137141

138142
assert signature is None

0 commit comments

Comments
 (0)