~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 13:02:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6434.
  • Revision ID: v.ladeuil+lp@free.fr-20120105130231-grtl31ovy72doqp9
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.

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
16
16
 
17
17
"""External tests of 'bzr ls'"""
18
18
 
19
 
import os
20
 
 
21
 
from bzrlib import ignores
22
 
from bzrlib.tests import TestCaseWithTransport
 
19
from bzrlib import (
 
20
    ignores,
 
21
    tests,
 
22
    )
23
23
from bzrlib.tests.matchers import ContainsNoVfsCalls
24
24
 
25
25
 
26
 
class TestLS(TestCaseWithTransport):
 
26
class TestLS(tests.TestCaseWithTransport):
27
27
 
28
28
    def setUp(self):
29
29
        super(TestLS, self).setUp()
37
37
                                 ('a', 'hello\n'),
38
38
                                 ])
39
39
 
40
 
    def ls_equals(self, value, args=None, recursive=True):
 
40
    def ls_equals(self, value, args=None, recursive=True, working_dir=None):
41
41
        command = 'ls'
42
42
        if args is not None:
43
43
            command += ' ' + args
44
44
        if recursive:
45
45
            command += ' -R'
46
 
        out, err = self.run_bzr(command)
 
46
        out, err = self.run_bzr(command, working_dir=working_dir)
47
47
        self.assertEqual('', err)
48
48
        self.assertEqualDiff(value, out)
49
49
 
127
127
                       , '--verbose', recursive=False)
128
128
 
129
129
        # Check what happens in a sub-directory
130
 
        os.chdir('subdir')
131
 
        self.ls_equals('b\n')
132
 
        self.ls_equals('b\0'
133
 
                  , '--null')
134
 
        self.ls_equals('subdir/b\n'
135
 
                       , '--from-root')
136
 
        self.ls_equals('subdir/b\0'
137
 
                       , '--from-root --null')
138
 
        self.ls_equals('subdir/b\n'
139
 
                       , '--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')
140
137
 
141
138
    def test_ls_path(self):
142
139
        """If a path is specified, files are listed with that prefix"""
144
141
        self.wt.add(['subdir', 'subdir/b'])
145
142
        self.ls_equals('subdir/b\n' ,
146
143
                       'subdir')
147
 
        os.chdir('subdir')
148
144
        self.ls_equals('../.bzrignore\n'
149
145
                       '../a\n'
150
146
                       '../subdir/\n'
151
147
                       '../subdir/b\n' ,
152
 
                       '..')
 
148
                       '..', working_dir='subdir')
153
149
        self.ls_equals('../.bzrignore\0'
154
150
                       '../a\0'
155
151
                       '../subdir\0'
156
152
                       '../subdir/b\0' ,
157
 
                       '.. --null')
 
153
                       '.. --null', working_dir='subdir')
158
154
        self.ls_equals('?        ../.bzrignore\n'
159
155
                       '?        ../a\n'
160
156
                       'V        ../subdir/\n'
161
157
                       'V        ../subdir/b\n' ,
162
 
                       '.. --verbose')
 
158
                       '.. --verbose', working_dir='subdir')
163
159
        self.run_bzr_error(['cannot specify both --from-root and PATH'],
164
 
                           'ls --from-root ..')
 
160
                           'ls --from-root ..', working_dir='subdir')
165
161
 
166
162
    def test_ls_revision(self):
167
163
        self.wt.add(['a'])
174
170
        self.ls_equals('V        a\n'
175
171
                       , '--verbose --revision 1')
176
172
 
177
 
        os.chdir('subdir')
178
 
        self.ls_equals('', '--revision 1')
 
173
        self.ls_equals('', '--revision 1', working_dir='subdir')
179
174
 
180
175
    def test_ls_branch(self):
181
176
        """If a branch is specified, files are listed from it"""
247
242
        self.ls_equals('sub/file\n', '-d dir sub')
248
243
 
249
244
 
250
 
class TestSmartServerLs(TestCaseWithTransport):
 
245
class TestSmartServerLs(tests.TestCaseWithTransport):
251
246
 
252
247
    def test_simple_ls(self):
253
248
        self.setup_smart_server_with_call_log()