/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_diff.py

  • Committer: Mikkel Kamstrup Erlandsen
  • Date: 2011-09-28 07:45:39 UTC
  • mto: This revision was merged to the branch mainline in revision 740.
  • Revision ID: mikkel.kamstrup@gmail.com-20110928074539-qxl1yn1bkjel6ir0
Add X-GNOME-Autostart-Delay=30 to bzr-notify.desktop

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
 
18
from cStringIO import StringIO
18
19
import os
19
20
 
20
 
from gi.repository import Gtk
21
 
 
22
21
from bzrlib import (
23
22
    conflicts,
24
23
    errors,
32
31
 
33
32
from bzrlib.plugins.gtk.diff import (
34
33
    DiffController,
35
 
    DiffFileView,
36
34
    DiffView,
37
 
    DiffWidget,
38
 
    DiffWindow,
39
 
    have_gtksourceview,
40
35
    iter_changes_to_status,
41
36
    MergeDirectiveController,
42
37
    )
43
 
from bzrlib.plugins.gtk.tests import MockMethod
44
 
 
45
 
 
46
38
eg_diff = """\
47
39
=== modified file 'tests/test_diff.py'
48
40
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
62
54
 class TestDiffViewSimple(tests.TestCase):
63
55
"""
64
56
 
65
 
 
66
 
class FakeDiffFileView(DiffFileView):
67
 
 
68
 
    SHOW_WIDGETS = False
69
 
 
70
 
 
71
 
class DiffFileViewTestCase(tests.TestCase):
72
 
 
73
 
    def test_init_construct(self):
74
 
        view = FakeDiffFileView()
75
 
        self.assertIsNot(None, view.buffer)
76
 
        self.assertIsNot(None, view.sourceview)
77
 
        self.assertIs(False, view.sourceview.props.editable)
78
 
        font_desc = view.sourceview.get_style_context().get_font(
79
 
            Gtk.StateFlags.NORMAL)
80
 
        self.assertIn('Monospace', font_desc.get_family())
81
 
 
82
 
    def test_init_construct_have_gtksourceview(self):
83
 
        if not have_gtksourceview:
84
 
            return
85
 
        view = FakeDiffFileView()
86
 
        self.assertEqual('Diff', view.buffer.get_language().get_name())
87
 
        self.assertIs(True, view.buffer.get_highlight_syntax())
 
57
class TestDiffViewSimple(tests.TestCase):
 
58
 
 
59
    def test_parse_colordiffrc(self):
 
60
        colordiffrc = '''\
 
61
newtext=blue
 
62
oldtext = Red
 
63
# now a comment and a blank line
 
64
 
 
65
diffstuff = #ffff00  
 
66
  # another comment preceded by whitespace
 
67
'''
 
68
        colors = {
 
69
                'newtext': 'blue',
 
70
                'oldtext': 'Red',
 
71
                'diffstuff': '#ffff00',
 
72
        }
 
73
        parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc))
 
74
        self.assertEqual(colors, parsed_colors)
88
75
 
89
76
 
90
77
class TestDiffView(tests.TestCaseWithTransport):
101
88
        view.show_diff(None)
102
89
        buf = view.buffer
103
90
        start, end = buf.get_bounds()
104
 
        text = buf.get_text(start, end, True)
 
91
        text = buf.get_text(start, end)
105
92
        self.assertContainsRe(text,
106
93
            "=== added file '\xce\xa9'\n"
107
94
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
112
99
            )
113
100
 
114
101
 
115
 
 
116
 
class FakeDiffWidget(DiffWidget):
117
 
 
118
 
    SHOW_WIDGETS = False
119
 
 
120
 
 
121
 
class TestDiffWidget(tests.TestCaseWithTransport):
122
 
 
123
 
    def test_treeview_cursor_cb(self):
124
 
        widget = FakeDiffWidget()
125
 
        widget.set_diff_text_sections(
126
 
            [('', None, 'patch1'), ('a', 'a', 'patch2')])
127
 
        widget.treeview.set_cursor(Gtk.TreePath(path=1), None, False)
128
 
        widget._treeview_cursor_cb(None)
129
 
        self.assertTrue('patch2', widget.diff_view.buffer.props.text)
130
 
 
131
 
    def test_treeview_cursor_cb_with_destroyed_treeview(self):
132
 
        widget = FakeDiffWidget()
133
 
        widget.set_diff_text_sections(
134
 
            [('', None, 'patch1'), ('a', 'a', 'patch2')])
135
 
        MockMethod.bind(self, widget.diff_view, 'show_diff')
136
 
        widget.treeview.destroy()
137
 
        widget._treeview_cursor_cb(None)
138
 
        self.assertFalse(widget.diff_view.show_diff.called)
139
 
 
140
 
 
141
 
class FakeDiffWindow(DiffWindow):
142
 
 
143
 
    SHOW_WIDGETS = False
144
 
 
145
 
 
146
 
class DiffWindowTestCase(tests.TestCaseWithTransport):
147
 
 
148
 
    def test_init(self):
149
 
        window = DiffWindow()
150
 
        self.assertEqual('bzr diff', window.props.title)
151
 
        self.assertEqual(0, window.props.border_width)
152
 
 
153
 
    def test_init_construct_without_operations(self):
154
 
        window = DiffWindow()
155
 
        widgets = window.vbox.get_children()
156
 
        self.assertEqual(2, len(widgets))
157
 
        self.assertIsInstance(widgets[0], Gtk.MenuBar)
158
 
        self.assertIsInstance(widgets[1], DiffWidget)
159
 
 
160
 
    def test_init_construct_with_operations(self):
161
 
        method = MockMethod()
162
 
        window = DiffWindow(operations=[('title', method)])
163
 
        widgets = window.vbox.get_children()
164
 
        self.assertEqual(3, len(widgets))
165
 
        self.assertIsInstance(widgets[0], Gtk.MenuBar)
166
 
        self.assertIsInstance(widgets[1], Gtk.HButtonBox)
167
 
        self.assertIsInstance(widgets[2], DiffWidget)
168
 
 
169
 
    def test_get_menu_bar(self):
170
 
        window = DiffWindow()
171
 
        menu_bar = window._get_menu_bar()
172
 
        self.assertIsNot(None, menu_bar)
173
 
        menus = menu_bar.get_children()
174
 
        self.assertEqual(1, len(menus))
175
 
        self.assertEqual('_View', menus[0].props.label)
176
 
        sub_menu = menus[0].get_submenu()
177
 
        self.assertIsNot(None, sub_menu)
178
 
        items = sub_menu.get_children()
179
 
        self.assertEqual(1, len(items))
180
 
        menus[0].get_submenu().get_children()[0].props.label
181
 
        self.assertEqual('Wrap _Long Lines', items[0].props.label)
182
 
 
183
 
    def test_get_button_bar_with_none(self):
184
 
        window = DiffWindow()
185
 
        self.assertIs(None, window._get_button_bar(None))
186
 
 
187
 
    def test_get_button_bar_with_operations(self):
188
 
        window = DiffWindow()
189
 
        method = MockMethod()
190
 
        button_bar = window._get_button_bar([('title', method)])
191
 
        self.assertIsNot(None, button_bar)
192
 
        buttons = button_bar.get_children()
193
 
        self.assertEqual(1, len(buttons))
194
 
        self.assertEqual('title', buttons[0].props.label)
195
 
        buttons[0].emit('clicked')
196
 
        self.assertIs(True, method.called)
197
 
 
198
 
 
199
 
 
200
102
class MockDiffWidget(object):
201
103
 
202
104
    def set_diff_text_sections(self, sections):