/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
232.1.4 by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines.
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2007 Adeodato Simó <dato@net.com.org.es>
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
from cStringIO import StringIO
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
19
import os
232.1.4 by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines.
20
278.1.13 by John Arbash Meinel
minor cleanup
21
from bzrlib import tests
22
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
23
from bzrlib.plugins.gtk.diff import DiffView, _iter_changes_to_status
24
25
26
class TestDiffViewSimple(tests.TestCase):
278.1.13 by John Arbash Meinel
minor cleanup
27
232.1.4 by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines.
28
    def test_parse_colordiffrc(self):
29
        colordiffrc = '''\
30
newtext=blue
31
oldtext = Red
32
# now a comment and a blank line
33
34
diffstuff = #ffff00  
35
  # another comment preceded by whitespace
36
'''
37
        colors = {
38
                'newtext': 'blue',
39
                'oldtext': 'Red',
40
                'diffstuff': '#ffff00',
41
        }
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
42
        parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc))
232.1.4 by Adeodato Simó
Add a test for parse_colordiffrc, and fix the function to handle empty lines.
43
        self.assertEqual(colors, parsed_colors)
278.1.29 by John Arbash Meinel
Start testing with Unicode data.
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)