~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2006-03-03 08:55:34 UTC
  • mto: This revision was merged to the branch mainline in revision 1593.
  • Revision ID: mbp@sourcefrog.net-20060303085534-d24a8118f4ce571a
Add some tests that format7 repo creates the right lock type

Show diffs side-by-side

added added

removed removed

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