~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-03 22:30:56 UTC
  • mfrom: (3644.2.13 index_builder_cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20080903223056-b108iytb38xkznci
(jam) Streamline BTreeBuilder.add_node et al to make btree creation
        faster.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2012 Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""External tests of 'bzr ls'"""
18
18
 
19
 
from bzrlib import (
20
 
    ignores,
21
 
    tests,
22
 
    )
23
 
from bzrlib.tests.matchers import ContainsNoVfsCalls
24
 
 
25
 
 
26
 
class TestLS(tests.TestCaseWithTransport):
 
19
import os
 
20
 
 
21
from bzrlib import ignores
 
22
from bzrlib.tests import TestCaseWithTransport
 
23
 
 
24
 
 
25
class TestLS(TestCaseWithTransport):
27
26
 
28
27
    def setUp(self):
29
28
        super(TestLS, self).setUp()
30
 
 
 
29
        
31
30
        # Create a simple branch that can be used in testing
32
31
        ignores._set_user_ignores(['user-ignore'])
33
32
 
37
36
                                 ('a', 'hello\n'),
38
37
                                 ])
39
38
 
40
 
    def ls_equals(self, value, args=None, recursive=True, working_dir=None):
 
39
    def ls_equals(self, value, args=None):
41
40
        command = 'ls'
42
41
        if args is not None:
43
42
            command += ' ' + args
44
 
        if recursive:
45
 
            command += ' -R'
46
 
        out, err = self.run_bzr(command, working_dir=working_dir)
 
43
        out, err = self.run_bzr(command)
47
44
        self.assertEqual('', err)
48
45
        self.assertEqualDiff(value, out)
49
46
 
55
52
    def test_ls_basic(self):
56
53
        """Test the abilities of 'bzr ls'"""
57
54
        self.ls_equals('.bzrignore\na\n')
58
 
        self.ls_equals('.bzrignore\na\n', './')
59
55
        self.ls_equals('?        .bzrignore\n'
60
56
                       '?        a\n',
61
57
                       '--verbose')
81
77
                       'V        a\n',
82
78
                       '--verbose')
83
79
        self.wt.commit('add')
84
 
 
 
80
        
85
81
        self.build_tree(['subdir/'])
86
82
        self.ls_equals('?        .bzrignore\n'
87
83
                       'V        a\n'
101
97
        self.ls_equals(
102
98
            '.bzrignore                                         \n'
103
99
            'a                                                  a-id\n'
104
 
            'subdir/                                            subdir-id\n',
 
100
            'subdir                                             subdir-id\n', 
105
101
            '--show-ids')
106
102
        self.ls_equals(
107
103
            '?        .bzrignore\n'
108
104
            'V        a                                         a-id\n'
109
 
            'V        subdir/                                   subdir-id\n',
 
105
            'V        subdir/                                   subdir-id\n', 
110
106
            '--show-ids --verbose')
111
107
        self.ls_equals('.bzrignore\0\0'
112
108
                       'a\0a-id\0'
113
109
                       'subdir\0subdir-id\0', '--show-ids --null')
114
110
 
115
 
    def test_ls_no_recursive(self):
 
111
    def test_ls_recursive(self):
116
112
        self.build_tree(['subdir/', 'subdir/b'])
117
113
        self.wt.add(['a', 'subdir/', 'subdir/b', '.bzrignore'])
118
114
 
119
115
        self.ls_equals('.bzrignore\n'
120
116
                       'a\n'
121
 
                       'subdir/\n'
122
 
                       , recursive=False)
 
117
                       'subdir\n'
 
118
                       , '--non-recursive')
123
119
 
124
120
        self.ls_equals('V        .bzrignore\n'
125
121
                       'V        a\n'
126
122
                       'V        subdir/\n'
127
 
                       , '--verbose', recursive=False)
 
123
                       , '--verbose --non-recursive')
128
124
 
129
125
        # Check what happens in a sub-directory
130
 
        self.ls_equals('b\n', working_dir='subdir')
131
 
        self.ls_equals('b\0', '--null', working_dir='subdir')
132
 
        self.ls_equals('subdir/b\n', '--from-root', working_dir='subdir')
133
 
        self.ls_equals('subdir/b\0', '--from-root --null',
134
 
                       working_dir='subdir')
135
 
        self.ls_equals('subdir/b\n', '--from-root', recursive=False,
136
 
                       working_dir='subdir')
 
126
        os.chdir('subdir')
 
127
        self.ls_equals('b\n')
 
128
        self.ls_equals('b\0'
 
129
                  , '--null')
 
130
        self.ls_equals('.bzrignore\n'
 
131
                       'a\n'
 
132
                       'subdir\n'
 
133
                       'subdir/b\n'
 
134
                       , '--from-root')
 
135
        self.ls_equals('.bzrignore\0'
 
136
                       'a\0'
 
137
                       'subdir\0'
 
138
                       'subdir/b\0'
 
139
                       , '--from-root --null')
 
140
        self.ls_equals('.bzrignore\n'
 
141
                       'a\n'
 
142
                       'subdir\n'
 
143
                       , '--from-root --non-recursive')
137
144
 
138
145
    def test_ls_path(self):
139
146
        """If a path is specified, files are listed with that prefix"""
141
148
        self.wt.add(['subdir', 'subdir/b'])
142
149
        self.ls_equals('subdir/b\n' ,
143
150
                       'subdir')
 
151
        os.chdir('subdir')
144
152
        self.ls_equals('../.bzrignore\n'
145
153
                       '../a\n'
146
 
                       '../subdir/\n'
 
154
                       '../subdir\n'
147
155
                       '../subdir/b\n' ,
148
 
                       '..', working_dir='subdir')
 
156
                       '..')
149
157
        self.ls_equals('../.bzrignore\0'
150
158
                       '../a\0'
151
159
                       '../subdir\0'
152
160
                       '../subdir/b\0' ,
153
 
                       '.. --null', working_dir='subdir')
 
161
                       '.. --null')
154
162
        self.ls_equals('?        ../.bzrignore\n'
155
163
                       '?        ../a\n'
156
164
                       'V        ../subdir/\n'
157
165
                       'V        ../subdir/b\n' ,
158
 
                       '.. --verbose', working_dir='subdir')
159
 
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
160
 
                           'ls --from-root ..', working_dir='subdir')
 
166
                       '.. --verbose')
 
167
        self.run_bzr_error('cannot specify both --from-root and PATH',
 
168
                           'ls --from-root ..')
161
169
 
162
170
    def test_ls_revision(self):
163
171
        self.wt.add(['a'])
170
178
        self.ls_equals('V        a\n'
171
179
                       , '--verbose --revision 1')
172
180
 
173
 
        self.ls_equals('', '--revision 1', working_dir='subdir')
 
181
        os.chdir('subdir')
 
182
        self.ls_equals('', '--revision 1')
174
183
 
175
184
    def test_ls_branch(self):
176
185
        """If a branch is specified, files are listed from it"""
179
188
        self.wt.commit('committing')
180
189
        branch = self.make_branch('branchdir')
181
190
        branch.pull(self.wt.branch)
182
 
        self.ls_equals('branchdir/subdir/\n'
 
191
        self.ls_equals('branchdir/subdir\n'
183
192
                       'branchdir/subdir/b\n',
184
193
                       'branchdir')
185
 
        self.ls_equals('branchdir/subdir/\n'
 
194
        self.ls_equals('branchdir/subdir\n'
186
195
                       'branchdir/subdir/b\n',
187
196
                       'branchdir --revision 1')
188
197
 
217
226
 
218
227
    def test_kinds(self):
219
228
        self.build_tree(['subdir/'])
220
 
        self.ls_equals('.bzrignore\n'
221
 
                       'a\n',
 
229
        self.ls_equals('.bzrignore\n' 
 
230
                       'a\n', 
222
231
                       '--kind=file')
223
 
        self.ls_equals('subdir/\n',
 
232
        self.ls_equals('subdir\n',
224
233
                       '--kind=directory')
225
234
        self.ls_equals('',
226
235
                       '--kind=symlink')
227
 
        self.run_bzr_error(['invalid kind specified'], 'ls --kind=pile')
228
 
 
229
 
    def test_ls_path_nonrecursive(self):
230
 
        self.ls_equals('%s/.bzrignore\n'
231
 
                       '%s/a\n'
232
 
                       % (self.test_dir, self.test_dir),
233
 
                       self.test_dir, recursive=False)
234
 
 
235
 
    def test_ls_directory(self):
236
 
        """Test --directory option"""
237
 
        self.wt = self.make_branch_and_tree('dir')
238
 
        self.build_tree(['dir/sub/', 'dir/sub/file'])
239
 
        self.wt.add(['sub', 'sub/file'])
240
 
        self.wt.commit('commit')
241
 
        self.ls_equals('sub/\nsub/file\n', '--directory=dir')
242
 
        self.ls_equals('sub/file\n', '-d dir sub')
243
 
 
244
 
 
245
 
class TestSmartServerLs(tests.TestCaseWithTransport):
246
 
 
247
 
    def test_simple_ls(self):
248
 
        self.setup_smart_server_with_call_log()
249
 
        t = self.make_branch_and_tree('branch')
250
 
        self.build_tree_contents([('branch/foo', 'thecontents')])
251
 
        t.add("foo")
252
 
        t.commit("message")
253
 
        self.reset_smart_call_log()
254
 
        out, err = self.run_bzr(['ls', self.get_url('branch')])
255
 
        # This figure represent the amount of work to perform this use case. It
256
 
        # is entirely ok to reduce this number if a test fails due to rpc_count
257
 
        # being too low. If rpc_count increases, more network roundtrips have
258
 
        # become necessary for this use case. Please do not adjust this number
259
 
        # upwards without agreement from bzr's network support maintainers.
260
 
        self.assertLength(6, self.hpss_calls)
261
 
        self.assertLength(1, self.hpss_connections)
262
 
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
236
        self.run_bzr_error('invalid kind specified', 'ls --kind=pile')