/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: Robert Collins
  • Date: 2007-04-18 08:39:02 UTC
  • mto: (2425.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 2427.
  • Revision ID: robertc@robertcollins.net-20070418083902-4o66h9fk7zeisvwa
Command objects can now declare related help topics by having _see_also
set to a list of related topic. Updated the HACKING guide entry on
documentation to be more clear about how the help for commands is
generated and to reference this new feature. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005 Canonical Ltd
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
 
 
18
 
 
19
"""Black-box tests for bzr cat.
 
20
"""
 
21
 
 
22
import os
 
23
 
 
24
from bzrlib.tests.blackbox import TestCaseWithTransport
 
25
 
 
26
class TestCat(TestCaseWithTransport):
 
27
 
 
28
    def test_cat(self):
 
29
 
 
30
        def bzr(*args, **kwargs):
 
31
            return self.run_bzr_subprocess(*args, **kwargs)[0]
 
32
 
 
33
        os.mkdir('branch')
 
34
        os.chdir('branch')
 
35
        bzr('init')
 
36
        open('a', 'wb').write('foo\n')
 
37
        bzr('add', 'a')
 
38
 
 
39
        # 'bzr cat' without an option should cat the last revision
 
40
        bzr('cat', 'a', retcode=3)
 
41
 
 
42
        bzr('commit', '-m', '1')
 
43
        open('a', 'wb').write('baz\n')
 
44
 
 
45
        self.assertEquals(bzr('cat', 'a'), 'foo\n')
 
46
 
 
47
        bzr('commit', '-m', '2')
 
48
        self.assertEquals(bzr('cat', 'a'), 'baz\n')
 
49
        self.assertEquals(bzr('cat', 'a', '-r', '1'), 'foo\n')
 
50
        self.assertEquals(bzr('cat', 'a', '-r', '-1'), 'baz\n')
 
51
 
 
52
        rev_id = bzr('revision-history').strip().split('\n')[-1]
 
53
 
 
54
        self.assertEquals(bzr('cat', 'a', '-r', 'revid:%s' % rev_id), 'baz\n')
 
55
        
 
56
        os.chdir('..')
 
57
        
 
58
        self.assertEquals(bzr('cat', 'branch/a', '-r', 'revno:1:branch'),
 
59
                          'foo\n')
 
60
        bzr('cat', 'a', retcode=3)
 
61
        bzr('cat', 'a', '-r', 'revno:1:branch-that-does-not-exist', retcode=3)
 
62
        
 
63
    def test_cat_different_id(self):
 
64
        """'cat' works with old and new files"""
 
65
        tree = self.make_branch_and_tree('.')
 
66
        # the files are named after their path in the revision and
 
67
        # current trees later in the test case
 
68
        # a-rev-tree is special because it appears in both the revision
 
69
        # tree and the working tree
 
70
        self.build_tree_contents([('a-rev-tree', 'foo\n'),
 
71
            ('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
 
72
        tree.lock_write()
 
73
        try:
 
74
            tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
 
75
            tree.commit('add test files')
 
76
            # remove currently uses self._write_inventory - 
 
77
            # work around that for now.
 
78
            tree.flush()
 
79
            tree.remove(['d-rev'])
 
80
            tree.rename_one('a-rev-tree', 'b-tree')
 
81
            tree.rename_one('c-rev', 'a-rev-tree')
 
82
        finally:
 
83
            # calling bzr as another process require free lock on win32
 
84
            tree.unlock()
 
85
 
 
86
        # 'b-tree' is not present in the old tree.
 
87
        self.run_bzr_error(["^bzr: ERROR: u?'b-tree' "
 
88
                            "is not present in revision .+$"],
 
89
                           'cat', 'b-tree', '--name-from-revision')
 
90
 
 
91
        # get to the old file automatically
 
92
        out, err = self.run_bzr('cat', 'd-rev')
 
93
        self.assertEqual('bar\n', out)
 
94
        self.assertEqual('', err)
 
95
 
 
96
        out, err = self.run_bzr('cat', 'a-rev-tree',
 
97
                                '--name-from-revision')
 
98
        self.assertEqual('foo\n', out)
 
99
        self.assertEqual('', err)
 
100
 
 
101
        out, err = self.run_bzr('cat', 'a-rev-tree')
 
102
        self.assertEqual('baz\n', out)
 
103
        self.assertEqual('', err)
 
104
 
 
105
    def test_remote_cat(self):
 
106
        wt = self.make_branch_and_tree('.')
 
107
        self.build_tree(['README'])
 
108
        wt.add('README')
 
109
        wt.commit('Making sure there is a basis_tree available')
 
110
 
 
111
        url = self.get_readonly_url() + '/README'
 
112
        out, err = self.run_bzr('cat', url)
 
113
        self.assertEqual('contents of README\n', out)
 
114
 
 
115
    def test_cat_no_working_tree(self):
 
116
        wt = self.make_branch_and_tree('.')
 
117
        self.build_tree(['README'])
 
118
        wt.add('README')
 
119
        wt.commit('Making sure there is a basis_tree available')
 
120
        wt.branch.bzrdir.destroy_workingtree()
 
121
 
 
122
        url = self.get_readonly_url() + '/README'
 
123
        out, err = self.run_bzr('cat', url)
 
124
        self.assertEqual('contents of README\n', out)
 
125