Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit bfd20dc4b44c67f47ca0c1d0538d4b5bba0ed519 1 parent 7f7a512
Petr Viktorin encukou authored
16 test/test_index.py
@@ -31,9 +31,11 @@
31 31 __author__ = 'jdavid@itaapy.com (J. David Ibáñez)'
32 32
33 33 import unittest
  34 +import os
34 35
35 36 import utils
36 37
  38 +import pygit2
37 39
38 40 class IndexBareTest(utils.BareRepoTestCase):
39 41
@@ -57,6 +59,7 @@ def test_read(self):
57 59 sha = 'a520c24d85fbfc815d385957eed41406ca5a860b'
58 60 self.assertTrue('hello.txt' in index)
59 61 self.assertEqual(index['hello.txt'].sha, sha)
  62 + self.assertEqual(index['hello.txt'].path, 'hello.txt')
60 63 self.assertEqual(index[1].sha, sha)
61 64
62 65 def test_add(self):
@@ -93,9 +96,10 @@ def test_iter(self):
93 96 index = self.repo.index
94 97 n = len(index)
95 98 self.assertEqual(len(list(index)), n)
96   - # FIXME This fails
97   - #entries = [index[x] for x in xrange(n)]
98   - #self.assertEqual(list(index), entries)
  99 +
  100 + # Compare SHAs, not IndexEntry object identity
  101 + entries = [index[x].sha for x in xrange(n)]
  102 + self.assertEqual(list(x.sha for x in index), entries)
99 103
100 104 def test_mode(self):
101 105 """
@@ -106,6 +110,12 @@ def test_mode(self):
106 110 hello_mode = index['hello.txt'].mode
107 111 self.assertEqual(hello_mode, 33188)
108 112
  113 + def test_bare_index(self):
  114 + index = pygit2.Index(os.path.join(self.repo.path, 'index'))
  115 + self.assertEqual([x.sha for x in index],
  116 + [x.sha for x in self.repo.index])
  117 +
  118 + self.assertRaises(pygit2.GitError, lambda: index.add('bye.txt', 0))
109 119
110 120 if __name__ == '__main__':
111 121 unittest.main()
12 test/test_repository.py
@@ -31,9 +31,11 @@
31 31
32 32 import binascii
33 33 import unittest
  34 +import os
34 35 from os.path import join, abspath
35 36
36   -from pygit2 import GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT
  37 +from pygit2 import (GitError, GIT_OBJ_ANY, GIT_OBJ_BLOB, GIT_OBJ_COMMIT,
  38 + init_repository)
37 39 import utils
38 40
39 41 A_HEX_SHA = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
@@ -111,6 +113,14 @@ def test_get_workdir(self):
111 113 self.assertEqual(directory, expected)
112 114
113 115
  116 +class NewRepositoryTest(utils.NoRepoTestCase):
  117 + def test_new_repo(self):
  118 + repo = init_repository(self.temp_dir, False)
  119 +
  120 + hex_sha = repo.write(GIT_OBJ_BLOB, "Test")
  121 + self.assertEqual(len(hex_sha), 40)
  122 +
  123 + assert os.path.exists(os.path.join(self._temp_dir, '.git'))
114 124
115 125 if __name__ == '__main__':
116 126 unittest.main()
20 test/test_revwalk.py
@@ -61,6 +61,26 @@ def test_hide(self):
61 61 walker.hide('4ec4389a8068641da2d6578db0419484972284c8')
62 62 self.assertEqual(len(list(walker)), 2)
63 63
  64 + def test_reset(self):
  65 + walker = self.repo.walk(log[0], GIT_SORT_TIME)
  66 + walker.reset()
  67 + out = [ x.sha for x in walker ]
  68 + self.assertEqual(out, [])
  69 +
  70 + def test_push(self):
  71 + walker = self.repo.walk(log[-1], GIT_SORT_TIME)
  72 + out = [ x.sha for x in walker ]
  73 + self.assertEqual(out, log[-1:])
  74 + walker.reset()
  75 + walker.push(log[0])
  76 + out = [ x.sha for x in walker ]
  77 + self.assertEqual(out, log)
  78 +
  79 + def test_sort(self):
  80 + walker = self.repo.walk(log[0], GIT_SORT_TIME)
  81 + walker.sort(GIT_SORT_TIME | GIT_SORT_REVERSE)
  82 + out = [ x.sha for x in walker ]
  83 + self.assertEqual(out, list(reversed(log)))
64 84
65 85 if __name__ == '__main__':
66 86 unittest.main()
5 test/utils.py
@@ -79,6 +79,11 @@ def setUp(self):
79 79 temp_repo_path = os.path.join(temp_dir, repo_dir, '.git')
80 80 self.repo = pygit2.Repository(temp_repo_path)
81 81
  82 +class NoRepoTestCase(BaseTestCase):
  83 + def setUp(self):
  84 + self.temp_dir = tempfile.mkdtemp()
  85 + self._temp_dir = self.temp_dir
  86 +
82 87 class DirtyRepoTestCase(RepoTestCase):
83 88
84 89 repo_dir = 'dirtyrepo'

0 comments on commit bfd20dc

Please sign in to comment.
Something went wrong with that request. Please try again.