~jelmer/dulwich/lp-pqm

« back to all changes in this revision

Viewing changes to dulwich/tests/test_utils.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-10 15:29:16 UTC
  • mfrom: (426.1.1 lp-pqm)
  • Revision ID: launchpad@pqm.canonical.com-20110810152916-2ivg8kq9gdwd7gr5
[rs=jelmer] Update to upstream 930.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# test_utils.py -- Tests for git test utilities.
 
2
# Copyright (C) 2010 Google, Inc.
 
3
#
 
4
# This program is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU General Public License
 
6
 
 
7
# as published by the Free Software Foundation; either version 2
 
8
# of the License, or (at your option) any later version.
 
9
#
 
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.
 
14
#
 
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.
 
19
 
 
20
"""Tests for git test utilities."""
 
21
 
 
22
from dulwich.object_store import (
 
23
    MemoryObjectStore,
 
24
    )
 
25
from dulwich.objects import (
 
26
    Blob,
 
27
    )
 
28
from dulwich.tests import (
 
29
    TestCase,
 
30
    )
 
31
from utils import (
 
32
    make_object,
 
33
    build_commit_graph,
 
34
    )
 
35
 
 
36
 
 
37
class BuildCommitGraphTest(TestCase):
 
38
 
 
39
    def setUp(self):
 
40
        self.store = MemoryObjectStore()
 
41
 
 
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)
 
51
 
 
52
    def test_merge(self):
 
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)
 
58
 
 
59
    def test_missing_parent(self):
 
60
        self.assertRaises(ValueError, build_commit_graph, self.store,
 
61
                          [[1], [3, 2], [2, 1]])
 
62
 
 
63
    def test_trees(self):
 
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'])
 
71
 
 
72
    def test_attrs(self):
 
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)
 
77
 
 
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)