~bzr-pqm/bzr/bzr.dev

0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
1
# Copyright (C) 2005, 2006 Canonical Ltd
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
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
19
from cStringIO import StringIO
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
import imp
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
21
import os
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
22
import sys
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
23
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
24
from bzrlib import (
3207.1.1 by Lukáš Lalinský
Raise a proper error when 'version-info --custom' is used without a template
25
    errors,
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
26
    registry,
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
27
    symbol_versioning,
28
    tests,
29
    version_info_formats,
30
    )
2022.1.3 by John Arbash Meinel
Remove unused imports
31
from bzrlib.tests import TestCaseWithTransport
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
32
from bzrlib.rio import read_stanzas
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
33
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
34
from bzrlib.version_info_formats.format_custom import CustomVersionInfoBuilder
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
35
from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
36
from bzrlib.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.
37
38
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
39
class TestVersionInfo(TestCaseWithTransport):
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
40
41
    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.
42
        wt = self.make_branch_and_tree('branch')
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
43
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
44
        self.build_tree(['branch/a'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
45
        wt.add('a')
46
        wt.commit('a', rev_id='r1')
47
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
48
        self.build_tree(['branch/b'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
49
        wt.add('b')
50
        wt.commit('b', rev_id='r2')
51
2022.1.4 by John Arbash Meinel
test feedback from Robert.
52
        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
53
        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
54
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
55
        return wt
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
56
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
57
    def test_rio_null(self):
58
        wt = self.make_branch_and_tree('branch')
59
60
        sio = StringIO()
61
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
62
        builder.generate(sio)
63
        val = sio.getvalue()
64
        self.assertContainsRe(val, 'build-date:')
65
        self.assertContainsRe(val, 'revno: 0')
66
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
67
    def test_rio_version_text(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.
68
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
69
70
        def regen(**kwargs):
71
            sio = StringIO()
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
72
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
73
                                            **kwargs)
74
            builder.generate(sio)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
75
            val = sio.getvalue()
76
            return val
77
78
        val = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
79
        self.assertContainsRe(val, 'build-date:')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
80
        self.assertContainsRe(val, 'date:')
81
        self.assertContainsRe(val, 'revno: 3')
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
82
        self.assertContainsRe(val, 'revision-id: r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
83
84
        val = regen(check_for_clean=True)
85
        self.assertContainsRe(val, 'clean: True')
86
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
87
        self.build_tree(['branch/c'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
88
        val = regen(check_for_clean=True)
89
        self.assertContainsRe(val, 'clean: False')
90
        os.remove('branch/c')
91
92
        val = regen(include_revision_history=True)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
93
        self.assertContainsRe(val, 'id: r1')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
94
        self.assertContainsRe(val, 'message: a')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
95
        self.assertContainsRe(val, 'id: r2')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
96
        self.assertContainsRe(val, 'message: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
97
        self.assertContainsRe(val, 'id: r3')
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
98
        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
99
4216.4.1 by Jelmer Vernooij
Allow hooks to add new entries to version-info.
100
    def test_rio_version_hook(self):
101
        def update_stanza(rev, stanza):
102
            stanza.add('bla', 'bloe')
103
        RioVersionInfoBuilder.hooks.install_named_hook(
104
            'revision', update_stanza, None)
105
        wt = self.create_branch()
106
107
        def regen(**kwargs):
108
            sio = StringIO()
109
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
110
                                            **kwargs)
111
            builder.generate(sio)
112
            sio.seek(0)
113
            stanzas = list(read_stanzas(sio))
114
            self.assertEqual(1, len(stanzas))
115
            return stanzas[0]
116
117
        stanza = regen()
118
        self.assertEqual(['bloe'], stanza.get_all('bla'))
119
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
120
    def test_rio_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.
121
        wt = self.create_branch()
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
122
123
        def regen(**kwargs):
124
            sio = StringIO()
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
125
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
126
                                            **kwargs)
127
            builder.generate(sio)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
128
            sio.seek(0)
129
            stanzas = list(read_stanzas(sio))
130
            self.assertEqual(1, len(stanzas))
131
            return stanzas[0]
132
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
133
        def get_one_stanza(stanza, key):
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
134
            new_stanzas = list(read_stanzas(
135
                                StringIO(stanza[key].encode('utf8'))))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
136
            self.assertEqual(1, len(new_stanzas))
137
            return new_stanzas[0]
138
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
139
        stanza = regen()
140
        self.failUnless('date' in stanza)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
141
        self.failUnless('build-date' in stanza)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
142
        self.assertEqual(['3'], stanza.get_all('revno'))
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
143
        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.
144
145
        stanza = regen(check_for_clean=True)
146
        self.assertEqual(['True'], stanza.get_all('clean'))
147
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
148
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
149
        stanza = regen(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.
150
        self.assertEqual(['False'], stanza.get_all('clean'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
151
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
152
        # This assumes it's being run against a tree that does not update the
153
        # root revision on every commit.
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
154
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
155
        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.
156
        self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
157
            file_rev_stanza.get_all('revision'))
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
158
        os.remove('branch/c')
159
160
        stanza = regen(include_revision_history=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
161
        revision_stanza = get_one_stanza(stanza, 'revisions')
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
162
        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
163
        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.
164
        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.
165
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
166
        # a was modified, so it should show up modified again
167
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
168
        wt.add('c')
169
        wt.rename_one('b', 'd')
170
        stanza = regen(check_for_clean=True, include_file_revisions=True)
171
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
172
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
173
                          file_rev_stanza.get_all('path'))
4599.4.2 by Robert Collins
Update test_version_info for rich root test data.
174
        self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
1731.1.50 by Aaron Bentley
Merge bzr.dev
175
                          'renamed from b'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
176
                         file_rev_stanza.get_all('revision'))
177
178
        wt.commit('modified', rev_id='r4')
179
        wt.remove(['c', 'd'])
180
        os.remove('branch/d')
181
        stanza = regen(check_for_clean=True, include_file_revisions=True)
182
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
183
        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.
184
        self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
185
                         file_rev_stanza.get_all('revision'))
186
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
187
    def test_python_null(self):
188
        wt = self.make_branch_and_tree('branch')
189
190
        sio = StringIO()
191
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
192
        builder.generate(sio)
193
        val = sio.getvalue()
194
        self.assertContainsRe(val, "'revision_id': None")
195
        self.assertContainsRe(val, "'revno': 0")
196
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
197
    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.
198
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
199
200
        def regen(**kwargs):
2022.1.4 by John Arbash Meinel
test feedback from Robert.
201
            """Create a test module, import and return it"""
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
202
            outf = open('test_version_information.py', 'wb')
2022.1.4 by John Arbash Meinel
test feedback from Robert.
203
            try:
204
                builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
205
                                                   **kwargs)
206
                builder.generate(outf)
207
            finally:
208
                outf.close()
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
209
            module_info = imp.find_module('test_version_information',
210
                                          [os.getcwdu()])
211
            tvi = imp.load_module('tvi', *module_info)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
212
            # Make sure the module isn't cached
213
            sys.modules.pop('tvi', None)
214
            sys.modules.pop('test_version_information', None)
215
            # Delete the compiled versions, because we are generating
216
            # a new file fast enough that python doesn't detect it
217
            # needs to recompile, and using sleep() just makes the
218
            # test slow
219
            if os.path.exists('test_version_information.pyc'):
220
                os.remove('test_version_information.pyc')
221
            if os.path.exists('test_version_information.pyo'):
222
                os.remove('test_version_information.pyo')
223
            return tvi
224
225
        tvi = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
226
        self.assertEqual(3, tvi.version_info['revno'])
227
        self.assertEqual('r3', tvi.version_info['revision_id'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
228
        self.failUnless(tvi.version_info.has_key('date'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
229
        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
230
231
        tvi = regen(check_for_clean=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
232
        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
233
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
234
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
235
        tvi = regen(check_for_clean=True, include_file_revisions=True)
236
        self.assertEqual(False, tvi.version_info['clean'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
237
        self.assertEqual(['', 'a', 'b', 'c'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
238
                         sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
239
        self.assertEqual('r3', tvi.file_revisions['a'])
240
        self.assertEqual('r2', tvi.file_revisions['b'])
241
        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
242
        os.remove('branch/c')
243
244
        tvi = regen(include_revision_history=True)
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
245
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
246
        rev_info = [(rev, message) for rev, message, timestamp, timezone
247
                                   in tvi.revisions]
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
248
        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.
249
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
250
        # a was modified, so it should show up modified again
251
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
252
        wt.add('c')
253
        wt.rename_one('b', 'd')
254
        tvi = regen(check_for_clean=True, include_file_revisions=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
255
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
256
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
257
        self.assertEqual('modified', tvi.file_revisions['a'])
258
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
259
        self.assertEqual('new', tvi.file_revisions['c'])
260
        self.assertEqual('renamed from b', tvi.file_revisions['d'])
261
262
        wt.commit('modified', rev_id='r4')
263
        wt.remove(['c', 'd'])
264
        os.remove('branch/d')
265
        tvi = regen(check_for_clean=True, include_file_revisions=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
266
        self.assertEqual(['', 'a', 'c', 'd'],
1731.1.50 by Aaron Bentley
Merge bzr.dev
267
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
268
        self.assertEqual('r4', tvi.file_revisions['a'])
269
        self.assertEqual('unversioned', tvi.file_revisions['c'])
270
        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
271
4250.1.1 by Jelmer Vernooij
Fix version-info in empty branches.
272
    def test_custom_null(self):
273
        sio = StringIO()
274
        wt = self.make_branch_and_tree('branch')
275
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
276
            template='revno: {revno}')
277
        builder.generate(sio)
278
        self.assertEquals("revno: 0", sio.getvalue())
279
280
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
281
            template='{revno} revid: {revision_id}')
282
        # revision_id is not available yet
283
        self.assertRaises(errors.MissingTemplateVariable, 
284
            builder.generate, sio)
285
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
286
    def test_custom_version_text(self):
287
        wt = self.create_branch()
288
289
        def regen(tpl, **kwargs):
290
            sio = StringIO()
291
            builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
292
                                               template=tpl, **kwargs)
293
            builder.generate(sio)
294
            val = sio.getvalue()
295
            return val
296
297
        val = regen('build-date: "{build_date}"\ndate: "{date}"')
298
        self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
299
        self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
300
301
        val = regen('revno: {revno}')
302
        self.assertEqual(val, 'revno: 3')
303
304
        val = regen('revision-id: {revision_id}')
305
        self.assertEqual(val, 'revision-id: r3')
306
307
        val = regen('clean: {clean}', check_for_clean=True)
308
        self.assertEqual(val, 'clean: 1')
309
310
        self.build_tree(['branch/c'])
311
        val = regen('clean: {clean}', check_for_clean=True)
312
        self.assertEqual(val, 'clean: 0')
313
        os.remove('branch/c')
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
314
3207.1.1 by Lukáš Lalinský
Raise a proper error when 'version-info --custom' is used without a template
315
    def test_custom_without_template(self):
316
        builder = CustomVersionInfoBuilder(None)
317
        sio = StringIO()
318
        self.assertRaises(errors.NoTemplate, builder.generate, sio)
319
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
320
321
class TestBuilder(version_info_formats.VersionInfoBuilder):
322
    pass
323
324
325
class TestVersionInfoFormatRegistry(tests.TestCase):
326
327
    def setUp(self):
328
        super(TestVersionInfoFormatRegistry, self).setUp()
4985.1.5 by Vincent Ladeuil
Deploying the new overrideAttr facility further reduces the complexity
329
        self.overrideAttr(version_info_formats,
330
                          'format_registry', registry.Registry())
3138.1.1 by John Arbash Meinel
Fix bug #175886: version_info deprecated functions should be tested to still work.
331
332
    def test_register_remove(self):
333
        registry = version_info_formats.format_registry
334
        registry.register('testbuilder',
335
            TestBuilder, 'a simple test builder')
336
        self.assertIs(TestBuilder, registry.get('testbuilder'))
337
        self.assertEqual('a simple test builder',
338
                         registry.get_help('testbuilder'))
339
        registry.remove('testbuilder')
340
        self.assertRaises(KeyError, registry.get, 'testbuilder')