Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
with pytest.raises(ValueError):
repo.create_commit(None, author, committer, message, too_short_prefix, parents)
sha = repo.create_commit(None, author, committer, message,
tree_prefix, parents)
commit = repo[sha]
assert GIT_OBJ_COMMIT == commit.type
assert '98286caaab3f1fde5bf52c8369b2b0423bad743b' == commit.hex
assert commit.message_encoding is None
assert message == commit.message
assert 12346 == commit.commit_time
assert committer == commit.committer
assert author == commit.author
assert tree == commit.tree.hex
assert Oid(hex=tree) == commit.tree_id
assert 1 == len(commit.parents)
assert COMMIT_SHA == commit.parents[0].hex
assert Oid(hex=COMMIT_SHA) == commit.parent_ids[0]
def test_cmp(self):
oid1 = Oid(raw=RAW)
# Equal
oid2 = Oid(hex=HEX)
assert oid1 == oid2
# Not equal
oid2 = Oid(hex="15b648aec6ed045b5ca6f57f8b7831a8b4757299")
assert oid1 != oid2
# Other
assert oid1 < oid2
assert oid1 <= oid2
assert not oid1 == oid2
assert not oid1 > oid2
assert not oid1 >= oid2
def test_iterable(self):
l = [obj for obj in self.repo]
oid = Oid(hex=BLOB_HEX)
self.assertTrue(oid in l)
import os
from os.path import join, realpath
# Import from pygit2
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
from pygit2 import init_repository, clone_repository, discover_repository
from pygit2 import Oid, Reference, hashfile
import pygit2
from . import utils
HEAD_SHA = '784855caf26449a1914d2cf62d12b9374d76ae78'
PARENT_SHA = 'f5e5aa4e36ab0fe62ee1ccc6eb8f79b866863b87' # HEAD^
BLOB_HEX = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
BLOB_RAW = binascii.unhexlify(BLOB_HEX.encode('ascii'))
BLOB_OID = Oid(raw=BLOB_RAW)
class RepositoryTest(utils.BareRepoTestCase):
def test_is_empty(self):
self.assertFalse(self.repo.is_empty)
def test_is_bare(self):
self.assertTrue(self.repo.is_bare)
def test_head(self):
head = self.repo.head
self.assertEqual(HEAD_SHA, head.target.hex)
self.assertEqual(type(head), Reference)
self.assertFalse(self.repo.head_is_orphaned)
self.assertFalse(self.repo.head_is_detached)
import gc
import os
import unittest
import pytest
# Import from pygit2
from pygit2 import Odb, OdbBackendPack, OdbBackendLoose, Oid
from pygit2 import GIT_OBJ_ANY, GIT_OBJ_BLOB
from . import utils
BLOB_HEX = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
BLOB_RAW = binascii.unhexlify(BLOB_HEX.encode('ascii'))
BLOB_OID = Oid(raw=BLOB_RAW)
class EmptyOdbTest(unittest.TestCase):
def setUp(self):
self.odb = Odb()
def test_iterable(self):
assert len([str(o) for o in self.odb]) == 0
def test_contains(self):
assert BLOB_HEX not in self.odb
def test_add_disk_alternate(self):
assert BLOB_HEX not in self.odb
path = os.path.join(os.path.dirname(__file__),
'data', 'testrepo.git', 'objects')
self.odb.add_disk_alternate(path)
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Tests for Blame objects."""
import pytest
from pygit2 import Signature, Oid
from . import utils
PATH = 'hello.txt'
HUNKS = [
(Oid(hex='acecd5ea2924a4b900e7e149496e1f4b57976e51'), 1,
Signature('J. David Ibañez', 'jdavid@itaapy.com',
1297179898, 60, encoding='utf-8'), True),
(Oid(hex='6aaa262e655dd54252e5813c8e5acd7780ed097d'), 2,
Signature('J. David Ibañez', 'jdavid@itaapy.com',
1297696877, 60, encoding='utf-8'), False),
(Oid(hex='4ec4389a8068641da2d6578db0419484972284c8'), 3,
Signature('J. David Ibañez', 'jdavid@itaapy.com',
1297696908, 60, encoding='utf-8'), False)
]
class BlameTest(utils.RepoTestCase):
def test_blame_index(self):
repo = self.repo
blame = repo.blame(PATH)
def test_hash(self):
s = set()
s.add(Oid(raw=RAW))
s.add(Oid(hex=HEX))
assert len(s) == 1
s.add(Oid(hex="0000000000000000000000000000000000000000"))
s.add(Oid(hex="0000000000000000000000000000000000000001"))
assert len(s) == 3
# Import from the Standard Library
import binascii
import gc
import os
import pytest
# Import from pygit2
from pygit2 import OdbBackend, OdbBackendPack, OdbBackendLoose, Oid
from pygit2 import GIT_OBJ_BLOB
from . import utils
BLOB_HEX = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
BLOB_RAW = binascii.unhexlify(BLOB_HEX.encode('ascii'))
BLOB_OID = Oid(raw=BLOB_RAW)
class OdbBackendTest(utils.BareRepoTestCase):
def setUp(self):
super().setUp()
self.ref_odb = self.repo.odb
self.obj_path = os.path.join(os.path.dirname(__file__),
'data', 'testrepo.git', 'objects')
def tearDown(self):
del self.ref_odb
gc.collect()
super().tearDown()
def test_pack(self):
def write_commit(self, message: typing.Optional[str] = ""):
now = int(time.time())
parents: typing.List[git.Oid]
if self._commit:
parents = [ self._commit ]
else:
parents = []
sig = git.Signature(self._name, self._email, time=now)
self._commit = self._repo.create_commit(
"HEAD",
sig,
sig,
message,
self._tree,
parents,
)