Somewhat better test coverage
- create_repository - IndexEntry.path - Correct SHAs in Index iteration - Opening a bare index & attempting to add to it - Walker.reset - Walker.push - Walker.sort
This commit is contained in:
parent
7f7a512e66
commit
bfd20dc4b4
@ -31,9 +31,11 @@
|
||||
__author__ = 'jdavid@itaapy.com (J. David Ibáñez)'
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
import utils
|
||||
|
||||
import pygit2
|
||||
|
||||
class IndexBareTest(utils.BareRepoTestCase):
|
||||
|
||||
@ -57,6 +59,7 @@ class IndexTest(utils.RepoTestCase):
|
||||
sha = 'a520c24d85fbfc815d385957eed41406ca5a860b'
|
||||
self.assertTrue('hello.txt' in index)
|
||||
self.assertEqual(index['hello.txt'].sha, sha)
|
||||
self.assertEqual(index['hello.txt'].path, 'hello.txt')
|
||||
self.assertEqual(index[1].sha, sha)
|
||||
|
||||
def test_add(self):
|
||||
@ -93,9 +96,10 @@ class IndexTest(utils.RepoTestCase):
|
||||
index = self.repo.index
|
||||
n = len(index)
|
||||
self.assertEqual(len(list(index)), n)
|
||||
# FIXME This fails
|
||||
#entries = [index[x] for x in xrange(n)]
|
||||
#self.assertEqual(list(index), entries)
|
||||
|
||||
# Compare SHAs, not IndexEntry object identity
|
||||
entries = [index[x].sha for x in xrange(n)]
|
||||
self.assertEqual(list(x.sha for x in index), entries)
|
||||
|
||||
def test_mode(self):
|
||||
"""
|
||||
@ -106,6 +110,12 @@ class IndexTest(utils.RepoTestCase):
|
||||
hello_mode = index['hello.txt'].mode
|
||||
self.assertEqual(hello_mode, 33188)
|
||||
|
||||
def test_bare_index(self):
|
||||
index = pygit2.Index(os.path.join(self.repo.path, 'index'))
|
||||
self.assertEqual([x.sha for x in index],
|
||||
[x.sha for x in self.repo.index])
|
||||
|
||||
self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt', 0))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -31,9 +31,11 @@ __author__ = 'dborowitz@google.com (Dave Borowitz)'
|
||||
|
||||
import binascii
|
||||
import unittest
|
||||
import os
|
||||
from os.path import join, abspath
|
||||
|
||||
from pygit2 import GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
|
||||
from pygit2 import (GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT,
|
||||
init_repository)
|
||||
import utils
|
||||
|
||||
A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
|
||||
@ -111,6 +113,14 @@ class RepositoryTest_II(utils.RepoTestCase):
|
||||
self.assertEqual(directory, expected)
|
||||
|
||||
|
||||
class NewRepositoryTest(utils.NoRepoTestCase):
|
||||
def test_new_repo(self):
|
||||
repo = init_repository(self.temp_dir, False)
|
||||
|
||||
hex_sha = repo.write(GIT_OBJ_BLOB, "Test")
|
||||
self.assertEqual(len(hex_sha), 40)
|
||||
|
||||
assert os.path.exists(os.path.join(self._temp_dir, '.git'))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -61,6 +61,26 @@ class WalkerTest(utils.RepoTestCase):
|
||||
walker.hide('4ec4389a8068641da2d6578db0419484972284c8')
|
||||
self.assertEqual(len(list(walker)), 2)
|
||||
|
||||
def test_reset(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME)
|
||||
walker.reset()
|
||||
out = [ x.sha for x in walker ]
|
||||
self.assertEqual(out, [])
|
||||
|
||||
def test_push(self):
|
||||
walker = self.repo.walk(log[-1], GIT_SORT_TIME)
|
||||
out = [ x.sha for x in walker ]
|
||||
self.assertEqual(out, log[-1:])
|
||||
walker.reset()
|
||||
walker.push(log[0])
|
||||
out = [ x.sha for x in walker ]
|
||||
self.assertEqual(out, log)
|
||||
|
||||
def test_sort(self):
|
||||
walker = self.repo.walk(log[0], GIT_SORT_TIME)
|
||||
walker.sort(GIT_SORT_TIME | GIT_SORT_REVERSE)
|
||||
out = [ x.sha for x in walker ]
|
||||
self.assertEqual(out, list(reversed(log)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -79,6 +79,11 @@ class RepoTestCase(BaseTestCase):
|
||||
temp_repo_path = os.path.join(temp_dir, repo_dir, '.git')
|
||||
self.repo = pygit2.Repository(temp_repo_path)
|
||||
|
||||
class NoRepoTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self._temp_dir = self.temp_dir
|
||||
|
||||
class DirtyRepoTestCase(RepoTestCase):
|
||||
|
||||
repo_dir = 'dirtyrepo'
|
||||
|
Loading…
x
Reference in New Issue
Block a user