1
# Copyright (C) 2011 Curtis Hovey <sinzui.is@verizon.net>
 
 
3
# This program is free software; you can redistribute it and/or modify
 
 
4
# it under the terms of the GNU General Public License as published by
 
 
5
# the Free Software Foundation; either version 2 of the License, or
 
 
6
# (at your option) any later version.
 
 
8
# This program is distributed in the hope that it will be useful,
 
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 
11
# GNU General Public License for more details.
 
 
13
# You should have received a copy of the GNU General Public License
 
 
14
# along with this program; if not, write to the Free Software
 
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
17
"""Test the BranchTreeModel functionality."""
 
 
28
from bzrlib.plugins.gtk.branchview.treemodel import BranchTreeModel
 
 
31
class BranchTreeModelTestCase(tests.TestCaseWithMemoryTransport):
 
 
33
    def make_test_branch(self, revid, message=None, committer=None):
 
 
34
        builder = self.make_branch_builder('test')
 
 
35
        builder.build_snapshot(
 
 
36
            revid, None, [('add', ('', 'root-id', 'directory', None))],
 
 
37
            message=message, committer=committer)
 
 
38
        return builder.get_branch()
 
 
41
        branch = self.make_test_branch('A')
 
 
42
        revision = branch.repository.get_revision('A')
 
 
43
        branch.tags.set_tag('2.0', revision.revision_id)
 
 
44
        model = BranchTreeModel(branch, [])
 
 
45
        self.assertEqual(branch, model.branch)
 
 
46
        self.assertEqual(branch.repository, model.repository)
 
 
47
        self.assertEqual({'A': [u'2.0']}, model.tags)
 
 
48
        self.assertEqual({}, model.revisions)
 
 
49
        self.assertEqual([], model.line_graph_data)
 
 
51
    def test_add_tag_create(self):
 
 
52
        branch = self.make_test_branch('A')
 
 
53
        revision = branch.repository.get_revision('A')
 
 
54
        model = BranchTreeModel(branch, [])
 
 
55
        model.add_tag('2.0', revision.revision_id)
 
 
56
        self.assertEqual({'A': [u'2.0']}, model.tags)
 
 
58
    def test_add_tag_append(self):
 
 
59
        branch = self.make_test_branch('A')
 
 
60
        revision = branch.repository.get_revision('A')
 
 
61
        branch.tags.set_tag('2.0', revision.revision_id)
 
 
62
        model = BranchTreeModel(branch, [])
 
 
63
        model.add_tag('2.1', revision.revision_id)
 
 
64
        self.assertEqual({'A': ['2.0', '2.1']}, model.tags)
 
 
66
    def test_line_graph_item_to_model_row(self):
 
 
67
        branch = self.make_test_branch(
 
 
68
            'A', message='badger', committer='fnord')
 
 
69
        revision = branch.repository.get_revision('A')
 
 
70
        branch.tags.set_tag('2.0', revision.revision_id)
 
 
71
        model = BranchTreeModel(branch, [])
 
 
73
            revision.revision_id, (1, 0), (5, 6, 0.5), ('B'), ('C'), [12, 34])
 
 
74
        row = model._line_graph_item_to_model_row(0, data_item)
 
 
75
        self.assertEqual(revision.revision_id, row[0], 'Wrong revid.')
 
 
76
        self.assertEqual((1, 0), row[1], 'Wrong node.')
 
 
77
        self.assertEqual((5, 6, 0.5), row[2], 'Wrong lines.')
 
 
78
        self.assertEqual([], row[3], 'Wrong last_lines.')
 
 
79
        self.assertEqual('12.34', row[4], 'Wrong revno.')
 
 
80
        self.assertEqual('badger', row[5], 'Wrong summary.')
 
 
81
        self.assertEqual('badger', row[6], 'Wrong message.')
 
 
82
        self.assertEqual('fnord', row[7], 'wrong committer.')
 
 
84
            strftime("%Y-%m-%d %H:%M", localtime(revision.timestamp)),
 
 
85
            row[8], 'Wrong timestamp.')
 
 
86
        self.assertEqual(revision, row[9], 'Wrong revision.')
 
 
87
        self.assertEqual(('B'), row[10], 'Wrong parents.')
 
 
88
        self.assertEqual(('C'), row[11], 'Wrong children.')
 
 
89
        self.assertEqual(['2.0'], row[12], 'Wrong tags.')
 
 
90
        self.assertEqual('fnord', row[13], 'Wrong authors.')
 
 
92
    def test_set_line_graph_data(self):
 
 
93
        branch = self.make_test_branch(
 
 
94
            'A', message='badger', committer='fnord')
 
 
95
        rev_id = branch.repository.get_revision('A').revision_id
 
 
96
        model = BranchTreeModel(branch, [])
 
 
97
        data = [(rev_id, (2, 0), (3, 4, 0.5), None, None, [1, 2])]
 
 
98
        model.set_line_graph_data(data)
 
 
99
        self.assertEqual(data, model.line_graph_data)
 
 
100
        tree_iter = model.get_iter_first()
 
 
101
        self.assertEqual(rev_id, model.get_value(tree_iter, 0))