tests: add utility function 'oid_to_hex'
This commit is contained in:
parent
8b84f90a81
commit
e9e902e024
@ -29,7 +29,6 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from binascii import b2a_hex
|
||||
import unittest
|
||||
|
||||
import pygit2
|
||||
@ -46,7 +45,7 @@ class BlobTest(utils.BareRepoTestCase):
|
||||
def test_read_blob(self):
|
||||
blob = self.repo[BLOB_SHA]
|
||||
self.assertEqual(blob.hex, BLOB_SHA)
|
||||
sha = b2a_hex(blob.oid).decode('ascii')
|
||||
sha = utils.oid_to_hex(blob.oid)
|
||||
self.assertEqual(sha, BLOB_SHA)
|
||||
self.assertTrue(isinstance(blob, pygit2.Blob))
|
||||
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from binascii import b2a_hex
|
||||
import os
|
||||
import unittest
|
||||
|
||||
@ -102,7 +101,7 @@ class IndexTest(utils.RepoTestCase):
|
||||
self.assertEqual(len(index), 1)
|
||||
# Test read-write returns the same oid
|
||||
oid = index.write_tree()
|
||||
oid = b2a_hex(oid).decode('ascii')
|
||||
oid = utils.oid_to_hex(oid)
|
||||
self.assertEqual(oid, tree_oid)
|
||||
# Test the index is only modified in memory
|
||||
index.read()
|
||||
@ -111,7 +110,7 @@ class IndexTest(utils.RepoTestCase):
|
||||
|
||||
def test_write_tree(self):
|
||||
oid = self.repo.index.write_tree()
|
||||
sha = b2a_hex(oid).decode('ascii')
|
||||
sha = utils.oid_to_hex(oid)
|
||||
self.assertEqual(sha, 'fd937514cb799514d4b81bb24c5fcfeb6472b245')
|
||||
|
||||
def test_iter(self):
|
||||
|
@ -29,7 +29,6 @@
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
from binascii import b2a_hex
|
||||
import os
|
||||
import unittest
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
"""Test utilities for libgit2."""
|
||||
|
||||
from binascii import b2a_hex
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
@ -40,6 +41,10 @@ import pygit2
|
||||
__author__ = 'dborowitz@google.com (Dave Borowitz)'
|
||||
|
||||
|
||||
def oid_to_hex(oid):
|
||||
return b2a_hex(oid).decode('ascii')
|
||||
|
||||
|
||||
def rmtree(path):
|
||||
"""In Windows a read-only file cannot be removed, and shutil.rmtree fails.
|
||||
So we implement our own version of rmtree to address this issue.
|
||||
|
Loading…
x
Reference in New Issue
Block a user