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