/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
7143.8.1 by Jelmer Vernooij
Cope with the revno not being known.
24
from breezy.errors import NoSuchRevision
7490.48.2 by Jelmer Vernooij
Move some bzr-specific test modules to breezy.bzr.tests.
25
from breezy.bzr.tests.matchers import ContainsNoVfsCalls
6352.2.2 by Jelmer Vernooij
Use new NoVfsCalls matcher in blackbox tests.
26
1185.50.17 by John Arbash Meinel
Forgot to add the test case
27
4409.1.21 by Vincent Ladeuil
Fix failing test.
28
class TestRevno(tests.TestCaseWithTransport):
1185.50.17 by John Arbash Meinel
Forgot to add the test case
29
30
    def test_revno(self):
31
32
        def bzr(*args, **kwargs):
33
            return self.run_bzr(*args, **kwargs)[0]
34
35
        os.mkdir('a')
36
        os.chdir('a')
37
        bzr('init')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
38
        self.assertEqual(int(bzr('revno')), 0)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
39
7143.15.2 by Jelmer Vernooij
Run autopep8.
40
        with open('foo', 'wb') as f:
41
            f.write(b'foo\n')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
42
        bzr('add foo')
43
        bzr('commit -m foo')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
44
        self.assertEqual(int(bzr('revno')), 1)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
45
46
        os.mkdir('baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        bzr('add baz')
48
        bzr('commit -m baz')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
49
        self.assertEqual(int(bzr('revno')), 2)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
50
51
        os.chdir('..')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
52
        self.assertEqual(int(bzr('revno a')), 2)
53
        self.assertEqual(int(bzr('revno a/baz')), 2)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
54
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
55
    def test_revno_tree(self):
56
        # Make branch and checkout
4409.1.8 by John Arbash Meinel
Small tweaks to to the tests for --tree support.
57
        wt = self.make_branch_and_tree('branch')
58
        checkout = wt.branch.create_checkout('checkout', lightweight=True)
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
59
60
        # Get the checkout out of date
61
        self.build_tree(['branch/file'])
4409.1.8 by John Arbash Meinel
Small tweaks to to the tests for --tree support.
62
        wt.add(['file'])
63
        wt.commit('mkfile')
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
64
65
        # Make sure revno says we're on 1
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
66
        out, err = self.run_bzr('revno checkout')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
67
        self.assertEqual('', err)
68
        self.assertEqual('1\n', out)
4409.1.2 by Matthew Fuller
Add tests for revno --tree.
69
70
        # Make sure --tree knows it's still on 0
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
71
        out, err = self.run_bzr('revno --tree checkout')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
72
        self.assertEqual('', err)
73
        self.assertEqual('0\n', out)
1185.50.17 by John Arbash Meinel
Forgot to add the test case
74
4409.1.16 by Matthew Fuller
Add a test for revno --tree on something without a tree.
75
    def test_revno_tree_no_tree(self):
76
        # Make treeless branch
77
        b = self.make_branch('branch')
78
79
        # Try getting it's --tree revno
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
80
        out, err = self.run_bzr('revno --tree branch', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
81
        self.assertEqual('', out)
82
        self.assertEqual('brz: ERROR: No WorkingTree exists for "branch".\n',
7143.15.2 by Jelmer Vernooij
Run autopep8.
83
                         err)
4409.1.16 by Matthew Fuller
Add a test for revno --tree on something without a tree.
84
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
85
    def test_dotted_revno_tree(self):
86
        builder = self.make_branch_builder('branch')
87
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
88
        builder.build_snapshot(None, [
6973.13.2 by Jelmer Vernooij
Fix some more tests.
89
            ('add', ('', b'root-id', 'directory', None)),
90
            ('add', ('file', b'file-id', 'file', b'content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
91
            revision_id=b'A-id')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
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')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
94
        builder.finish_series()
95
        b = builder.get_branch()
96
        co_b = b.create_checkout('checkout_b', lightweight=True,
6855.4.1 by Jelmer Vernooij
Yet more bees.
97
                                 revision_id=b'B-id')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
98
        out, err = self.run_bzr('revno checkout_b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
99
        self.assertEqual('', err)
100
        self.assertEqual('2\n', out)
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
101
        out, err = self.run_bzr('revno --tree checkout_b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
102
        self.assertEqual('', err)
103
        self.assertEqual('1.1.1\n', out)
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
104
105
    def test_stale_revno_tree(self):
106
        builder = self.make_branch_builder('branch')
107
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
108
        builder.build_snapshot(None, [
6855.4.1 by Jelmer Vernooij
Yet more bees.
109
            ('add', ('', b'root-id', 'directory', None)),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
110
            ('add', ('file', b'file-id', 'file', b'content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
111
            revision_id=b'A-id')
6973.13.2 by Jelmer Vernooij
Fix some more tests.
112
        builder.build_snapshot([b'A-id'], [], revision_id=b'B-id')
113
        builder.build_snapshot([b'A-id'], [], revision_id=b'C-id')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
114
        builder.finish_series()
115
        b = builder.get_branch()
116
        # The branch is now at "C-id", but the checkout is still at "B-id"
117
        # which is no longer in the history
118
        co_b = b.create_checkout('checkout_b', lightweight=True,
6855.4.1 by Jelmer Vernooij
Yet more bees.
119
                                 revision_id=b'B-id')
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
120
        out, err = self.run_bzr('revno checkout_b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
121
        self.assertEqual('', err)
122
        self.assertEqual('2\n', out)
4409.1.9 by John Arbash Meinel
Add tests that dotted revno and unknown revno are both supported.
123
        out, err = self.run_bzr('revno --tree checkout_b')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
124
        self.assertEqual('', err)
125
        self.assertEqual('???\n', out)
6202.1.1 by Jelmer Vernooij
'bzr revno' now takes a --revision argument.
126
7143.8.1 by Jelmer Vernooij
Cope with the revno not being known.
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
6202.1.1 by Jelmer Vernooij
'bzr revno' now takes a --revision argument.
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 .')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
151
        self.assertEqual('1\n', out)
6202.1.1 by Jelmer Vernooij
'bzr revno' now takes a --revision argument.
152
7045.4.10 by Jelmer Vernooij
Fix a couple more tests.
153
        out, err = self.run_bzr('revno -rrevid:%s .' % revid1.decode('utf-8'))
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
154
        self.assertEqual('1\n', out)
6202.1.2 by Jelmer Vernooij
Add check for using --tree and --revision together.
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)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
159
        self.assertEqual('', out)
6202.1.2 by Jelmer Vernooij
Add check for using --tree and --revision together.
160
        self.assertEqual(
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
161
            '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.
162
            err)