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