/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
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
19
import imp
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
20
import os
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
21
import sys
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
22
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
23
from StringIO 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.
24
from bzrlib.tests import TestCase, TestCaseWithTransport
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
25
from bzrlib.branch import Branch
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
26
from bzrlib.rio import read_stanzas
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
27
28
# TODO: jam 20051228 When part of bzrlib, this should become
29
#       from bzrlib.generate_version_info import foo
30
0.8.21 by John Arbash Meinel
Splitting up the version info code into a lazy factory style.
31
from version_info_formats.format_rio import RioVersionInfoBuilder
32
from version_info_formats.format_python import PythonVersionInfoBuilder
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
33
34
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
class TestVersionInfo(TestCaseWithTransport):
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
36
37
    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.
38
        wt = self.make_branch_and_tree('branch')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
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/a'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
41
        wt.add('a')
42
        wt.commit('a', rev_id='r1')
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/b'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
45
        wt.add('b')
46
        wt.commit('b', rev_id='r2')
47
48
        open('branch/a', 'wb').write('new contents\n')
49
        wt.commit('a2', rev_id='r3')
50
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
51
        return wt
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
52
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
53
    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.
54
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
55
56
        def regen(**kwargs):
57
            sio = 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.
58
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, 
59
                                            **kwargs)
60
            builder.generate(sio)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
61
            val = sio.getvalue()
62
            return val
63
64
        val = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
65
        self.assertContainsRe(val, 'build-date:')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
66
        self.assertContainsRe(val, 'date:')
67
        self.assertContainsRe(val, 'revno: 3')
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
68
        self.assertContainsRe(val, 'revision-id: r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
69
70
        val = regen(check_for_clean=True)
71
        self.assertContainsRe(val, 'clean: True')
72
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
        self.build_tree(['branch/c'])
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
74
        val = regen(check_for_clean=True)
75
        self.assertContainsRe(val, 'clean: False')
76
        os.remove('branch/c')
77
78
        val = regen(include_revision_history=True)
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
79
        self.assertContainsRe(val, 'id: r1')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
80
        self.assertContainsRe(val, 'message: a')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
81
        self.assertContainsRe(val, 'id: r2')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
82
        self.assertContainsRe(val, 'message: b')
0.8.6 by John Arbash Meinel
Updated the blackbox tests.
83
        self.assertContainsRe(val, 'id: r3')
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
84
        self.assertContainsRe(val, 'message: a2')
85
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
86
    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.
87
        wt = self.create_branch()
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
88
89
        def regen(**kwargs):
90
            sio = 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.
91
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, 
92
                                            **kwargs)
93
            builder.generate(sio)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
94
            sio.seek(0)
95
            stanzas = list(read_stanzas(sio))
96
            self.assertEqual(1, len(stanzas))
97
            return stanzas[0]
98
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
99
        def get_one_stanza(stanza, key):
100
            new_stanzas = list(read_stanzas(StringIO(stanza[key])))
101
            self.assertEqual(1, len(new_stanzas))
102
            return new_stanzas[0]
103
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
104
        stanza = regen()
105
        self.failUnless('date' in stanza)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
106
        self.failUnless('build-date' in stanza)
0.8.7 by John Arbash Meinel
Adding tests for parsing the rio text back into rio.
107
        self.assertEqual(['3'], stanza.get_all('revno'))
0.8.16 by John Arbash Meinel
Using revision-id for rio, and revision_id for python
108
        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.
109
110
        stanza = regen(check_for_clean=True)
111
        self.assertEqual(['True'], stanza.get_all('clean'))
112
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
113
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
114
        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.
