/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_ls.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-18 18:18:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4461.
  • Revision ID: john@arbash-meinel.com-20090618181836-biodfkat9a8eyzjz
The new add_inventory_by_delta is returning a CHKInventory when mapping from NULL
Which is completely valid, but 'broke' one of the tests.
So to fix it, changed the test to use CHKInventories on both sides, and add an __eq__
member. The nice thing is that CHKInventory.__eq__ is fairly cheap, since it only
has to check the root keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""External tests of 'bzr ls'"""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib import ignores
 
22
from bzrlib.tests import TestCaseWithTransport
 
23
 
 
24
 
 
25
class TestLS(TestCaseWithTransport):
 
26
 
 
27
    def setUp(self):
 
28
        super(TestLS, self).setUp()
 
29
 
 
30
        # Create a simple branch that can be used in testing
 
31
        ignores._set_user_ignores(['user-ignore'])
 
32
 
 
33
        self.wt = self.make_branch_and_tree('.')
 
34
        self.build_tree_contents([
 
35
                                 ('.bzrignore', '*.pyo\n'),
 
36
                                 ('a', 'hello\n'),
 
37
                                 ])
 
38
 
 
39
    def ls_equals(self, value, args=None, recursive=True):
 
40
        command = 'ls'
 
41
        if args is not None:
 
42
            command += ' ' + args
 
43
        if recursive:
 
44
            command += ' -R'
 
45
        out, err = self.run_bzr(command)
 
46
        self.assertEqual('', err)
 
47
        self.assertEqualDiff(value, out)
 
48
 
 
49
    def test_ls_null_verbose(self):
 
50
        # Can't supply both
 
51
        self.run_bzr_error(['Cannot set both --verbose and --null'],
 
52
                           'ls --verbose --null')
 
53
 
 
54
    def test_ls_basic(self):
 
55
        """Test the abilities of 'bzr ls'"""
 
56
        self.ls_equals('.bzrignore\na\n')
 
57
        self.ls_equals('?        .bzrignore\n'
 
58
                       '?        a\n',
 
59
                       '--verbose')
 
60
        self.ls_equals('.bzrignore\n'
 
61
                       'a\n',
 
62
                       '--unknown')
 
63
        self.ls_equals('', '--ignored')
 
64
        self.ls_equals('', '--versioned')
 
65
        self.ls_equals('', '-V')
 
66
        self.ls_equals('.bzrignore\n'
 
67
                       'a\n',
 
68
                       '--unknown --ignored --versioned')
 
69
        self.ls_equals('.bzrignore\n'
 
70
                       'a\n',
 
71
                       '--unknown --ignored -V')
 
72
        self.ls_equals('', '--ignored --versioned')
 
73
        self.ls_equals('', '--ignored -V')
 
74
        self.ls_equals('.bzrignore\0a\0', '--null')
 
75
 
 
76
    def test_ls_added(self):
 
77
        self.wt.add(['a'])
 
78
        self.ls_equals('?        .bzrignore\n'
 
79
                       'V        a\n',
 
80
                       '--verbose')
 
81
        self.wt.commit('add')
 
82
 
 
83
        self.build_tree(['subdir/'])
 
84
        self.ls_equals('?        .bzrignore\n'
 
85
                       'V        a\n'
 
86
                       '?        subdir/\n'
 
87
                       , '--verbose')
 
88
        self.build_tree(['subdir/b'])
 
89
        self.wt.add(['subdir/', 'subdir/b', '.bzrignore'])
 
90
        self.ls_equals('V        .bzrignore\n'
 
91
                       'V        a\n'
 
92
                       'V        subdir/\n'
 
93
                       'V        subdir/b\n'
 
94
                       , '--verbose')
 
95
 
 
96
    def test_show_ids(self):
 
97
        self.build_tree(['subdir/'])
 
98
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
99
        self.ls_equals(
 
100
            '.bzrignore                                         \n'
 
101
            'a                                                  a-id\n'
 
102
            'subdir/                                            subdir-id\n',
 
103
            '--show-ids')
 
104
        self.ls_equals(
 
105
            '?        .bzrignore\n'
 
106
            'V        a                                         a-id\n'
 
107
            'V        subdir/                                   subdir-id\n',
 
108
            '--show-ids --verbose')
 
109
        self.ls_equals('.bzrignore\0\0'
 
110
                       'a\0a-id\0'
 
111
                       'subdir\0subdir-id\0', '--show-ids --null')
 
112
 
 
113
    def test_ls_no_recursive(self):
 
114
        self.build_tree(['subdir/', 'subdir/b'])
 
115
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
 
116
 
 
117
        self.ls_equals('.bzrignore\n'
 
118
                       'a\n'
 
119
                       'subdir/\n'
 
120
                       , recursive=False)
 
121
 
 
122
        self.ls_equals('V        .bzrignore\n'
 
123
                       'V        a\n'
 
124
                       'V        subdir/\n'
 
125
                       , '--verbose', recursive=False)
 
126
 
 
127
        # Check what happens in a sub-directory
 
128
        os.chdir('subdir')
 
129
        self.ls_equals('b\n')
 
130
        self.ls_equals('b\0'
 
131
                  , '--null')
 
132
        self.ls_equals('.bzrignore\n'
 
133
                       'a\n'
 
134
                       'subdir/\n'
 
135
                       'subdir/b\n'
 
136
                       , '--from-root')
 
137
        self.ls_equals('.bzrignore\0'
 
138
                       'a\0'
 
139
                       'subdir\0'
 
140
                       'subdir/b\0'
 
141
                       , '--from-root --null')
 
142
        self.ls_equals('.bzrignore\n'
 
143
                       'a\n'
 
144
                       'subdir/\n'
 
145
                       , '--from-root', recursive=False)
 
146
 
 
147
    def test_ls_path(self):
 
148
        """If a path is specified, files are listed with that prefix"""
 
149
        self.build_tree(['subdir/', 'subdir/b'])
 
150
        self.wt.add(['subdir', 'subdir/b'])
 
151
        self.ls_equals('subdir/b\n' ,
 
152
                       'subdir')
 
153
        os.chdir('subdir')
 
154
        self.ls_equals('../.bzrignore\n'
 
155
                       '../a\n'
 
156
                       '../subdir/\n'
 
157
                       '../subdir/b\n' ,
 
158
                       '..')
 
159
        self.ls_equals('../.bzrignore\0'
 
160
                       '../a\0'
 
161
                       '../subdir\0'
 
162
                       '../subdir/b\0' ,
 
163
                       '.. --null')
 
164
        self.ls_equals('?        ../.bzrignore\n'
 
165
                       '?        ../a\n'
 
166
                       'V        ../subdir/\n'
 
167
                       'V        ../subdir/b\n' ,
 
168
                       '.. --verbose')
 
169
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
 
170
                           'ls --from-root ..')
 
171
 
 
172
    def test_ls_revision(self):
 
173
        self.wt.add(['a'])
 
174
        self.wt.commit('add')
 
175
 
 
176
        self.build_tree(['subdir/'])
 
177
 
 
178
        # Check what happens when we supply a specific revision
 
179
        self.ls_equals('a\n', '--revision 1')
 
180
        self.ls_equals('V        a\n'
 
181
                       , '--verbose --revision 1')
 
182
 
 
183
        os.chdir('subdir')
 
184
        self.ls_equals('', '--revision 1')
 
185
 
 
186
    def test_ls_branch(self):
 
187
        """If a branch is specified, files are listed from it"""
 
188
        self.build_tree(['subdir/', 'subdir/b'])
 
189
        self.wt.add(['subdir', 'subdir/b'])
 
190
        self.wt.commit('committing')
 
191
        branch = self.make_branch('branchdir')
 
192
        branch.pull(self.wt.branch)
 
193
        self.ls_equals('branchdir/subdir/\n'
 
194
                       'branchdir/subdir/b\n',
 
195
                       'branchdir')
 
196
        self.ls_equals('branchdir/subdir/\n'
 
197
                       'branchdir/subdir/b\n',
 
198
                       'branchdir --revision 1')
 
199
 
 
200
    def test_ls_ignored(self):
 
201
        # Now try to do ignored files.
 
202
        self.wt.add(['a', '.bzrignore'])
 
203
 
 
204
        self.build_tree(['blah.py', 'blah.pyo', 'user-ignore'])
 
205
        self.ls_equals('.bzrignore\n'
 
206
                       'a\n'
 
207
                       'blah.py\n'
 
208
                       'blah.pyo\n'
 
209
                       'user-ignore\n'
 
210
                       )
 
211
        self.ls_equals('V        .bzrignore\n'
 
212
                       'V        a\n'
 
213
                       '?        blah.py\n'
 
214
                       'I        blah.pyo\n'
 
215
                       'I        user-ignore\n'
 
216
                       , '--verbose')
 
217
        self.ls_equals('blah.pyo\n'
 
218
                       'user-ignore\n'
 
219
                       , '--ignored')
 
220
        self.ls_equals('blah.py\n'
 
221
                       , '--unknown')
 
222
        self.ls_equals('.bzrignore\n'
 
223
                       'a\n'
 
224
                       , '--versioned')
 
225
        self.ls_equals('.bzrignore\n'
 
226
                       'a\n'
 
227
                       , '-V')
 
228
 
 
229
    def test_kinds(self):
 
230
        self.build_tree(['subdir/'])
 
231
        self.ls_equals('.bzrignore\n'
 
232
                       'a\n',
 
233
                       '--kind=file')
 
234
        self.ls_equals('subdir/\n',
 
235
                       '--kind=directory')
 
236
        self.ls_equals('',
 
237
                       '--kind=symlink')
 
238
        self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
 
239
 
 
240
    def test_ls_path_nonrecursive(self):
 
241
        self.ls_equals('%s/.bzrignore\n'
 
242
                       '%s/a\n'
 
243
                       % (self.test_dir, self.test_dir),
 
244
                       self.test_dir, recursive=False)