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

  • Committer: Jelmer Vernooij
  • Date: 2018-11-18 18:23:32 UTC
  • mto: This revision was merged to the branch mainline in revision 7197.
  • Revision ID: jelmer@jelmer.uk-20181118182332-viz1qvqese2mo9i6
Fix some more Bazaar references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2016 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 bzr revno.
 
18
"""Black-box tests for brz revno.
19
19
"""
20
20
 
21
21
import os
22
22
 
23
 
from bzrlib import tests
 
23
from breezy import tests
 
24
from breezy.errors import NoSuchRevision
 
25
from breezy.tests.matchers import ContainsNoVfsCalls
 
26
 
24
27
 
25
28
class TestRevno(tests.TestCaseWithTransport):
26
29
 
32
35
        os.mkdir('a')
33
36
        os.chdir('a')
34
37
        bzr('init')
35
 
        self.assertEquals(int(bzr('revno')), 0)
 
38
        self.assertEqual(int(bzr('revno')), 0)
36
39
 
37
 
        open('foo', 'wb').write('foo\n')
 
40
        with open('foo', 'wb') as f:
 
41
            f.write(b'foo\n')
38
42
        bzr('add foo')
39
43
        bzr('commit -m foo')
40
 
        self.assertEquals(int(bzr('revno')), 1)
 
44
        self.assertEqual(int(bzr('revno')), 1)
41
45
 
42
46
        os.mkdir('baz')
43
47
        bzr('add baz')
44
48
        bzr('commit -m baz')
45
 
        self.assertEquals(int(bzr('revno')), 2)
 
49
        self.assertEqual(int(bzr('revno')), 2)
46
50
 
47
51
        os.chdir('..')
48
 
        self.assertEquals(int(bzr('revno a')), 2)
49
 
        self.assertEquals(int(bzr('revno a/baz')), 2)
 
52
        self.assertEqual(int(bzr('revno a')), 2)
 
53
        self.assertEqual(int(bzr('revno a/baz')), 2)
50
54
 
51
55
    def test_revno_tree(self):
52
56
        # Make branch and checkout
59
63
        wt.commit('mkfile')
60
64
 
61
65
        # Make sure revno says we're on 1
62
 
        out,err = self.run_bzr('revno checkout')
 
66
        out, err = self.run_bzr('revno checkout')
63
67
        self.assertEqual('', err)
64
68
        self.assertEqual('1\n', out)
65
69
 
66
70
        # Make sure --tree knows it's still on 0
67
 
        out,err = self.run_bzr('revno --tree checkout')
 
71
        out, err = self.run_bzr('revno --tree checkout')
68
72
        self.assertEqual('', err)
69
73
        self.assertEqual('0\n', out)
70
74
 
73
77
        b = self.make_branch('branch')
74
78
 
75
79
        # Try getting it's --tree revno
76
 
        out,err = self.run_bzr('revno --tree branch', retcode=3)
 
80
        out, err = self.run_bzr('revno --tree branch', retcode=3)
77
81
        self.assertEqual('', out)
78
 
        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
79
 
            err)
 
82
        self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
 
83
                         err)
80
84
 
81
85
    def test_dotted_revno_tree(self):
82
86
        builder = self.make_branch_builder('branch')
83
87
        builder.start_series()
84
 
        builder.build_snapshot('A-id', None, [
85
 
            ('add', ('', 'root-id', 'directory', None)),
86
 
            ('add', ('file', 'file-id', 'file', 'content\n'))])
87
 
        builder.build_snapshot('B-id', ['A-id'], [])
88
 
        builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
 
88
        builder.build_snapshot(None, [
 
89
            ('add', ('', b'root-id', 'directory', None)),
 
90
            ('add', ('file', b'file-id', 'file', b'content\n'))],
 
91
            revision_id=b'A-id')
 
92
        builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
 
93
        builder.build_snapshot([b'A-id', b'B-id'], [], revision_id=b'C-id')
89
94
        builder.finish_series()
90
95
        b = builder.get_branch()
91
96
        co_b = b.create_checkout('checkout_b', lightweight=True,
92
 
                                 revision_id='B-id')
 
97
                                 revision_id=b'B-id')
93
98
        out, err = self.run_bzr('revno checkout_b')
94
99
        self.assertEqual('', err)
95
100
        self.assertEqual('2\n', out)
100
105
    def test_stale_revno_tree(self):
101
106
        builder = self.make_branch_builder('branch')
102
107
        builder.start_series()
103
 
        builder.build_snapshot('A-id', None, [
104
 
            ('add', ('', 'root-id', 'directory', None)),
105
 
            ('add', ('file', 'file-id', 'file', 'content\n'))])
106
 
        builder.build_snapshot('B-id', ['A-id'], [])
