/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
2022.1.3 by John Arbash Meinel
Remove unused imports
24
from bzrlib.tests import TestCaseWithTransport
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
25
from bzrlib.rio import read_stanzas
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
26
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
27
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
28
from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
29
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.
30
31
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
32
class TestVersionInfo(TestCaseWithTransport):
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
33
34
    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.
35
        wt = self.make_branch_and_tree('branch')
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
36
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
37
        self.build_tree(['branch/a'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
38
        wt.add('a')
39
        wt.commit('a', rev_id='r1')
40
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
        self.build_tree(['branch/b'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
42
        wt.add('b')
43
        wt.commit('b', rev_id='r2')
44
2022.1.4 by John Arbash Meinel
test feedback from Robert.
45
        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
46
        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
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
        return wt
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
49
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
50
    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.
51
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
52
53
        def regen(**kwargs):
54
            sio = StringIO()
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
55
            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.
56
                                            **kwargs)
57
            builder.generate(sio)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
58
            val = sio.getvalue()
59
            return val
60
61
        val = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
62
        self.assertContainsRe(val, 'build-date:')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
63
        self.assertContainsRe(val, 'date:')
64
        self.assertContainsRe(val, 'revno: 3')
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
65
        self.assertContainsRe(val, 'revision-id: r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
66
67
        val = regen(check_for_clean=True)
68
        self.assertContainsRe(val, 'clean: True')
69
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
70
        self.build_tree(['branch/c'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
71
        val = regen(check_for_clean=True)
72
        self.assertContainsRe(val, 'clean: False')
73
        os.remove('branch/c')
74
75
        val = regen(include_revision_history=True)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
76
        self.assertContainsRe(val, 'id: r1')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
77
        self.assertContainsRe(val, 'message: a')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
78
        self.assertContainsRe(val, 'id: r2')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
79
        self.assertContainsRe(val, 'message: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
80
        self.assertContainsRe(val, 'id: r3')
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
81
        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
82
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
83
    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.
84
        wt = self.create_branch()
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
85
86
        def regen(**kwargs):
87
            sio = StringIO()
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
88
            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.
89
                                            **kwargs)
90
            builder.generate(sio)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
91
            sio.seek(0)
92
            stanzas = list(read_stanzas(sio))
93
            self.assertEqual(1, len(stanzas))
94
            return stanzas[0]
95
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
96
        def get_one_stanza(stanza, key):
2022.1.1 by John Arbash Meinel
[merge] version-info plugin, and cleanup for layout in bzr
97
            new_stanzas = list(read_stanzas(
98
                                StringIO(stanza[key].encode('utf8'))))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
99
            self.assertEqual(1, len(new_stanzas))
100
            return new_stanzas[0]
101
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
102
        stanza = regen()
103
        self.failUnless('date' in stanza)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
104
        self.failUnless('build-date' in stanza)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
105
        self.assertEqual(['3'], stanza.get_all('revno'))
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
106
        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.
107
108
        stanza = regen(check_for_clean=True)
109
        self.assertEqual(['True'], stanza.get_all('clean'))
110
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
111
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
112
        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.
113
        self.assertEqual(['False'], stanza.get_all('clean'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
114
2903.2.9 by Martin Pool
Review cleanups, mostly documentation
115
        # XXX: This assumes it's being run against a repository that updates
116
        # the root revision on every commit.  Newer ones that use
2903.2.2 by Martin Pool
doc
117
        # RootCommitBuilder won't update it on each commit.
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
118
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
119
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
120
        self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
121
            file_rev_stanza.get_all('revision'))
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
122
        os.remove('branch/c')
123
124
        stanza = regen(include_revision_history=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
125
        revision_stanza = get_one_stanza(stanza, 'revisions')
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
126
        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
127
        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.
128
        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.
129
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
130
        # a was modified, so it should show up modified again
131
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
132
        wt.add('c')
133
        wt.rename_one('b', 'd')
134
        stanza = regen(check_for_clean=True, include_file_revisions=True)
135
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
136
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
137
                          file_rev_stanza.get_all('path'))
138
        self.assertEqual(['r3', 'modified', 'renamed to d', 'new', 
139
                          'renamed from b'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
140
                         file_rev_stanza.get_all('revision'))
141
142
        wt.commit('modified', rev_id='r4')
143
        wt.remove(['c', 'd'])
144
        os.remove('branch/d')
145
        stanza = regen(check_for_clean=True, include_file_revisions=True)
146
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
1731.1.50 by Aaron Bentley
Merge bzr.dev
147
        self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
148
        self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
149
                         file_rev_stanza.get_all('revision'))
150
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
151
    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.
152
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
153
154
        def regen(**kwargs):
2022.1.4 by John Arbash Meinel
test feedback from Robert.
155
            """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
156
            outf = open('test_version_information.py', 'wb')
2022.1.4 by John Arbash Meinel
test feedback from Robert.
157
            try:
158
                builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
159
                                                   **kwargs)
160
                builder.generate(outf)
161
            finally:
162
                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.
163
            module_info = imp.find_module('test_version_information',
164
                                          [os.getcwdu()])
165
            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
166
            # Make sure the module isn't cached
167
            sys.modules.pop('tvi', None)
168
            sys.modules.pop('test_version_information', None)
169
            # Delete the compiled versions, because we are generating
170
            # a new file fast enough that python doesn't detect it
171
            # needs to recompile, and using sleep() just makes the
172
            # test slow
173
            if os.path.exists('test_version_information.pyc'):
174
                os.remove('test_version_information.pyc')
175
            if os.path.exists('test_version_information.pyo'):
176
                os.remove('test_version_information.pyo')
177
            return tvi
178
179
        tvi = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
180
        self.assertEqual(3, tvi.version_info['revno'])
181
        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
182
        self.failUnless(tvi.version_info.has_key('date'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
183
        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
184
185
        tvi = regen(check_for_clean=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
186
        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
187
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
188
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
189
        tvi = regen(check_for_clean=True, include_file_revisions=True)
190
        self.assertEqual(False, tvi.version_info['clean'])
1731.1.50 by Aaron Bentley
Merge bzr.dev
191
        self.assertEqual(['', 'a', 'b', 'c'], 
192
                         sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
193
        self.assertEqual('r3', tvi.file_revisions['a'])
194
        self.assertEqual('r2', tvi.file_revisions['b'])
195
        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
196
        os.remove('branch/c')
197
198
        tvi = regen(include_revision_history=True)
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
199
0.8.23 by John Arbash Meinel
whitespace and formatting cleanups.
200
        rev_info = [(rev, message) for rev, message, timestamp, timezone
201
                                   in tvi.revisions]
2030.1.2 by John Arbash Meinel
Change the version-info --format=rio to support unicode messages
202
        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.
203
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
204
        # a was modified, so it should show up modified again
205
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
206
        wt.add('c')
207
        wt.rename_one('b', 'd')
208
        tvi = regen(check_for_clean=True, include_file_revisions=True)
1731.1.50 by Aaron Bentley
Merge bzr.dev
209
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
210
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
211
        self.assertEqual('modified', tvi.file_revisions['a'])
212
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
213
        self.assertEqual('new', tvi.file_revisions['c'])
214
        self.assertEqual('renamed from b', tvi.file_revisions['d'])
215
216
        wt.commit('modified', rev_id='r4')
217
        wt.remove(['c', 'd'])
218
        os.remove('branch/d')
219
        tvi = regen(check_for_clean=True, include_file_revisions=True)
1731.1.50 by Aaron Bentley
Merge bzr.dev
220
        self.assertEqual(['', 'a', 'c', 'd'], 
221
                          sorted(tvi.file_revisions.keys()))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
222
        self.assertEqual('r4', tvi.file_revisions['a'])
223
        self.assertEqual('unversioned', tvi.file_revisions['c'])
224
        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
225
2948.4.1 by Lukáš Lalinský
Custom template-based version info formatter.
226
    def test_custom_version_text(self):
227
        wt = self.create_branch()
228
229
        def regen(tpl, **kwargs):
230
            sio = StringIO()
231
            builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
232
                                               template=tpl, **kwargs)
233
            builder.generate(sio)
234
            val = sio.getvalue()
235
            return val
236
237
        val = regen('build-date: "{build_date}"\ndate: "{date}"')
238
        self.assertContainsRe(val, 'build-date: "[0-9-+: ]+"')
239
        self.assertContainsRe(val, 'date: "[0-9-+: ]+"')
240
241
        val = regen('revno: {revno}')
242
        self.assertEqual(val, 'revno: 3')
243
244
        val = regen('revision-id: {revision_id}')
245
        self.assertEqual(val, 'revision-id: r3')
246
247
        val = regen('clean: {clean}', check_for_clean=True)
248
        self.assertEqual(val, 'clean: 1')
249
250
        self.build_tree(['branch/c'])
251
        val = regen('clean: {clean}', check_for_clean=True)
252
        self.assertEqual(val, 'clean: 0')
253
        os.remove('branch/c')