1
# test_utils.py -- Tests for git test utilities.
2
# Copyright (C) 2010 Google, Inc.
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
# Boston, MA 02110-1301, USA.
20
"""Tests for git test utilities."""
22
from dulwich.object_store import (
25
from dulwich.objects import (
28
from dulwich.tests import (
37
class BuildCommitGraphTest(TestCase):
40
self.store = MemoryObjectStore()
42
def test_linear(self):
43
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]])
44
for obj_id in [c1.id, c2.id, c1.tree, c2.tree]:
45
self.assertTrue(obj_id in self.store)
46
self.assertEqual([], c1.parents)
47
self.assertEqual([c1.id], c2.parents)
48
self.assertEqual(c1.tree, c2.tree)
49
self.assertEqual([], list(self.store[c1.tree].iteritems()))
50
self.assertTrue(c2.commit_time > c1.commit_time)
53
c1, c2, c3, c4 = build_commit_graph(self.store,
54
[[1], [2, 1], [3, 1], [4, 2, 3]])
55
self.assertEqual([c2.id, c3.id], c4.parents)
56
self.assertTrue(c4.commit_time > c2.commit_time)
57
self.assertTrue(c4.commit_time > c3.commit_time)
59
def test_missing_parent(self):
60
self.assertRaises(ValueError, build_commit_graph, self.store,
61
[[1], [3, 2], [2, 1]])
64
a1 = make_object(Blob, data='aaa1')
65
a2 = make_object(Blob, data='aaa2')
66
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
67
trees={1: [('a', a1)],
68
2: [('a', a2, 0100644)]})
69
self.assertEqual((0100644, a1.id), self.store[c1.tree]['a'])
70
self.assertEqual((0100644, a2.id), self.store[c2.tree]['a'])
73
c1, c2 = build_commit_graph(self.store, [[1], [2, 1]],
74
attrs={1: {'message': 'Hooray!'}})
75
self.assertEqual('Hooray!', c1.message)
76
self.assertEqual('Commit 2', c2.message)
78
def test_commit_time(self):
79
c1, c2, c3 = build_commit_graph(self.store, [[1], [2, 1], [3, 2]],
80
attrs={1: {'commit_time': 124},
81
2: {'commit_time': 123}})
82
self.assertEqual(124, c1.commit_time)
83
self.assertEqual(123, c2.commit_time)
84
self.assertTrue(c2.commit_time < c1.commit_time < c3.commit_time)