115
        self.assertEqual(['False'], stanza.get_all('clean'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
116
117
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
118
        self.assertEqual(['a', 'b', 'c'], file_rev_stanza.get_all('path'))
119
        self.assertEqual(['r3', 'r2', 'unversioned'],
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'))
126
        self.assertEqual(['a', 'b', 'a2'], 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')
135
        self.assertEqual(['a', 'b', 'c', 'd'], file_rev_stanza.get_all('path'))
136
        self.assertEqual(['modified', 'renamed to d', 'new', 'renamed from b'],
137
                         file_rev_stanza.get_all('revision'))
138
139
        wt.commit('modified', rev_id='r4')
140
        wt.remove(['c', 'd'])
141
        os.remove('branch/d')
142
        stanza = regen(check_for_clean=True, include_file_revisions=True)
143
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
144
        self.assertEqual(['a', 'c', 'd'], file_rev_stanza.get_all('path'))
145
        self.assertEqual(['r4', 'unversioned', 'removed'],
146
                         file_rev_stanza.get_all('revision'))
147
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
148
    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.
149
        wt = self.create_branch()
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
150
151
        def regen(**kwargs):
152
            outf = open('test_version_information.py', 'wb')
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
153
            builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt, 
154
                                               **kwargs)
155
            builder.generate(outf)
0.8.5 by John Arbash Meinel
Adding some whitebox tests for the output of generate_version_info
156
            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.
157
            module_info = imp.find_module('test_version_information',
158
                                          [os.getcwdu()])
159
            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
160
            # Make sure the module isn't cached
161
            sys.modules.pop('tvi', None)
162
            sys.modules.pop('test_version_information', None)
163
            # Delete the compiled versions, because we are generating
164
            # a new file fast enough that python doesn't detect it
165
            # needs to recompile, and using sleep() just makes the
166
            # test slow
167
            if os.path.exists('test_version_information.pyc'):
168
                os.remove('test_version_information.pyc')
169
            if os.path.exists('test_version_information.pyo'):
170
                os.remove('test_version_information.pyo')
171
            return tvi
172
173
        tvi = regen()
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
174
        self.assertEqual(3, tvi.version_info['revno'])
175
        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
176
        self.failUnless(tvi.version_info.has_key('date'))
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
177
        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
178
179
        tvi = regen(check_for_clean=True)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
180
        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
181
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
182
        self.build_tree(['branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
183
        tvi = regen(check_for_clean=True, include_file_revisions=True)
184
        self.assertEqual(False, tvi.version_info['clean'])
185
        self.assertEqual(['a', 'b', 'c'], sorted(tvi.file_revisions.keys()))
186
        self.assertEqual('r3', tvi.file_revisions['a'])
187
        self.assertEqual('r2', tvi.file_revisions['b'])
188
        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
189
        os.remove('branch/c')
190
191
        tvi = regen(include_revision_history=True)
0.8.15 by John Arbash Meinel
Including the date stamp for all revisions.
192
193
        rev_info = [(rev, message) for rev, message, timestamp, timezone 
194
                                   in tvi.revisions] 
195
        self.assertEqual([('r1', 'a'), ('r2', 'b'), ('r3', 'a2')], rev_info)
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
196
0.8.20 by John Arbash Meinel
Updated version-info to the latest bzr.dev codebase. Changed to using VersionInfoBuilder, and made tests pass.
197
        # a was modified, so it should show up modified again
198
        self.build_tree(['branch/a', 'branch/c'])
0.8.13 by John Arbash Meinel
Including file-revisions fields, updated test suite.
199
        wt.add('c')
200
        wt.rename_one('b', 'd')
201
        tvi = regen(check_for_clean=True, include_file_revisions=True)
202
        self.assertEqual(['a', 'b', 'c', 'd'], sorted(tvi.file_revisions.keys()))
203
        self.assertEqual('modified', tvi.file_revisions['a'])
204
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
205
        self.assertEqual('new', tvi.file_revisions['c'])
206
        self.assertEqual('renamed from b', tvi.file_revisions['d'])
207
208
        wt.commit('modified', rev_id='r4')
209
        wt.remove(['c', 'd'])
210
        os.remove('branch/d')
211
        tvi = regen(check_for_clean=True, include_file_revisions=True)
212
        self.assertEqual(['a', 'c', 'd'], sorted(tvi.file_revisions.keys()))
213
        self.assertEqual('r4', tvi.file_revisions['a'])
214
        self.assertEqual('unversioned', tvi.file_revisions['c'])
215
        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
216
0.8.1 by John Arbash Meinel
Creating a plugin to ease generating version information from a tree.
217