107
 
        builder.build_snapshot('C-id', ['A-id'], [])
 
108
        builder.build_snapshot(None, [
 
109
            ('add', ('', b'root-id', 'directory', None)),
 
110
            ('add', ('file', b'file-id', 'file', b'content\n'))],
 
111
            revision_id=b'A-id')
 
112
        builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
 
113
        builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
108
114
        builder.finish_series()
109
115
        b = builder.get_branch()
110
116
        # The branch is now at "C-id", but the checkout is still at "B-id"
111
117
        # which is no longer in the history
112
118
        co_b = b.create_checkout('checkout_b', lightweight=True,
113
 
                                 revision_id='B-id')
 
119
                                 revision_id=b'B-id')
114
120
        out, err = self.run_bzr('revno checkout_b')
115
121
        self.assertEqual('', err)
116
122
        self.assertEqual('2\n', out)
117
123
        out, err = self.run_bzr('revno --tree checkout_b')
118
124
        self.assertEqual('', err)
119
125
        self.assertEqual('???\n', out)
 
126
 
 
127
    def test_revno_ghost(self):
 
128
        builder = self.make_branch_builder('branch')
 
129
        builder.start_series()
 
130
        revid = builder.build_snapshot([b'aghost'], [
 
131
            ('add', ('', b'root-id', 'directory', None)),
 
132
            ('add', ('file', b'file-id', 'file', b'content\n'))],
 
133
            revision_id=b'A-id', allow_leftmost_as_ghost=True)
 
134
        builder.finish_series()
 
135
        b = builder.get_branch()
 
136
 
 
137
        def revision_id_to_revno(s, r):
 
138
            raise NoSuchRevision(s, r)
 
139
        self.overrideAttr(type(b), 'revision_id_to_dotted_revno', revision_id_to_revno)
 
140
        self.overrideAttr(type(b), 'revision_id_to_revno', revision_id_to_revno)
 
141
        out, err = self.run_bzr('revno branch')
 
142
        self.assertEqual('', err)
 
143
        self.assertEqual('???\n', out)
 
144
 
 
145
    def test_revno_with_revision(self):
 
146
        wt = self.make_branch_and_tree('.')
 
147
        revid1 = wt.commit('rev1')
 
148
        revid2 = wt.commit('rev2')
 
149
 
 
150
        out, err = self.run_bzr('revno -r-2 .')
 
151
        self.assertEqual('1\n', out)
 
152
 
 
153
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1.decode('utf-8'))
 
154
        self.assertEqual('1\n', out)
 
155
 
 
156
    def test_revno_and_tree_mutually_exclusive(self):
 
157
        wt = self.make_branch_and_tree('.')
 
158
        out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
 
159
        self.assertEqual('', out)
 
160
        self.assertEqual(
 
161
            'brz: ERROR: --tree and --revision can not be used together\n',
 
162
            err)
 
163
 
 
164
 
 
165
class TestSmartServerRevno(tests.TestCaseWithTransport):
 
166
 
 
167
    def test_simple_branch_revno(self):
 
168
        self.setup_smart_server_with_call_log()
 
169
        t = self.make_branch_and_tree('branch')
 
170
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
171
        t.add("foo")
 
172
        revid = t.commit("message")
 
173
        self.reset_smart_call_log()
 
174
        out, err = self.run_bzr(['revno', self.get_url('branch')])
 
175
        # This figure represent the amount of work to perform this use case. It
 
176
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
177
        # being too low. If rpc_count increases, more network roundtrips have
 
178
        # become necessary for this use case. Please do not adjust this number
 
179
        # upwards without agreement from bzr's network support maintainers.
 
180
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
181
        self.assertLength(1, self.hpss_connections)
 
182
        self.assertLength(6, self.hpss_calls)
 
183
 
 
184
    def test_simple_branch_revno_lookup(self):
 
185
        self.setup_smart_server_with_call_log()
 
186
        t = self.make_branch_and_tree('branch')
 
187
        self.build_tree_contents([('branch/foo', b'thecontents')])
 
188
        t.add("foo")
 
189
        revid1 = t.commit("message")
 
190
        revid2 = t.commit("message")
 
191
        self.reset_smart_call_log()
 
192
        out, err = self.run_bzr(['revno', '-rrevid:' + revid1.decode('utf-8'),
 
193
                                 self.get_url('branch')])
 
194
        # This figure represent the amount of work to perform this use case. It
 
195
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
196
        # being too low. If rpc_count increases, more network roundtrips have
 
197
        # become necessary for this use case. Please do not adjust this number
 
198
        # upwards without agreement from bzr's network support maintainers.
 
199
        self.assertLength(5, self.hpss_calls)
 
200
        self.assertLength(1, self.hpss_connections)
 
201
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)