/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-2012, 2016 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
"""Tests for version_info"""
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
18
19
import os
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
20
import sys
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
21
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
22
from .. import (
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
23
    registry,
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
24
    tests,
25
    version_info_formats,
26
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
27
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
28
    BytesIO,
29
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
30
from . import TestCaseWithTransport
31
from ..rio import read_stanzas
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
32
6734.1.17 by Jelmer Vernooij
Move format custom errors.
33
from ..version_info_formats.format_custom import (
34
    CustomVersionInfoBuilder,
35
    MissingTemplateVariable,
36
    NoTemplate,
37
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
38
from ..version_info_formats.format_rio import RioVersionInfoBuilder
39
from ..version_info_formats.format_python import PythonVersionInfoBuilder
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
40
41
6406.1.1 by Jelmer Vernooij
Split up version info tests.
42
class VersionInfoTestCase(TestCaseWithTransport):
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
43
44
    def create_branch(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.
45
        wt = self.make_branch_and_tree('branch')
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
46
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
47
        self.build_tree(['branch/a'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
48
        wt.add('a')
49
        wt.commit('a', rev_id='r1')
50
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
51
        self.build_tree(['branch/b'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
52
        wt.add('b')
53
        wt.commit('b', rev_id='r2')
54
2022.1.4 by John Arbash Meinel
test feedback from Robert.
55
        self.build_tree_contents([('branch/a', 'new contents\n')])
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
56
        wt.commit(u'\xe52', rev_id='r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
57
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
58
        return wt
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
59
5967.11.4 by Benoît Pierre
Rename tests helper "create_tree_on_dotted_revno" to "create_tree_with_dotted_revno".
60
    def create_tree_with_dotted_revno(self):
5967.11.1 by Benoît Pierre
Update version-info tests.
61
        wt = self.make_branch_and_tree('branch')
62
        self.build_tree(['branch/a'])
63
        wt.add('a')
64
        wt.commit('a', rev_id='r1')
65
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
66
        other = wt.controldir.sprout('other').open_workingtree()
5967.11.1 by Benoît Pierre
Update version-info tests.
67
        self.build_tree(['other/b.a'])
68
        other.add(['b.a'])
69
        other.commit('b.a', rev_id='o2')
70
71
        os.chdir('branch')
72
        self.run_bzr('merge ../other')
73
        wt.commit('merge', rev_id='merge')
74
75
        wt.update(revision='o2')
76
77
        return wt
78
6406.1.1 by Jelmer Vernooij
Split up version info tests.
79
80
class TestVersionInfoRio(VersionInfoTestCase):
81
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
82
    def test_rio_null(self):
83
        wt = self.make_branch_and_tree('branch')
84
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
85
        sio = BytesIO()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
86
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
87
        builder.generate(sio)
88
        val = sio.getvalue()
89
        self.assertContainsRe(val, 'build-date:')
90
        self.assertContainsRe(val, 'revno: 0')
91
5967.11.1 by Benoît Pierre
Update version-info tests.
92
    def test_rio_dotted_revno(self):
5967.11.4 by Benoît Pierre
Rename tests helper "create_tree_on_dotted_revno" to "create_tree_with_dotted_revno".
93
        wt = self.create_tree_with_dotted_revno()
5967.11.1 by Benoît Pierre
Update version-info tests.
94
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
95
        sio = BytesIO()
5967.11.1 by Benoît Pierre
Update version-info tests.
96
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
97
        builder.generate(sio)
98
        val = sio.getvalue()
99
        self.assertContainsRe(val, 'revno: 1.1.1')
100
6406.1.1 by Jelmer Vernooij
Split up version info tests.
101
    def regen_text(self, wt, **kwargs):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
102
        sio = BytesIO()
6406.1.4 by Jelmer Vernooij
Fix some indentation.
103
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
6406.1.1 by Jelmer Vernooij
Split up version info tests.
104
        builder.generate(sio)
105
        val = sio.getvalue()
106
        return val
107
108
    def test_simple(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.
109
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
110
6406.1.1 by Jelmer Vernooij
Split up version info tests.
111
        val = self.regen_text(wt)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
112
        self.assertContainsRe(val, 'build-date:')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
113
        self.assertContainsRe(val, 'date:')
114
        self.assertContainsRe(val, 'revno: 3')
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
115
        self.assertContainsRe(val, 'revision-id: r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
116
6406.1.1 by Jelmer Vernooij
Split up version info tests.
117
    def test_clean(self):
118
        wt = self.create_branch()
119
        val = self.regen_text(wt, check_for_clean=True)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
120
        self.assertContainsRe(val, 'clean: True')
121
6406.1.1 by Jelmer Vernooij
Split up version info tests.
122
    def test_no_clean(self):
123
        wt = self.create_branch()
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
124
        self.build_tree(['branch/c'])
6406.1.1 by Jelmer Vernooij
Split up version info tests.
125
        val = self.regen_text(wt, check_for_clean=True)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
126
        self.assertContainsRe(val, 'clean: False')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
127
128
    def test_history(self):
129
        wt = self.create_branch()
130
131
        val = self.regen_text(wt, include_revision_history=True)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
132
        self.assertContainsRe(val, 'id: r1')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
133
        self.assertContainsRe(val, 'message: a')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
134
        self.assertContainsRe(val, 'id: r2')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
135
        self.assertContainsRe(val, 'message: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
136
        self.assertContainsRe(val, 'id: r3')
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
137
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
138
6406.1.1 by Jelmer Vernooij
Split up version info tests.
139
    def regen(self, wt, **kwargs):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
140
        sio = BytesIO()
6406.1.4 by Jelmer Vernooij
Fix some indentation.
141
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
6406.1.1 by Jelmer Vernooij
Split up version info tests.
142
        builder.generate(sio)
143
        sio.seek(0)
144
        stanzas = list(read_stanzas(sio))
145
        self.assertEqual(1, len(stanzas))
146
        return stanzas[0]
147
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
148
    def test_rio_version_hook(self):
149
        def update_stanza(rev, stanza):
150
            stanza.add('bla', 'bloe')
151
        RioVersionInfoBuilder.hooks.install_named_hook(
152
            'revision', update_stanza, None)
153
        wt = self.create_branch()
154
6406.1.1 by Jelmer Vernooij
Split up version info tests.
155
        stanza = self.regen(wt)
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
156
        self.assertEqual(['bloe'], stanza.get_all('bla'))
157
6406.1.1 by Jelmer Vernooij
Split up version info tests.
158
    def get_one_stanza(self, stanza, key):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
159
        new_stanzas = list(read_stanzas(BytesIO(stanza[key].encode('utf8'))))
6406.1.1 by Jelmer Vernooij
Split up version info tests.
160
        self.assertEqual(1, len(new_stanzas))
161
        return new_stanzas[0]
162
163
    def test_build_date(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.
164
        wt = self.create_branch()
6406.1.1 by Jelmer Vernooij
Split up version info tests.
165
        stanza = self.regen(wt)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
166
        self.assertTrue('date' in stanza)
167
        self.assertTrue('build-date' in stanza)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
168
        self.assertEqual(['3'], stanza.get_all('revno'))
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
169
        self.assertEqual(['r3'], stanza.get_all('revision-id'))
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
170
6406.1.1 by Jelmer Vernooij
Split up version info tests.
171
    def test_not_clean(self):
172
        wt = self.create_branch()
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
173
        self.build_tree(['branch/c'])
6406.1.1 by Jelmer Vernooij
Split up version info tests.
174
        stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
175
        self.assertEqual(['False'], stanza.get_all('clean'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
176
6406.1.1 by Jelmer Vernooij
Split up version info tests.
177
    def test_file_revisions(self):
178
        wt = self.create_branch()
179
        self.build_tree(['branch/c'])
180
        stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
181
        # This assumes it's being run against a tree that does not update the
182
        # root revision on every commit.
6406.1.1 by Jelmer Vernooij
Split up version info tests.
183
        file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
184
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
185
        self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
186
            file_rev_stanza.get_all('revision'))
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
187
6406.1.1 by Jelmer Vernooij
Split up version info tests.
188
    def test_revision_history(self):
189
        wt = self.create_branch()
190
        stanza = self.regen(wt, include_revision_history=True)
191
        revision_stanza = self.get_one_stanza(stanza, 'revisions')
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
192
        self.assertEqual(['r1', 'r2', 'r3'], revision_stanza.get_all('id'))
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
193
        self.assertEqual(['a', 'b', u'\xe52'], revision_stanza.get_all('message'))
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
194
        self.assertEqual(3, len(revision_stanza.get_all('date')))
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
195
6406.1.1 by Jelmer Vernooij
Split up version info tests.
196
    def test_file_revisions_with_rename(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.
197
        # a was modified, so it should show up modified again
6406.1.1 by Jelmer Vernooij
Split up version info tests.
198
        wt = self.create_branch()
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
199
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
200
        wt.add('c')
201
        wt.rename_one('b', 'd')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
202
        stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
203
        file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
204
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
205
                          file_rev_stanza.get_all('path'))
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
206
        self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
1731.1.50 by Aaron Bentley
Merge bzr.dev
207
                          'renamed from b'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
208
                         file_rev_stanza.get_all('revision'))
209
6406.1.1 by Jelmer Vernooij
Split up version info tests.
210
    def test_file_revisions_with_removal(self):
211
        wt = self.create_branch()
212
        self.build_tree(['branch/a', 'branch/c'])
213
        wt.add('c')
214
        wt.rename_one('b', 'd')
215
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
216
        wt.commit('modified', rev_id='r4')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
217
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
218
        wt.remove(['c', 'd'])
219
        os.remove('branch/d')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
220
        stanza = self.regen(wt, check_for_clean=True, include_file_revisions=True)
221
        file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
222
        self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
223
        self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
224
                         file_rev_stanza.get_all('revision'))
225
6406.1.3 by Jelmer Vernooij
Fix version_info tree.
226
    def test_revision(self):
227
        wt = self.create_branch()
228
        self.build_tree(['branch/a', 'branch/c'])
229
        wt.add('c')
230
        wt.rename_one('b', 'd')
231
232
        stanza = self.regen(wt, check_for_clean=True,
233
            include_file_revisions=True, revision_id=wt.last_revision())
234
        file_rev_stanza = self.get_one_stanza(stanza, 'file-revisions')
235
        self.assertEqual(['', 'a', 'b'], file_rev_stanza.get_all('path'))
236
        self.assertEqual(['r1', 'r3', 'r2'],
237
                         file_rev_stanza.get_all('revision'))
238
6406.1.1 by Jelmer Vernooij
Split up version info tests.
239
240
class PythonVersionInfoTests(VersionInfoTestCase):
241
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
242
    def test_python_null(self):
243
        wt = self.make_branch_and_tree('branch')
244
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
245
        sio = BytesIO()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
246
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
247
        builder.generate(sio)
248
        val = sio.getvalue()
249
        self.assertContainsRe(val, "'revision_id': None")
5967.11.1 by Benoît Pierre
Update version-info tests.
250
        self.assertContainsRe(val, "'revno': '0'")
5598.1.1 by Soren Hansen
Fix PEP-8 violation in PythonVersionInfoBuilder's output
251
        self.assertNotContainsString(val, '\n\n\n\n')
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
252
5967.11.1 by Benoît Pierre
Update version-info tests.
253
    def test_python_dotted_revno(self):
5967.11.4 by Benoît Pierre
Rename tests helper "create_tree_on_dotted_revno" to "create_tree_with_dotted_revno".
254
        wt = self.create_tree_with_dotted_revno()
5967.11.1 by Benoît Pierre
Update version-info tests.
255
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
256
        sio = BytesIO()
5967.11.1 by Benoît Pierre
Update version-info tests.
257
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
258
        builder.generate(sio)
259
        val = sio.getvalue()
260
        self.assertContainsRe(val, "'revno': '1.1.1'")
261
6406.1.1 by Jelmer Vernooij
Split up version info tests.
262
    def regen(self, wt, **kwargs):
263
        """Create a test module, import and return it"""
264
        outf = open('test_version_information.py', 'wb')
265
        try:
266
            builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
267
                                               **kwargs)
268
            builder.generate(outf)
269
        finally:
270
            outf.close()
6799 by Jelmer Vernooij
Merge lp:~jelmer/brz/escaping.
271
        import imp
6406.1.1 by Jelmer Vernooij
Split up version info tests.
272
        module_info = imp.find_module('test_version_information',
6619.3.26 by Martin
Fix fallout from 2to3 getcwdu transformation and other test uses
273
                                      [self.test_dir])
6406.1.1 by Jelmer Vernooij
Split up version info tests.
274
        tvi = imp.load_module('tvi', *module_info)
275
        # Make sure the module isn't cached
276
        sys.modules.pop('tvi', None)
277
        sys.modules.pop('test_version_information', None)
278
        # Delete the compiled versions, because we are generating
279
        # a new file fast enough that python doesn't detect it
280
        # needs to recompile, and using sleep() just makes the
281
        # test slow
282
        if os.path.exists('test_version_information.pyc'):
283
            os.remove('test_version_information.pyc')
284
        if os.path.exists('test_version_information.pyo'):
285
            os.remove('test_version_information.pyo')
286
        return tvi
287
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
288
    def test_python_version(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.
289
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
290
6406.1.1 by Jelmer Vernooij
Split up version info tests.
291
        tvi = self.regen(wt)
5967.11.1 by Benoît Pierre
Update version-info tests.
292
        self.assertEqual('3', tvi.version_info['revno'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
293
        self.assertEqual('r3', tvi.version_info['revision_id'])
6619.3.1 by Jelmer Vernooij
Apply 2to3 has_key fix.
294
        self.assertTrue('date' in tvi.version_info)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
295
        self.assertEqual(None, tvi.version_info['clean'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
296
6406.1.1 by Jelmer Vernooij
Split up version info tests.
297
        tvi = self.regen(wt, check_for_clean=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
298
        self.assertEqual(True, tvi.version_info['clean'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
299
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
300
        self.build_tree(['branch/c'])
6406.1.1 by Jelmer Vernooij
Split up version info tests.
301
        tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
302
        self.assertEqual(False, tvi.version_info['clean'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
303
        self.assertEqual(['', 'a', 'b', 'c'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
304
                         sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
305
        self.assertEqual('r3', tvi.file_revisions['a'])
306
        self.assertEqual('r2', tvi.file_revisions['b'])
307
        self.assertEqual('unversioned', tvi.file_revisions['c'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
308
        os.remove('branch/c')
309
6406.1.1 by Jelmer Vernooij
Split up version info tests.
310
        tvi = self.regen(wt, include_revision_history=True)
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
311
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
312
        rev_info = [(rev, message) for rev, message, timestamp, timezone
313
                                   in tvi.revisions]
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
314
        self.assertEqual([('r1', 'a'), ('r2', 'b'), ('r3', u'\xe52')], rev_info)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
315
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
316
        # a was modified, so it should show up modified again
317
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
318
        wt.add('c')
319
        wt.rename_one('b', 'd')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
320
        tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
321
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
322
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
323
        self.assertEqual('modified', tvi.file_revisions['a'])
324
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
325
        self.assertEqual('new', tvi.file_revisions['c'])
326
        self.assertEqual('renamed from b', tvi.file_revisions['d'])
327
328
        wt.commit('modified', rev_id='r4')
329
        wt.remove(['c', 'd'])
330
        os.remove('branch/d')
6406.1.1 by Jelmer Vernooij
Split up version info tests.
331
        tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
332
        self.assertEqual(['', 'a', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
333
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
334
        self.assertEqual('r4', tvi.file_revisions['a'])
335
        self.assertEqual('unversioned', tvi.file_revisions['c'])
336
        self.assertEqual('removed', tvi.file_revisions['d'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
337
6406.1.1 by Jelmer Vernooij
Split up version info tests.
338
339
class CustomVersionInfoTests(VersionInfoTestCase):
340
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
341
    def test_custom_null(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
342
        sio = BytesIO()
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
343
        wt = self.make_branch_and_tree('branch')
344
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
345
            template='revno: {revno}')
346
        builder.generate(sio)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
347
        self.assertEqual("revno: 0", sio.getvalue())
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
348
349
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
350
            template='{revno} revid: {revision_id}')
351
        # revision_id is not available yet
6734.1.17 by Jelmer Vernooij
Move format custom errors.
352
        self.assertRaises(MissingTemplateVariable, builder.generate, sio)
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
353
5967.11.1 by Benoît Pierre
Update version-info tests.
354
    def test_custom_dotted_revno(self):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
355
        sio = BytesIO()
5967.11.4 by Benoît Pierre
Rename tests helper "create_tree_on_dotted_revno" to "create_tree_with_dotted_revno".
356
        wt = self.create_tree_with_dotted_revno()
5967.11.1 by Benoît Pierre
Update version-info tests.
357
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
358
            template='{revno} revid: {revision_id}')
359
        builder.generate(sio)
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
360
        self.assertEqual("1.1.1 revid: o2", sio.getvalue())
5967.11.1 by Benoît Pierre
Update version-info tests.
361
6406.1.1 by Jelmer Vernooij
Split up version info tests.
362
    def regen(self, wt, tpl, **kwargs):
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
363
        sio = BytesIO()
6406.1.1 by Jelmer Vernooij
Split up version info tests.
364
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
365
                                           template=tpl, **kwargs)
366
        builder.generate(sio)
367
        val = sio.getvalue()
368
        return val
369
370
    def test_build_date(self):
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
371
        wt = self.create_branch()
372
6406.1.1 by Jelmer Vernooij
Split up version info tests.
373
        val = self.regen(wt, 'build-date: "{build_date}"\ndate: "{date}"')
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
374
        self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
375
        self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
376
6406.1.1 by Jelmer Vernooij
Split up version info tests.
377
    def test_revno(self):
378
        wt = self.create_branch()
379
        val = self.regen(wt, 'revno: {revno}')
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
380
        self.assertEqual(val, 'revno: 3')
381
6406.1.1 by Jelmer Vernooij
Split up version info tests.
382
    def test_revision_id(self):
383
        wt = self.create_branch()
384
        val = self.regen(wt, 'revision-id: {revision_id}')
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
385
        self.assertEqual(val, 'revision-id: r3')
386
6406.1.1 by Jelmer Vernooij
Split up version info tests.
387
    def test_clean(self):
388
        wt = self.create_branch()
389
        val = self.regen(wt, 'clean: {clean}', check_for_clean=True)
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
390
        self.assertEqual(val, 'clean: 1')
391
6406.1.1 by Jelmer Vernooij
Split up version info tests.
392
    def test_not_clean(self):
393
        wt = self.create_branch()
394
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
395
        self.build_tree(['branch/c'])
6406.1.1 by Jelmer Vernooij
Split up version info tests.
396
        val = self.regen(wt, 'clean: {clean}', check_for_clean=True)
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
397
        self.assertEqual(val, 'clean: 0')
398
        os.remove('branch/c')
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
399
3207.1.1 by Lukáš Lalinský
Raise a proper error when 'version-info --custom' is used without a template
400
    def test_custom_without_template(self):
401
        builder = CustomVersionInfoBuilder(None)
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
402
        sio = BytesIO()
6734.1.17 by Jelmer Vernooij
Move format custom errors.
403
        self.assertRaises(NoTemplate, builder.generate, sio)
3207.1.1 by Lukáš Lalinský
Raise a proper error when 'version-info --custom' is used without a template
404
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
405
406
class TestBuilder(version_info_formats.VersionInfoBuilder):
407
    pass
408
409
410
class TestVersionInfoFormatRegistry(tests.TestCase):
411
412
    def setUp(self):
413
        super(TestVersionInfoFormatRegistry, self).setUp()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
414
        self.overrideAttr(version_info_formats,
415
                          'format_registry', registry.Registry())
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
416
417
    def test_register_remove(self):
418
        registry = version_info_formats.format_registry
419
        registry.register('testbuilder',
420
            TestBuilder, 'a simple test builder')
421
        self.assertIs(TestBuilder, registry.get('testbuilder'))
422
        self.assertEqual('a simple test builder',
423
                         registry.get_help('testbuilder'))
424
        registry.remove('testbuilder')
425
        self.assertRaises(KeyError, registry.get, 'testbuilder')