/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5452.4.3 by John Arbash Meinel
Merge bzr.dev to resolve bzr-2.3.txt (aka NEWS)
1
# Copyright (C) 2005-2010 Canonical Ltd
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
2
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
7
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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.
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
12
#
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
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
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
16
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
17
"""Blackbox tests for version_info"""
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
18
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
19
import os
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
20
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy.tests import TestCaseWithTransport
22
from breezy.version_info_formats import VersionInfoBuilder
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
23
6406.1.3 by Jelmer Vernooij
Fix version_info tree.
24
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
25
class TestVersionInfo(TestCaseWithTransport):
0.8.2 by John Arbash Meinel
Have working rio output
26
27
    def test_invalid_format(self):
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
28
        self.run_bzr('version-info --format quijibo', retcode=3)
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
29
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
30
    def create_tree(self):
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
31
        wt = self.make_branch_and_tree('branch')
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
32
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
33
        self.build_tree(['branch/a'])
34
        wt.add('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
35
        wt.commit('adding a', rev_id=b'r1')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
36
37
        self.build_tree(['branch/b'])
38
        wt.add('b')
6855.4.1 by Jelmer Vernooij
Yet more bees.
39
        wt.commit('adding b', rev_id=b'r2')
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
40
        return wt
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
41
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
42
    def test_basic(self):
6165.4.24 by Jelmer Vernooij
Avoid revision_history()
43
        wt = self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
44
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
45
        txt = self.run_bzr('version-info branch')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
46
        self.assertContainsRe(txt, 'date:')
47
        self.assertContainsRe(txt, 'build-date:')
48
        self.assertContainsRe(txt, 'revno: 2')
7143.15.2 by Jelmer Vernooij
Run autopep8.
49
        self.assertContainsRe(txt, 'revision-id: ' +
50
                              wt.branch.last_revision().decode('utf-8'))
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
51
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
52
    def test_all(self):
53
        """'--all' includes clean, revision history, and file revisions"""
6165.4.24 by Jelmer Vernooij
Avoid revision_history()
54
        wt = self.create_tree()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
55
        txt = self.run_bzr('version-info branch --all')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
56
        self.assertContainsRe(txt, 'date:')
57
        self.assertContainsRe(txt, 'revno: 2')
7143.15.2 by Jelmer Vernooij
Run autopep8.
58
        self.assertContainsRe(txt, 'revision-id: ' +
59
                              wt.branch.last_revision().decode('utf-8'))
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
60
        self.assertContainsRe(txt, 'clean: True')
61
        self.assertContainsRe(txt, 'revisions:')
6165.4.24 by Jelmer Vernooij
Avoid revision_history()
62
        for rev_id in wt.branch.repository.all_revision_ids():
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
63
            self.assertContainsRe(txt, 'id: ' + rev_id.decode('utf-8'))
64
        self.assertContainsRe(txt, 'message: adding a')
65
        self.assertContainsRe(txt, 'message: adding b')
66
        self.assertContainsRe(txt, 'file-revisions:')
67
        self.assertContainsRe(txt, 'path: a')
68
        self.assertContainsRe(txt, 'path: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
69
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
70
    def test_clean(self):
71
        """Test that --check-clean includes the right info"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
72
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
73
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
74
        txt = self.run_bzr('version-info branch --check-clean')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
75
        self.assertContainsRe(txt, 'clean: True')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
76
6855.4.1 by Jelmer Vernooij
Yet more bees.
77
        self.build_tree_contents([('branch/c', b'now unclean\n')])
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
78
        txt = self.run_bzr('version-info branch --check-clean')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
79
        self.assertContainsRe(txt, 'clean: False')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
80
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
81
        txt = self.run_bzr('version-info branch --check-clean'
82
                           ' --include-file-revisions')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
83
        self.assertContainsRe(txt, 'revision: unversioned')
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
84
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
85
        os.remove('branch/c')
86
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
87
    def test_no_working_tree(self):
88
        tree = self.create_tree()
89
        branch = self.make_branch('just_branch')
90
        branch.pull(tree.branch)
91
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
92
        txt = self.run_bzr('version-info just_branch')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
93
        self.assertStartsWith(txt, 'revision-id: r2\n')
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
94
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
95
    def assertEqualNoBuildDate(self, text1, text2):
96
        """Compare 2 texts, but ignore the build-date field.
97
98
        build-date is the current timestamp, accurate to seconds. But the
99
        clock is always ticking, and it may have ticked between the time
100
        that text1 and text2 were generated.
101
        """
102
        lines1 = text1.splitlines(True)
103
        lines2 = text2.splitlines(True)
104
        for line1, line2 in zip(lines1, lines2):
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
105
            if line1.startswith('build-date: '):
106
                self.assertStartsWith(line2, 'build-date: ')
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
107
            else:
108
                self.assertEqual(line1, line2)
109
        self.assertEqual(len(lines1), len(lines2))
110
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
111
    def test_no_branch(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
112
        """Test that brz defaults to the local working directory"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
113
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
114
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
115
        txt1 = self.run_bzr('version-info branch')[0]
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
116
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
117
        os.chdir('branch')
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
118
        txt2 = self.run_bzr('version-info')[0]
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
119
        self.assertEqualNoBuildDate(txt1, txt2)
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
120
121
    def test_rio(self):
122
        """Test that we can pass --format=rio"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
123
        self.create_tree()
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
124
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
125
        txt = self.run_bzr('version-info branch')[0]
126
        txt1 = self.run_bzr('version-info --format rio branch')[0]
127
        txt2 = self.run_bzr('version-info --format=rio branch')[0]
2030.1.3 by John Arbash Meinel
Change comparisons to ignore the build-date field
128
        self.assertEqualNoBuildDate(txt, txt1)
129
        self.assertEqualNoBuildDate(txt, txt2)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
130
131
    def test_python(self):
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
132
        """Test that we can do --format=python"""
2030.1.4 by John Arbash Meinel
Add a test that we can find the version info when we only have a branch
133
        self.create_tree()
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
134
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
135
        txt = self.run_bzr('version-info --format python branch')[0]
2022.1.5 by John Arbash Meinel
Cleanup and simplify the blackbox tests
136
2022.1.6 by John Arbash Meinel
small cleanup, remove unused imports
137
        self.assertContainsRe(txt, 'version_info = {')
3207.1.1 by Lukáš Lalinský
Raise a proper error when 'version-info --custom' is used without a template
138
139
    def test_custom_without_template(self):
140
        wt = self.make_branch_and_tree('branch')
141
        out, err = self.run_bzr('version-info --custom', retcode=3)
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
142
        self.assertContainsRe(err, r'ERROR: No template specified\.')
3231.2.1 by James Westby
Make version-info --custom imply --all.
143
144
    def test_custom_implies_all(self):
145
        self.create_tree()
146
        out, err = self.run_bzr('version-info --custom --template='
7143.15.2 by Jelmer Vernooij
Run autopep8.
147
                                '"{revno} {branch_nick} {clean}\n" branch')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
148
        self.assertEqual("2 branch 1\n", out)
149
        self.assertEqual("", err)
6855.4.1 by Jelmer Vernooij
Yet more bees.
150
        self.build_tree_contents([('branch/c', b'now unclean\n')])
3231.2.1 by James Westby
Make version-info --custom imply --all.
151
        out, err = self.run_bzr('version-info --custom --template='
7143.15.2 by Jelmer Vernooij
Run autopep8.
152
                                '"{revno} {branch_nick} {clean}\n" branch')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
153
        self.assertEqual("2 branch 0\n", out)
154
        self.assertEqual("", err)
6234.3.1 by Lawrence Mitchell
Introduce failing test for version-info templates without {clean}
155
156
    def test_custom_no_clean_in_template(self):
157
        def should_not_be_called(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
158
            raise AssertionError(
159
                "Method on %r should not have been used" % (self,))
6234.3.1 by Lawrence Mitchell
Introduce failing test for version-info templates without {clean}
160
        self.overrideAttr(VersionInfoBuilder, "_extract_file_revisions",
161
                          should_not_be_called)
162
        self.create_tree()
7143.15.2 by Jelmer Vernooij
Run autopep8.
163
        out, err = self.run_bzr(
164
            'version-info --custom --template=r{revno} branch')
7045.1.20 by Jelmer Vernooij
Fix per_pack_repository tests.
165
        self.assertEqual("r2", out)
166
        self.assertEqual("", err)
6234.3.1 by Lawrence Mitchell
Introduce failing test for version-info templates without {clean}
167
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
168
    def test_non_ascii(self):
169
        """Test that we can output non-ascii data"""
6406.1.3 by Jelmer Vernooij
Fix version_info tree.
170
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
171
        commit_message = u'Non-ascii message with character not in latin-1: \u1234'
6406.1.3 by Jelmer Vernooij
Fix version_info tree.
172
5436.1.3 by Andrej A Antonov
tiny simplification (remove unnecessary) in test 'blackbox.test_version_info.TestVersionInfo.test_non_ascii'
173
        tree = self.make_branch_and_tree('.')
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
174
        self.build_tree(['a_file'])
175
        tree.add('a_file')
176
        tree.commit(commit_message)
7065.3.6 by Jelmer Vernooij
Fix some more tests.
177
        out, err = self.run_bzr_raw(
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
178
            ['version-info', '--include-history'], encoding='latin-1')
6406.1.3 by Jelmer Vernooij
Fix version_info tree.
179
7065.3.6 by Jelmer Vernooij
Fix some more tests.
180
        commit_message = commit_message.encode('latin-1', 'replace')
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
181
        self.assertContainsString(out, commit_message)
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
182
6196.1.1 by Jelmer Vernooij
Add --revision argument to 'bzr version-info'.
183
    def test_revision(self):
184
        tree = self.create_tree()
185
        branch = self.make_branch('just_branch')
186
        branch.pull(tree.branch)
5436.1.2 by Andrej A Antonov
adding test: blackbox.test_version_info.TestVersionInfo.test_non_ascii
187
6196.1.1 by Jelmer Vernooij
Add --revision argument to 'bzr version-info'.
188
        txt = self.run_bzr('version-info -r1 just_branch')[0]
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
189
        self.assertStartsWith(txt, 'revision-id: r1\n')