/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to tests/test_graphcell.py

  • Committer: Curtis Hovey
  • Date: 2011-09-04 20:04:03 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110904200403-t38t3o2q1j600dho
Added missing tests for BranchTreeModel and CellRendererGraph.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2011 Curtis Hovey <sinzui.is@verizon.net>
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
"""Test the CellRendererGraph functionality."""
 
18
 
 
19
from gi.repository import Gtk
 
20
 
 
21
from bzrlib import (
 
22
    tests,
 
23
    )
 
24
 
 
25
from bzrlib.plugins.gtk.branchview.graphcell import CellRendererGraph
 
26
 
 
27
 
 
28
class CellRendererGraphTestCase(tests.TestCase):
 
29
 
 
30
    def test_columns_len(self):
 
31
        cell = CellRendererGraph()
 
32
        self.assertEqual(0, cell.columns_len)
 
33
        cell.columns_len = 1
 
34
        self.assertEqual(1, cell.columns_len)
 
35
 
 
36
    def test_props_writeonly(self):
 
37
        # Props can be set, but not read, though they can be accessed
 
38
        # as attributes
 
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')
 
52
 
 
53
    def test_do_activate(self):
 
54
        # The cell cannot be activated. It returns True to indicate the
 
55
        # event is handled.
 
56
        cell = CellRendererGraph()
 
57
        self.assertEqual(
 
58
            True, cell.do_activate(None, None, None, None, None))
 
59
 
 
60
    def test_do_editing_started(self):
 
61
        # The cell cannot be edited. It returns None.
 
62
        cell = CellRendererGraph()
 
63
        self.assertEqual(
 
64
            None, cell.do_editing_started(None, None, None, None, None))
 
65
 
 
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()
 
70
        cell.columns_len = 1
 
71
        cell._box_size = 21
 
72
        treeview = Gtk.TreeView()
 
73
        self.assertEqual(
 
74
            (0, 0, 44, 22), cell.do_get_size(treeview, None))
 
75
 
 
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()
 
80
        self.assertEqual(
 
81
            "<type 'instancemethod'>", str(type(cell.do_render)))