~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005, 2006, 2007, 2009, 2011, 2012, 2016 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.50.17 by John Arbash Meinel
Forgot to add the test case
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.50.17 by John Arbash Meinel
Forgot to add the test case
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.50.17 by John Arbash Meinel
Forgot to add the test case
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.50.17 by John Arbash Meinel
Forgot to add the test case
16
17
18
"""Black-box tests for bzr revno.
19
"""
20
21
import os
22
4409.1.21 by Vincent Ladeuil
Fix failing test.
23
from bzrlib import tests
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
24
from bzrlib.tests.matchers import ContainsNoVfsCalls
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
25
1185.50.17 by John Arbash Meinel
Forgot to add the test case
26
4409.1.21 by Vincent Ladeuil
Fix failing test.
27
class TestRevno(tests.TestCaseWithTransport):
1185.50.17 by John Arbash Meinel
Forgot to add the test case
28
29
    def test_revno(self):
30
31
        def bzr(*args, **kwargs):
32
            return self.run_bzr(*args, **kwargs)[0]
33
34
        os.mkdir('a')
35
        os.chdir('a')
36
        bzr('init')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
37
        self.assertEqual(int(bzr('revno')), 0)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
38
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
39
        with open('foo', 'wb') as f: f.write('foo\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
40
        bzr('add foo')
41
        bzr('commit -m foo')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
42
        self.assertEqual(int(bzr('revno')), 1)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
43
44
        os.mkdir('baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
45
        bzr('add baz')
46
        bzr('commit -m baz')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
47
        self.assertEqual(int(bzr('revno')), 2)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
48
49
        os.chdir('..')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
50
        self.assertEqual(int(bzr('revno a')), 2)
51
        self.assertEqual(int(bzr('revno a/baz')), 2)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
52
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
53
    def test_revno_tree(self):
54
        # Make branch and checkout
4409.1.8 by John Arbash Meinel
Small tweaks to to the tests for --tree support.
55
        wt = self.make_branch_and_tree('branch')
56
        checkout = wt.branch.create_checkout('checkout', lightweight=True)
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
57
58
        # Get the checkout out of date
59
        self.build_tree(['branch/file'])
4409.1.8 by John Arbash Meinel
Small tweaks to to the tests for --tree support.
60
        wt.add(['file'])
61
        wt.commit('mkfile')
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
62
63
        # Make sure revno says we're on 1
64
        out,err = self.run_bzr('revno checkout')
65
        self.assertEqual('', err)
66
        self.assertEqual('1\n', out)
67
68
        # Make sure --tree knows it's still on 0
69
        out,err = self.run_bzr('revno --tree checkout')
70
        self.assertEqual('', err)
71
        self.assertEqual('0\n', out)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
72
4409.1.16 by Matthew Fuller
Add a test for revno --tree on something without a tree.
73
    def test_revno_tree_no_tree(self):
74
        # Make treeless branch
75
        b = self.make_branch('branch')
76
77
        # Try getting it's --tree revno
78
        out,err = self.run_bzr('revno --tree branch', retcode=3)
79
        self.assertEqual('', out)
80
        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
81
            err)
82
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
83
    def test_dotted_revno_tree(self):
84
        builder = self.make_branch_builder('branch')
85
        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'], [])
91
        builder.finish_series()
92
        b = builder.get_branch()
93
        co_b = b.create_checkout('checkout_b', lightweight=True,
94
                                 revision_id='B-id')
95
        out, err = self.run_bzr('revno checkout_b')
96
        self.assertEqual('', err)
97
        self.assertEqual('2\n', out)
98
        out, err = self.run_bzr('revno --tree checkout_b')
99
        self.assertEqual('', err)
100
        self.assertEqual('1.1.1\n', out)
101
102
    def test_stale_revno_tree(self):
103
        builder = self.make_branch_builder('branch')
104
        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'], [])
110
        builder.finish_series()
111
        b = builder.get_branch()
112
        # The branch is now at "C-id", but the checkout is still at "B-id"
113
        # which is no longer in the history
114
        co_b = b.create_checkout('checkout_b', lightweight=True,
115
                                 revision_id='B-id')
116
        out, err = self.run_bzr('revno checkout_b')
117
        self.assertEqual('', err)
118
        self.assertEqual('2\n', out)
119
        out, err = self.run_bzr('revno --tree checkout_b')
120
        self.assertEqual('', err)
121
        self.assertEqual('???\n', out)
6202.1.1 by Jelmer Vernooij
'bzr revno' now takes a --revision argument.
122
123
    def test_revno_with_revision(self):
124
        wt = self.make_branch_and_tree('.')
125
        revid1 = wt.commit('rev1')
126
        revid2 = wt.commit('rev2')
127
128
        out, err = self.run_bzr('revno -r-2 .')
129
        self.assertEqual('1\n', out)
130
131
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1)
132
        self.assertEqual('1\n', out)
6202.1.2 by Jelmer Vernooij
Add check for using --tree and --revision together.
133
134
    def test_revno_and_tree_mutually_exclusive(self):
135
        wt = self.make_branch_and_tree('.')
136
        out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
137
        self.assertEqual('', out)
138
        self.assertEqual(
139
            'bzr: ERROR: --tree and --revision can not be used together\n',
140
            err)
6283.1.4 by Jelmer Vernooij
Add revno hpss call count.
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.
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
158
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
159
        self.assertLength(1, self.hpss_connections)
6263.1.8 by Jelmer Vernooij
Merge bzr.dev, fix hpss call counts.
160
        self.assertLength(6, self.hpss_calls)
6283.1.4 by Jelmer Vernooij
Add revno hpss call count.
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.
6263.1.8 by Jelmer Vernooij
Merge bzr.dev, fix hpss call counts.
177
        self.assertLength(5, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
178
        self.assertLength(1, self.hpss_connections)
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
179
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)