/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: Aaron Bentley
  • Date: 2008-05-08 23:23:47 UTC
  • mto: This revision was merged to the branch mainline in revision 492.
  • Revision ID: aaron@aaronbentley.com-20080508232347-ob7qsl91fg8vr4mi
Add tests for DiffController

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib import tests
22
22
 
23
 
from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
24
 
 
 
23
from bzrlib.plugins.gtk.diff import (
 
24
    DiffController,
 
25
    DiffView,
 
26
    iter_changes_to_status,
 
27
    )
 
28
eg_diff = """\
 
29
=== modified file 'tests/test_diff.py'
 
30
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
 
31
+++ tests/test_diff.py  2008-05-08 22:44:02 +0000
 
32
@@ -20,7 +20,11 @@
 
33
 
 
34
 from bzrlib import tests
 
35
 
 
36
-from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
 
37
+from bzrlib.plugins.gtk.diff import (
 
38
+    DiffController,
 
39
+    DiffView,
 
40
+    iter_changes_to_status,
 
41
+    )
 
42
 
 
43
 
 
44
 class TestDiffViewSimple(tests.TestCase):
 
45
"""
25
46
 
26
47
class TestDiffViewSimple(tests.TestCase):
27
48
 
69
90
            )
70
91
 
71
92
 
 
93
class MockDiffWidget(object):
 
94
 
 
95
    def set_diff_text_sections(self, sections):
 
96
        self.sections = list(sections)
 
97
 
 
98
 
 
99
class MockWindow(object):
 
100
    def __init__(self):
 
101
        self.diff = MockDiffWidget()
 
102
 
 
103
    def set_title(self, title):
 
104
        self.title = title
 
105
 
 
106
    def _get_save_path(self, basename):
 
107
        return 'save-path'
 
108
 
 
109
 
 
110
class TestDiffController(tests.TestCaseWithTransport):
 
111
 
 
112
    def get_controller(self):
 
113
        window = MockWindow()
 
114
        return DiffController('load-path', eg_diff.splitlines(True), window)
 
115
 
 
116
    def test_get_diff_sections(self):
 
117
        controller = self.get_controller()
 
118
        controller = DiffController('.', eg_diff.splitlines(True),
 
119
                                    controller.window)
 
120
        sections = list(controller.get_diff_sections())
 
121
        self.assertEqual('Complete Diff', sections[0][0])
 
122
        self.assertIs(None, sections[0][1])
 
123
        self.assertEqual(eg_diff, sections[0][2])
 
124
 
 
125
        self.assertEqual('tests/test_diff.py', sections[1][0])
 
126
        self.assertEqual('tests/test_diff.py', sections[1][1])
 
127
        self.assertEqual(''.join(eg_diff.splitlines(True)[1:]),
 
128
                         sections[1][2])
 
129
 
 
130
    def test_initialize_window(self):
 
131
        controller = self.get_controller()
 
132
        controller.initialize_window(controller.window)
 
133
        self.assertEqual(2, len(controller.window.diff.sections))
 
134
        self.assertEqual('load-path - diff', controller.window.title)
 
135
 
 
136
    def test_perform_save(self):
 
137
        self.build_tree_contents([('load-path', 'foo')])
 
138
        controller = self.get_controller()
 
139
        controller.perform_save(None)
 
140
        self.assertFileEqual('foo', 'save-path')
 
141
 
 
142
 
72
143
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
73
144
 
74
145
    def assertStatusEqual(self, expected, tree):