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 CellRendererGraph functionality."""
 
19
 
from gi.repository import Gtk
 
25
 
from bzrlib.plugins.gtk.branchview.graphcell import CellRendererGraph
 
28
 
class CellRendererGraphTestCase(tests.TestCase):
 
30
 
    def test_columns_len(self):
 
31
 
        cell = CellRendererGraph()
 
32
 
        self.assertEqual(0, cell.columns_len)
 
34
 
        self.assertEqual(1, cell.columns_len)
 
36
 
    def test_props_writeonly(self):
 
37
 
        # Props can be set, but not read, though they can be accessed
 
39
 
        cell = CellRendererGraph()
 
40
 
        cell.props.node = (1, 0)
 
41
 
        cell.props.tags = ['2.0']
 
42
 
        cell.props.in_lines = ((1, 2, 1.0))
 
43
 
        cell.props.out_lines = ((1, 3, 1.0))
 
44
 
        self.assertEqual((1, 0), cell.node)
 
45
 
        self.assertRaises(TypeError, cell.props, 'node')
 
46
 
        self.assertEqual(['2.0'], cell.tags)
 
47
 
        self.assertRaises(TypeError, cell.props, 'tags')
 
48
 
        self.assertEqual(((1, 2, 1.0)), cell.in_lines)
 
49
 
        self.assertRaises(TypeError, cell.props, 'in_lines')
 
50
 
        self.assertEqual(((1, 3, 1.0)), cell.out_lines)
 
51
 
        self.assertRaises(TypeError, cell.props, 'out_lines')
 
53
 
    def test_do_activate(self):
 
54
 
        # The cell cannot be activated. It returns True to indicate the
 
56
 
        cell = CellRendererGraph()
 
58
 
            True, cell.do_activate(None, None, None, None, None))
 
60
 
    def test_do_editing_started(self):
 
61
 
        # The cell cannot be edited. It returns None.
 
62
 
        cell = CellRendererGraph()
 
64
 
            None, cell.do_editing_started(None, None, None, None, None))
 
66
 
    def test_do_get_size(self):
 
67
 
        # The layout offset and size is based by cell.box_size(widget)
 
68
 
        # box_size is cached, and this can be set ensure a predictable result.
 
69
 
        cell = CellRendererGraph()
 
72
 
        treeview = Gtk.TreeView()
 
74
 
            (0, 0, 44, 22), cell.do_get_size(treeview, None))
 
76
 
    def test_do_render(self):
 
77
 
        # A simple test to verify the method is defined. Cairo is broken
 
78
 
        # in gi--contexts cannot get created.
 
79
 
        cell = CellRendererGraph()
 
81
 
            "<type 'instancemethod'>", str(type(cell.do_render)))