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