Browse files

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
  • Loading branch information...
1 parent 7f7a512 commit bfd20dc4b44c67f47ca0c1d0538d4b5bba0ed519 @encukou encukou committed Aug 8, 2011
Showing with 49 additions and 4 deletions.
  1. +13 −3 test/test_index.py
  2. +11 −1 test/test_repository.py
  3. +20 −0 test/test_revwalk.py
  4. +5 −0 test/utils.py
View
16 test/test_index.py
@@ -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 @@ def test_read(self):
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 @@ def test_iter(self):
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 @@ def test_mode(self):
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()
View
12 test/test_repository.py
@@ -31,9 +31,11 @@
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 @@ def test_get_workdir(self):
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()
View
20 test/test_revwalk.py
@@ -61,6 +61,26 @@ def test_hide(self):
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()
View
5 test/utils.py
@@ -79,6 +79,11 @@ def setUp(self):
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'

0 comments on commit bfd20dc

Please sign in to comment.