~bzr-pqm/bzr/bzr.dev

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