/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: John Arbash Meinel
  • Date: 2007-10-02 23:08:12 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002230812-h8i6pq8fwvodute4
Start testing with Unicode data.
It seems there is some brokenness with serializing Unicode messages.
But otherwise everything seems to be working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
from cStringIO import StringIO
 
19
import os
19
20
 
20
21
from bzrlib import tests
21
22
 
22
 
from bzrlib.plugins.gtk.diff import DiffView
23
 
 
24
 
 
25
 
class TestDiffView(tests.TestCase):
 
23
from bzrlib.plugins.gtk.diff import DiffView, _iter_changes_to_status
 
24
 
 
25
 
 
26
class TestDiffViewSimple(tests.TestCase):
26
27
 
27
28
    def test_parse_colordiffrc(self):
28
29
        colordiffrc = '''\
40
41
        }
41
42
        parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc))
42
43
        self.assertEqual(colors, parsed_colors)
 
44
 
 
45
 
 
46
class TestDiffView(tests.TestCaseWithTransport):
 
47
 
 
48
    def test_unicode(self):
 
49
        from bzrlib.tests.test_diff import UnicodeFilename
 
50
        self.requireFeature(UnicodeFilename)
 
51
 
 
52
        tree = self.make_branch_and_tree('tree')
 
53
        self.build_tree([u'tree/\u03a9'])
 
54
        tree.add([u'\u03a9'], ['omega-id'])
 
55
 
 
56
        view = DiffView()
 
57
        view.set_trees(tree, tree.basis_tree())
 
58
        view.show_diff(None)
 
59
        buf = view.buffer
 
60
        start, end = buf.get_bounds()
 
61
        text = buf.get_text(start, end)
 
62
        self.assertContainsRe(text,
 
63
            "=== added file '\xce\xa9'\n"
 
64
            '--- .*\t1970-01-01 00:00:00 \\+0000\n'
 
65
            r'\+\+\+ .*\t\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d [+-]\d\d\d\d\n'
 
66
            '@@ -0,0 \\+1,1 @@\n'
 
67
            '\\+contents of tree/\xce\xa9\n'
 
68
            '\n'
 
69
            )
 
70
 
 
71
 
 
72
class Test_IterChangesToStatus(tests.TestCaseWithTransport):
 
73
 
 
74
    def assertStatusEqual(self, expected, tree):
 
75
        values = _iter_changes_to_status(tree.basis_tree(), tree)
 
76
        self.assertEqual(expected, values)
 
77
 
 
78
    def test_status_added(self):
 
79
        tree = self.make_branch_and_tree('tree')
 
80
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
81
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
82
 
 
83
        self.assertStatusEqual(
 
84
            [('a-id', 'a', 'added', 'a'),
 
85
             ('b-id', 'b', 'added', 'b/'),
 
86
             ('c-id', 'b/c', 'added', 'b/c'),
 
87
            ], tree)
 
88
 
 
89
    def test_status_renamed(self):
 
90
        tree = self.make_branch_and_tree('tree')
 
91
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
92
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
93
        rev_id1 = tree.commit('one')
 
94
 
 
95
        tree.rename_one('b', 'd')
 
96
        tree.rename_one('a', 'd/a')
 
97
 
 
98
        self.assertStatusEqual(
 
99
            [('b-id', 'd', 'renamed', 'b/ => d/'),
 
100
             ('a-id', 'd/a', 'renamed', 'a => d/a'),
 
101
            ], tree)
 
102
 
 
103
    def test_status_modified(self):
 
104
        tree = self.make_branch_and_tree('tree')
 
105
        self.build_tree(['tree/a'])
 
106
        tree.add(['a'], ['a-id'])
 
107
        rev_id1 = tree.commit('one')
 
108
 
 
109
        self.build_tree_contents([('tree/a', 'new contents for a\n')])
 
110
 
 
111
        self.assertStatusEqual(
 
112
            [('a-id', 'a', 'modified', 'a'),
 
113
            ], tree)
 
114
 
 
115
    def test_status_renamed_and_modified(self):
 
116
        tree = self.make_branch_and_tree('tree')
 
117
        self.build_tree(['tree/a', 'tree/b/', 'tree/b/c'])
 
118
        tree.add(['a', 'b', 'b/c'], ['a-id', 'b-id', 'c-id'])
 
119
        rev_id1 = tree.commit('one')
 
120
 
 
121
        tree.rename_one('b', 'd')
 
122
        tree.rename_one('a', 'd/a')
 
123
        self.build_tree_contents([('tree/d/a', 'new contents for a\n'),
 
124
                                  ('tree/d/c', 'new contents for c\n'),
 
125
                                 ])
 
126
        # 'c' is not considered renamed, because only its parent was moved, it
 
127
        # stayed in the same directory
 
128
 
 
129
        self.assertStatusEqual(
 
130
            [('b-id', 'd', 'renamed', 'b/ => d/'),
 
131
             ('a-id', 'd/a', 'renamed and modified', 'a => d/a'),
 
132
             ('c-id', 'd/c', 'modified', 'd/c'),
 
133
            ], tree)
 
134
 
 
135
    def test_status_kind_changed(self):
 
136
        tree = self.make_branch_and_tree('tree')
 
137
        self.build_tree(['tree/a', 'tree/b'])
 
138
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
139
        tree.commit('one')
 
140
 
 
141
        os.remove('tree/a')
 
142
        self.build_tree(['tree/a/'])
 
143
        # XXX:  This is technically valid, and the file list handles it fine,
 
144
        #       but 'show_diff_trees()' does not, so we skip this part of the
 
145
        #       test for now.
 
146
        # tree.rename_one('b', 'c')
 
147
        # os.remove('tree/c')
 
148
        # self.build_tree(['tree/c/'])
 
149
 
 
150
        self.assertStatusEqual(
 
151
            [('a-id', 'a', 'kind changed', 'a => a/'),
 
152
            # ('b-id', 'c', True, 'b => c/', 'renamed and modified'),
 
153
            ], tree)
 
154
 
 
155
    def test_status_removed(self):
 
156
        tree = self.make_branch_and_tree('tree')
 
157
        self.build_tree(['tree/a', 'tree/b/'])
 
158
        tree.add(['a', 'b'], ['a-id', 'b-id'])
 
159
        tree.commit('one')
 
160
 
 
161
        os.remove('tree/a')
 
162
        tree.remove('b', force=True)
 
163
 
 
164
        self.assertStatusEqual(
 
165
            [('a-id', 'a', 'removed', 'a'),
 
166
             ('b-id', 'b', 'removed', 'b/'),
 
167
            ], tree)