/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

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