/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

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
 
 
20
 
from bzrlib.plugins.gtk.diff import DiffWindow
21
 
from bzrlib.tests import TestCase
22
 
 
23
 
class TestDiffWindow(TestCase):
 
19
import os
 
20
 
 
21
from bzrlib import tests
 
22
 
 
23
from bzrlib.plugins.gtk.diff import DiffView, iter_changes_to_status
 
24
 
 
25
 
 
26
class TestDiffViewSimple(tests.TestCase):
 
27
 
24
28
    def test_parse_colordiffrc(self):
25
29
        colordiffrc = '''\
26
30
newtext=blue
35
39
                'oldtext': 'Red',
36
40
                'diffstuff': '#ffff00',
37
41
        }
38
 
        parsed_colors = DiffWindow.parse_colordiffrc(StringIO(colordiffrc))
 
42
        parsed_colors = DiffView.parse_colordiffrc(StringIO(colordiffrc))
39
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)