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