/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_cat.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
"""Black-box tests for brz cat.
 
18
"""Black-box tests for bzr cat.
19
19
"""
20
20
 
21
 
from ... import tests
22
 
from ..matchers import ContainsNoVfsCalls
23
 
from ...transport import memory
 
21
from bzrlib import tests
 
22
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
23
from bzrlib.transport import memory
24
24
 
25
25
 
26
26
class TestCat(tests.TestCaseWithTransport):
27
27
 
28
28
    def test_cat(self):
29
29
        tree = self.make_branch_and_tree('branch')
30
 
        self.build_tree_contents([('branch/a', b'foo\n')])
 
30
        self.build_tree_contents([('branch/a', 'foo\n')])
31
31
        tree.add('a')
32
 
        # 'brz cat' without an option should cat the last revision
 
32
        # 'bzr cat' without an option should cat the last revision
33
33
        self.run_bzr(['cat', 'a'], retcode=3, working_dir='branch')
34
34
 
35
35
        tree.commit(message='1')
36
 
        self.build_tree_contents([('branch/a', b'baz\n')])
 
36
        self.build_tree_contents([('branch/a', 'baz\n')])
37
37
 
38
 
        self.assertEqual('foo\n',
 
38
        self.assertEquals('foo\n',
39
39
                          self.run_bzr(['cat', 'a'], working_dir='branch')[0])
40
40
 
41
41
        # On Windows, we used to have a bug where newlines got changed into
42
42
        # crlf, whereas cat ought to write out the file exactly as it's
43
43
        # recorded (by default.)  That problem can't be reproduced in-process,
44
44
        # so we need just one test here that 
45
 
        self.assertEqual('foo\n',
 
45
        self.assertEquals('foo\n',
46
46
                          self.run_bzr_subprocess(['cat', 'a'],
47
47
                                                  working_dir='branch')[0])
48
48
 
49
49
        tree.commit(message='2')
50
 
        self.assertEqual(
 
50
        self.assertEquals(
51
51
            'baz\n', self.run_bzr(['cat', 'a'], working_dir='branch')[0])
52
 
        self.assertEqual(
 
52
        self.assertEquals(
53
53
            'foo\n', self.run_bzr(['cat', 'a', '-r', '1'],
54
54
                                  working_dir='branch')[0])
55
 
        self.assertEqual(
 
55
        self.assertEquals(
56
56
            'baz\n', self.run_bzr(['cat', 'a', '-r', '-1'],
57
57
                                  working_dir='branch')[0])
58
58
 
59
59
        rev_id = tree.branch.last_revision()
60
60
 
61
 
        self.assertEqual(
 
61
        self.assertEquals(
62
62
            'baz\n', self.run_bzr(['cat', 'a', '-r', 'revid:%s' % rev_id],
63
63
                                  working_dir='branch')[0])
64
64
 
65
 
        self.assertEqual('foo\n',
 
65
        self.assertEquals('foo\n',
66
66
                          self.run_bzr(['cat', 'branch/a',
67
67
                                        '-r', 'revno:1:branch'])[0])
68
68
        self.run_bzr(['cat', 'a'], retcode=3)
77
77
        # current trees later in the test case
78
78
        # a-rev-tree is special because it appears in both the revision
79
79
        # tree and the working tree
80
 
        self.build_tree_contents([('a-rev-tree', b'foo\n'),
81
 
            ('c-rev', b'baz\n'), ('d-rev', b'bar\n'), ('e-rev', b'qux\n')])
82
 
        with tree.lock_write():
 
80
        self.build_tree_contents([('a-rev-tree', 'foo\n'),
 
81
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
 
82
        tree.lock_write()
 
83
        try:
83
84
            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
84
 
            tree.commit('add test files', rev_id=b'first')
 
85
            tree.commit('add test files', rev_id='first')
85
86
            # remove currently uses self._write_inventory -
86
87
            # work around that for now.
87
88
            tree.flush()
89
90
            tree.rename_one('a-rev-tree', 'b-tree')
90
91
            tree.rename_one('c-rev', 'a-rev-tree')
91
92
            tree.rename_one('e-rev', 'old-rev')
92
 
            self.build_tree_contents([('e-rev', b'new\n')])
 
93
            self.build_tree_contents([('e-rev', 'new\n')])
93
94
            tree.add(['e-rev'])
 
95
        finally:
 
96
            # calling bzr as another process require free lock on win32
 
97
            tree.unlock()
94
98
 
95
99
        # 'b-tree' is not present in the old tree.
96
 
        self.run_bzr_error(["^brz: ERROR: u?'b-tree' "
 
100
        self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
97
101
                            "is not present in revision .+$"],
98
102
                           'cat b-tree --name-from-revision')
99
103
 
100
104
        # get to the old file automatically
101
105
        out, err = self.run_bzr('cat d-rev')
102
 
        self.assertEqual('', err)
103
106
        self.assertEqual('bar\n', out)
 
107
        self.assertEqual('', err)
104
108
 
105
109
        out, err = \
106
110
                self.run_bzr('cat a-rev-tree --name-from-revision')
157
161
        # subprocess because we really need to patch in a plugin that
158
162
        # registers the filters. Instead, we patch in a custom
159
163
        # filter_stack and use run_bzr() ...
160
 
        from ..test_filters import _stack_2
161
 
        from ...tree import Tree
 
164
        from cStringIO import StringIO
 
165
        from bzrlib.commands import run_bzr
 
166
        from bzrlib.tests.test_filters import _stack_2
 
167
        from bzrlib.trace import mutter
 
168
        from bzrlib.tree import Tree
162
169
        wt = self.make_branch_and_tree('.')
163
170
        self.build_tree_contents([
164
 
            ('README', b"junk\nline 1 of README\nline 2 of README\n"),
 
171
            ('README', "junk\nline 1 of README\nline 2 of README\n"),
165
172
            ])
166
173
        wt.add('README')
167
174
        wt.commit('Making sure there is a basis_tree available')
183
190
        self.build_tree(['README'])
184
191
        wt.add('README')
185
192
        wt.commit('Making sure there is a basis_tree available')
186
 
        wt.branch.controldir.destroy_workingtree()
 
193
        wt.branch.bzrdir.destroy_workingtree()
187
194
 
188
195
        url = self.get_readonly_url() + '/README'
189
196
        out, err = self.run_bzr(['cat', url])
191
198
 
192
199
    def test_cat_nonexistent_branch(self):
193
200
        self.vfs_transport_factory = memory.MemoryServer
194
 
        self.run_bzr_error(['^brz: ERROR: Not a branch'],
 
201
        self.run_bzr_error(['^bzr: ERROR: Not a branch'],
195
202
                           ['cat', self.get_url()])
196
203
 
197
204
    def test_cat_directory(self):
219
226
    def test_simple_branch_cat(self):
220
227
        self.setup_smart_server_with_call_log()
221
228
        t = self.make_branch_and_tree('branch')
222
 
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
229
        self.build_tree_contents([('branch/foo', 'thecontents')])
223
230
        t.add("foo")
224
231
        t.commit("message")
225
232
        self.reset_smart_call_log()