18
18
from cStringIO import StringIO
 
21
 
from bzrlib import errors, tests
 
22
 
from bzrlib.merge_directive import MergeDirective2
 
24
 
from bzrlib.plugins.gtk.diff import (
 
27
 
    iter_changes_to_status,
 
28
 
    MergeDirectiveController,
 
31
 
=== modified file 'tests/test_diff.py'
 
32
 
--- tests/test_diff.py  2008-03-11 13:18:28 +0000
 
33
 
+++ tests/test_diff.py  2008-05-08 22:44:02 +0000
 
36
 
 from bzrlib import tests
 
38
 
-from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
 
39
 
+from bzrlib.plugins.gtk.diff import (
 
42
 
+    iter_changes_to_status,
 
46
 
 class TestDiffViewSimple(tests.TestCase):
 
 
21
from bzrlib import tests
 
 
23
from bzrlib.plugins.gtk.diff import DiffView, _iter_changes_to_status
 
49
26
class TestDiffViewSimple(tests.TestCase):
 
 
94
 
class MockDiffWidget(object):
 
96
 
    def set_diff_text_sections(self, sections):
 
97
 
        self.sections = list(sections)
 
100
 
class MockWindow(object):
 
102
 
        self.diff = MockDiffWidget()
 
103
 
        self.merge_successful = False
 
105
 
    def set_title(self, title):
 
108
 
    def _get_save_path(self, basename):
 
111
 
    def _get_merge_target(self):
 
117
 
    def _merge_successful(self):
 
118
 
        self.merge_successful = True
 
120
 
    def _conflicts(self):
 
121
 
        self.conflicts = True
 
123
 
    def _handle_error(self, e):
 
124
 
        self.handled_error = e
 
127
 
class TestDiffController(tests.TestCaseWithTransport):
 
129
 
    def get_controller(self):
 
130
 
        window = MockWindow()
 
131
 
        return DiffController('load-path', eg_diff.splitlines(True), window)
 
133
 
    def test_get_diff_sections(self):
 
134
 
        controller = self.get_controller()
 
135
 
        controller = DiffController('.', eg_diff.splitlines(True),
 
137
 
        sections = list(controller.get_diff_sections())
 
138
 
        self.assertEqual('Complete Diff', sections[0][0])
 
139
 
        self.assertIs(None, sections[0][1])
 
140
 
        self.assertEqual(eg_diff, sections[0][2])
 
142
 
        self.assertEqual('tests/test_diff.py', sections[1][0])
 
143
 
        self.assertEqual('tests/test_diff.py', sections[1][1])
 
144
 
        self.assertEqual(''.join(eg_diff.splitlines(True)[1:]),
 
147
 
    def test_initialize_window(self):
 
148
 
        controller = self.get_controller()
 
149
 
        controller.initialize_window(controller.window)
 
150
 
        self.assertEqual(2, len(controller.window.diff.sections))
 
151
 
        self.assertEqual('load-path - diff', controller.window.title)
 
153
 
    def test_perform_save(self):
 
154
 
        self.build_tree_contents([('load-path', 'foo')])
 
155
 
        controller = self.get_controller()
 
156
 
        controller.perform_save(None)
 
157
 
        self.assertFileEqual('foo', 'save-path')
 
160
 
class TestMergeDirectiveController(tests.TestCaseWithTransport):
 
162
 
    def make_this_other_directive(self):
 
163
 
        this = self.make_branch_and_tree('this')
 
164
 
        this.commit('first commit')
 
165
 
        other = this.bzrdir.sprout('other').open_workingtree()
 
166
 
        self.build_tree_contents([('other/foo', 'bar')])
 
168
 
        other.commit('second commit')
 
171
 
            directive = MergeDirective2.from_objects(other.branch.repository,
 
172
 
                                                     other.last_revision(), 0,
 
176
 
        return this, other, directive
 
178
 
    def make_merged_window(self, directive):
 
179
 
        window = MockWindow()
 
180
 
        controller = MergeDirectiveController('directive', directive, window)
 
181
 
        controller.perform_merge(window)
 
184
 
    def test_perform_merge_success(self):
 
185
 
        this, other, directive = self.make_this_other_directive()
 
186
 
        window = self.make_merged_window(directive)
 
187
 
        self.assertTrue(window.merge_successful)
 
188
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
 
189
 
        self.assertFileEqual('bar', 'this/foo')
 
191
 
    def test_perform_merge_conflicts(self):
 
192
 
        this, other, directive = self.make_this_other_directive()
 
193
 
        self.build_tree_contents([('this/foo', 'bar')])
 
195
 
        this.commit('message')
 
196
 
        window = self.make_merged_window(directive)
 
197
 
        self.assertFalse(window.merge_successful)
 
198
 
        self.assertTrue(window.conflicts)
 
199
 
        self.assertEqual(other.last_revision(), this.get_parent_ids()[1])
 
200
 
        self.assertFileEqual('bar', 'this/foo')
 
202
 
    def test_perform_merge_uncommitted_changes(self):
 
203
 
        this, other, directive = self.make_this_other_directive()
 
204
 
        self.build_tree_contents([('this/foo', 'bar')])
 
206
 
        window = self.make_merged_window(directive)
 
207
 
        self.assertIsInstance(window.handled_error, errors.UncommittedChanges)
 
210
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
 
212
74
    def assertStatusEqual(self, expected, tree):
 
213
 
        values = iter_changes_to_status(tree.basis_tree(), tree)
 
 
75
        values = _iter_changes_to_status(tree.basis_tree(), tree)
 
214
76
        self.assertEqual(expected, values)
 
216
78
    def test_status_added(self):