/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz revno.
1185.50.17 by John Arbash Meinel
Forgot to add the test case
19
"""
20
21
import os
22
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
23
from breezy import tests
24
from breezy.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
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
64
        out, err = self.run_bzr('revno checkout')
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
65
        self.assertEqual('', err)
66
        self.assertEqual('1\n', out)
67
68
        # Make sure --tree knows it's still on 0
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
69
        out, err = self.run_bzr('revno --tree checkout')
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
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
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
78
        out, err = self.run_bzr('revno --tree branch', retcode=3)
4409.1.16 by Matthew Fuller
Add a test for revno --tree on something without a tree.
79
        self.assertEqual('', out)
6622.1.29 by Jelmer Vernooij
Fix some more tests.
80
        self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
4409.1.16 by Matthew Fuller
Add a test for revno --tree on something without a tree.
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()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
86
        builder.build_snapshot(None, [
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
87
            ('add', ('', 'root-id', 'directory', None)),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
88
            ('add', ('file', 'file-id', 'file', 'content\n'))],
89
            revision_id='A-id')
90
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
91
        builder.build_snapshot(['A-id', 'B-id'], [], revision_id='C-id')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
92
        builder.finish_series()
93
        b = builder.get_branch()
94
        co_b = b.create_checkout('checkout_b', lightweight=True,
95
                                 revision_id='B-id')
96
        out, err = self.run_bzr('revno checkout_b')
97
        self.assertEqual('', err)
98
        self.assertEqual('2\n', out)
99
        out, err = self.run_bzr('revno --tree checkout_b')
100
        self.assertEqual('', err)
101
        self.assertEqual('1.1.1\n', out)
102
103
    def test_stale_revno_tree(self):
104
        builder = self.make_branch_builder('branch')
105
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
106
        builder.build_snapshot(None, [
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
107
            ('add', ('', 'root-id', 'directory', None)),
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
108
            ('add', ('file', 'file-id', 'file', 'content\n'))],
109
            revision_id='A-id')
110
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
111
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
112
        builder.finish_series()
113
        b = builder.get_branch()
114
        # The branch is now at "C-id", but the checkout is still at "B-id"
115
        # which is no longer in the history
116
        co_b = b.create_checkout('checkout_b', lightweight=True,
117
                                 revision_id='B-id')
118
        out, err = self.run_bzr('revno checkout_b')
119
        self.assertEqual('', err)
120
        self.assertEqual('2\n', out)
121
        out, err = self.run_bzr('revno --tree checkout_b')
122
        self.assertEqual('', err)
123
        self.assertEqual('???\n', out)
6202.1.1 by Jelmer Vernooij
'bzr revno' now takes a --revision argument.
124
125
    def test_revno_with_revision(self):
126
        wt = self.make_branch_and_tree('.')
127
        revid1 = wt.commit('rev1')
128
        revid2 = wt.commit('rev2')
129
130
        out, err = self.run_bzr('revno -r-2 .')
131
        self.assertEqual('1\n', out)
132
133
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1)
134
        self.assertEqual('1\n', out)
6202.1.2 by Jelmer Vernooij
Add check for using --tree and --revision together.
135
136
    def test_revno_and_tree_mutually_exclusive(self):
137
        wt = self.make_branch_and_tree('.')
138
        out, err = self.run_bzr('revno -r-2 --tree .', retcode=3)
139
        self.assertEqual('', out)
140
        self.assertEqual(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
141
            'brz: ERROR: --tree and --revision can not be used together\n',
6202.1.2 by Jelmer Vernooij
Add check for using --tree and --revision together.
142
            err)
6283.1.4 by Jelmer Vernooij
Add revno hpss call count.
143
144
145
class TestSmartServerRevno(tests.TestCaseWithTransport):
146
147
    def test_simple_branch_revno(self):
148
        self.setup_smart_server_with_call_log()
149
        t = self.make_branch_and_tree('branch')
150
        self.build_tree_contents([('branch/foo', 'thecontents')])
151
        t.add("foo")
152
        revid = t.commit("message")
153
        self.reset_smart_call_log()
154
        out, err = self.run_bzr(['revno', self.get_url('branch')])
155
        # This figure represent the amount of work to perform this use case. It
156
        # is entirely ok to reduce this number if a test fails due to rpc_count
157
        # being too low. If rpc_count increases, more network roundtrips have
158
        # become necessary for this use case. Please do not adjust this number
159
        # upwards without agreement from bzr's network support maintainers.
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
160
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
161
        self.assertLength(1, self.hpss_connections)
6263.1.8 by Jelmer Vernooij
Merge bzr.dev, fix hpss call counts.
162
        self.assertLength(6, self.hpss_calls)
6283.1.4 by Jelmer Vernooij
Add revno hpss call count.
163
164
    def test_simple_branch_revno_lookup(self):
165
        self.setup_smart_server_with_call_log()
166
        t = self.make_branch_and_tree('branch')
167
        self.build_tree_contents([('branch/foo', 'thecontents')])
168
        t.add("foo")
169
        revid1 = t.commit("message")
170
        revid2 = t.commit("message")
171
        self.reset_smart_call_log()
172
        out, err = self.run_bzr(['revno', '-rrevid:' + revid1,
173
            self.get_url('branch')])
174
        # This figure represent the amount of work to perform this use case. It
175
        # is entirely ok to reduce this number if a test fails due to rpc_count
176
        # being too low. If rpc_count increases, more network roundtrips have
177
        # become necessary for this use case. Please do not adjust this number
178
        # upwards without agreement from bzr's network support maintainers.
6263.1.8 by Jelmer Vernooij
Merge bzr.dev, fix hpss call counts.
179
        self.assertLength(5, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
180
        self.assertLength(1, self.hpss_connections)
6352.2.3 by Jelmer Vernooij
s/NoVfsCalls/ContainsNoVfsCalls/.
181
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)