/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 breezy/tests/blackbox/test_ls.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-16 13:07:04 UTC
  • mto: This revision was merged to the branch mainline in revision 7174.
  • Revision ID: jelmer@jelmer.uk-20181116130704-prj4jo8otlee68qf
Use flake8 rather than pyflakes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
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):
 
17
"""External tests of 'brz ls'"""
 
18
 
 
19
from breezy import (
 
20
    ignores,
 
21
    tests,
 
22
    )
 
23
from breezy.tests.matchers import ContainsNoVfsCalls
 
24
 
 
25
 
 
26
class TestLS(tests.TestCaseWithTransport):
26
27
 
27
28
    def setUp(self):
28
29
        super(TestLS, self).setUp()
32
33
 
33
34
        self.wt = self.make_branch_and_tree('.')
34
35
        self.build_tree_contents([
35
 
                                 ('.bzrignore', '*.pyo\n'),
36
 
                                 ('a', 'hello\n'),
 
36
                                 ('.bzrignore', b'*.pyo\n'),
 
37
                                 ('a', b'hello\n'),
37
38
                                 ])
38
39
 
39
 
    def ls_equals(self, value, args=None, recursive=True):
 
40
    def ls_equals(self, value, args=None, recursive=True, working_dir=None):
40
41
        command = 'ls'
41
42
        if args is not None:
42
43
            command += ' ' + args
43
44
        if recursive:
44
45
            command += ' -R'
45
 
        out, err = self.run_bzr(command)
 
46
        out, err = self.run_bzr(command, working_dir=working_dir)
46
47
        self.assertEqual('', err)
47
48
        self.assertEqualDiff(value, out)
48
49
 
52
53
                           'ls --verbose --null')
53
54
 
54
55
    def test_ls_basic(self):
55
 
        """Test the abilities of 'bzr ls'"""
 
56
        """Test the abilities of 'brz ls'"""
56
57
        self.ls_equals('.bzrignore\na\n')
57
58
        self.ls_equals('.bzrignore\na\n', './')
58
59
        self.ls_equals('?        .bzrignore\n'
96
97
 
97
98
    def test_show_ids(self):
98
99
        self.build_tree(['subdir/'])
99
 
        self.wt.add(['a', 'subdir'], ['a-id', 'subdir-id'])
 
100
        self.wt.add(['a', 'subdir'], [b'a-id', b'subdir-id'])
100
101
        self.ls_equals(
101
102
            '.bzrignore                                         \n'
102
103
            'a                                                  a-id\n'
126
127
                       , '--verbose', recursive=False)
127
128
 
128
129
        # Check what happens in a sub-directory
129
 
        os.chdir('subdir')
130
 
        self.ls_equals('b\n')
131
 
        self.ls_equals('b\0'
132
 
                  , '--null')
133
 
        self.ls_equals('subdir/b\n'
134
 
                       , '--from-root')
135
 
        self.ls_equals('subdir/b\0'
136
 
                       , '--from-root --null')
137
 
        self.ls_equals('subdir/b\n'
138
 
                       , '--from-root', recursive=False)
 
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')
139
137
 
140
138
    def test_ls_path(self):
141
139
        """If a path is specified, files are listed with that prefix"""
142
140
        self.build_tree(['subdir/', 'subdir/b'])
143
141
        self.wt.add(['subdir', 'subdir/b'])
144
 
        self.ls_equals('subdir/b\n' ,
 
142
        self.ls_equals('subdir/b\n',
145
143
                       'subdir')
146
 
        os.chdir('subdir')
147
144
        self.ls_equals('../.bzrignore\n'
148
145
                       '../a\n'
149
146
                       '../subdir/\n'
150
 
                       '../subdir/b\n' ,
151
 
                       '..')
 
147
                       '../subdir/b\n',
 
148
                       '..', working_dir='subdir')
152
149
        self.ls_equals('../.bzrignore\0'
153
150
                       '../a\0'
154
151
                       '../subdir\0'
155
 
                       '../subdir/b\0' ,
156
 
                       '.. --null')
 
152
                       '../subdir/b\0',
 
153
                       '.. --null', working_dir='subdir')
157
154
        self.ls_equals('?        ../.bzrignore\n'
158
155
                       '?        ../a\n'
159
156
                       'V        ../subdir/\n'
160
 
                       'V        ../subdir/b\n' ,
161
 
                       '.. --verbose')
 
157
                       'V        ../subdir/b\n',
 
158
                       '.. --verbose', working_dir='subdir')
162
159
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
163
 
                           'ls --from-root ..')
 
160
                           'ls --from-root ..', working_dir='subdir')
164
161
 
165
162
    def test_ls_revision(self):
166
163
        self.wt.add(['a'])
173
170
        self.ls_equals('V        a\n'
174
171
                       , '--verbose --revision 1')
175
172
 
176
 
        os.chdir('subdir')
177
 
        self.ls_equals('', '--revision 1')
 
173
        self.ls_equals('', '--revision 1', working_dir='subdir')
178
174
 
179
175
    def test_ls_branch(self):
180
176
        """If a branch is specified, files are listed from it"""
235
231
                       '%s/a\n'
236
232
                       % (self.test_dir, self.test_dir),
237
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', b'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)