aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-12-29 10:10:47 +0100
committerGuido Günther <agx@sigxcpu.org>2011-12-29 12:46:17 +0100
commit84d3bfb9af954ced15282fc8c35f1a1cbe140455 (patch)
tree007b2d3b24914e441cb48b6fc7f147c50524e32b /tests
parent479b933c55228cba29bae9cfa50930bb1ff32f00 (diff)
GitRepository: add test for {write,commit}_tree
Git-Dch: Ignore
Diffstat (limited to 'tests')
-rw-r--r--tests/09_test_write_tree.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/09_test_write_tree.py b/tests/09_test_write_tree.py
new file mode 100644
index 00000000..c642ed60
--- /dev/null
+++ b/tests/09_test_write_tree.py
@@ -0,0 +1,82 @@
+# vim: set fileencoding=utf-8 :
+
+"""Test L{GitRepository}'s write_tree method"""
+
+import os
+import shutil
+import tempfile
+import unittest
+
+import gbp.log
+import gbp.git
+import gbp.errors
+
+
+class TestWriteTree(unittest.TestCase):
+ def _write_testtree(self):
+ """Write a test tree"""
+ paths = []
+ for i in range(4):
+ path = os.path.join(self.repo.path, 'testfile%d' % i)
+ with file(path, 'w') as f:
+ print >>f, "testdata %d" % i
+ paths.append(path)
+ return paths
+
+ def setUp(self):
+ gbp.log.setup(False, False)
+ top = os.path.abspath(os.path.curdir)
+ self.tmpdir = os.path.join(top, 'gbp_%s_repo' % __name__)
+ os.mkdir(self.tmpdir)
+
+ repodir = os.path.join(self.tmpdir, 'test_repo')
+ self.repo = gbp.git.GitRepository.create(repodir)
+
+ def tearDown(self):
+ shutil.rmtree(self.tmpdir)
+
+ def test_write_tree_index_nonexistant(self):
+ """Write out index file to nonexistant dir"""
+ paths = self._write_testtree()
+ self.repo.add_files(paths)
+ self.assertRaises(gbp.git.GitRepositoryError,
+ self.repo.write_tree,
+ '/does/not/exist')
+
+ def test_write_tree(self):
+ """Write out index file to alternate index file"""
+ index = os.path.join(self.repo.git_dir, 'gbp_index')
+ expected_sha1 = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
+
+ paths = self._write_testtree()
+ self.repo.add_files(paths)
+ sha1 = self.repo.write_tree(index)
+ self.assertTrue(os.path.exists(index))
+ self.assertEqual(sha1, expected_sha1)
+ self.assertTrue(self.repo.has_treeish(expected_sha1))
+
+ def test_commit_tree(self):
+ """Commit a tree"""
+ expected_sha1 = 'ea63fcee40675a5f82ea6bedbf29ca86d89c5f63'
+ paths = self._write_testtree()
+ self.repo.add_files(paths)
+ sha1 = self.repo.write_tree()
+ self.assertEqual(sha1, expected_sha1)
+ self.assertTrue(self.repo.has_treeish(expected_sha1))
+ commit = self.repo.commit_tree(sha1, "first commit", parents=[],
+ committer=dict(name='foo',
+ email='foo@example.com'),
+ author=dict(name='bar',
+ email='bar@example.com'),
+ )
+ self.assertEqual(len(commit), 40)
+ # commit the same tree again using the previous commit as parent
+ commit2 = self.repo.commit_tree(sha1, "second commit", parents=[commit])
+ # commit the same tree again using a non existant parent
+ self.assertRaises(gbp.errors.GbpError,
+ self.repo.commit_tree,
+ sha1,
+ "failed commit",
+ ['doesnotexist'])
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: