~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-04 14:10:13 UTC
  • mto: This revision was merged to the branch mainline in revision 3805.
  • Revision ID: john@arbash-meinel.com-20081004141013-yskxjlwtuy2k18ue
Playing around with expanding requests for btree index nodes into neighboring nodes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for version_info"""
18
18
 
23
23
 
24
24
from bzrlib import (
25
25
    errors,
26
 
    registry,
 
26
    symbol_versioning,
27
27
    tests,
28
28
    version_info_formats,
29
29
    )
53
53
 
54
54
        return wt
55
55
 
56
 
    def create_tree_with_dotted_revno(self):
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
 
 
75
 
    def test_rio_null(self):
76
 
        wt = self.make_branch_and_tree('branch')
77
 
 
78
 
        sio = StringIO()
79
 
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
80
 
        builder.generate(sio)
81
 
        val = sio.getvalue()
82
 
        self.assertContainsRe(val, 'build-date:')
83
 
        self.assertContainsRe(val, 'revno: 0')
84
 
 
85
 
    def test_rio_dotted_revno(self):
86
 
        wt = self.create_tree_with_dotted_revno()
87
 
 
88
 
        sio = StringIO()
89
 
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
90
 
        builder.generate(sio)
91
 
        val = sio.getvalue()
92
 
        self.assertContainsRe(val, 'revno: 1.1.1')
93
 
 
94
56
    def test_rio_version_text(self):
95
57
        wt = self.create_branch()
96
58
 
124
86
        self.assertContainsRe(val, 'id: r3')
125
87
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
126
88
 
127
 
    def test_rio_version_hook(self):
128
 
        def update_stanza(rev, stanza):
129
 
            stanza.add('bla', 'bloe')
130
 
        RioVersionInfoBuilder.hooks.install_named_hook(
131
 
            'revision', update_stanza, None)
132
 
        wt = self.create_branch()
133
 
 
134
 
        def regen(**kwargs):
135
 
            sio = StringIO()
136
 
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
137
 
                                            **kwargs)
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
 
 
144
 
        stanza = regen()
145
 
        self.assertEqual(['bloe'], stanza.get_all('bla'))
146
 
 
147
89
    def test_rio_version(self):
148
90
        wt = self.create_branch()
149
91
 
164
106
            return new_stanzas[0]
165
107
 
166
108
        stanza = regen()
167
 
        self.assertTrue('date' in stanza)
168
 
        self.assertTrue('build-date' in stanza)
 
109
        self.failUnless('date' in stanza)
 
110
        self.failUnless('build-date' in stanza)
169
111
        self.assertEqual(['3'], stanza.get_all('revno'))
170
112
        self.assertEqual(['r3'], stanza.get_all('revision-id'))
171
113
 
176
118
        stanza = regen(check_for_clean=True, include_file_revisions=True)
177
119
        self.assertEqual(['False'], stanza.get_all('clean'))
178
120
 
179
 
        # This assumes it's being run against a tree that does not update the
180
 
        # root revision on every commit.
 
121
        # XXX: This assumes it's being run against a repository that updates
 
122
        # the root revision on every commit.  Newer ones that use
 
123
        # RootCommitBuilder won't update it on each commit.
181
124
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
182
125
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
183
 
        self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
 
126
        self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
184
127
            file_rev_stanza.get_all('revision'))
185
128
        os.remove('branch/c')
186
129
 
196
139
        wt.rename_one('b', 'd')
197
140
        stanza = regen(check_for_clean=True, include_file_revisions=True)
198
141
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
199
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
 
142
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
200
143
                          file_rev_stanza.get_all('path'))
201
 
        self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
 
144
        self.assertEqual(['r3', 'modified', 'renamed to d', 'new', 
202
145
                          'renamed from b'],
203
146
                         file_rev_stanza.get_all('revision'))
204
147
 
208
151
        stanza = regen(check_for_clean=True, include_file_revisions=True)
209
152
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
210
153
        self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
211
 
        self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
 
154
        self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
212
155
                         file_rev_stanza.get_all('revision'))
213
156
 
214
 
    def test_python_null(self):
215
 
        wt = self.make_branch_and_tree('branch')
216
 
 
217
 
        sio = StringIO()
218
 
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
219
 
        builder.generate(sio)
220
 
        val = sio.getvalue()
221
 
        self.assertContainsRe(val, "'revision_id': None")
222
 
        self.assertContainsRe(val, "'revno': '0'")
223
 
        self.assertNotContainsString(val, '\n\n\n\n')
224
 
 
225
 
    def test_python_dotted_revno(self):
226
 
        wt = self.create_tree_with_dotted_revno()
227
 
 
228
 
        sio = StringIO()
229
 
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
230
 
        builder.generate(sio)
231
 
        val = sio.getvalue()
232
 
        self.assertContainsRe(val, "'revno': '1.1.1'")
233
 
 
234
157
    def test_python_version(self):
235
158
        wt = self.create_branch()
236
159
 
260
183
            return tvi
261
184
 
262
185
        tvi = regen()
263
 
        self.assertEqual('3', tvi.version_info['revno'])
 
186
        self.assertEqual(3, tvi.version_info['revno'])
264
187
        self.assertEqual('r3', tvi.version_info['revision_id'])
265
 
        self.assertTrue(tvi.version_info.has_key('date'))
 
188
        self.failUnless(tvi.version_info.has_key('date'))
266
189
        self.assertEqual(None, tvi.version_info['clean'])
267
190
 
268
191
        tvi = regen(check_for_clean=True)
271
194
        self.build_tree(['branch/c'])
272
195
        tvi = regen(check_for_clean=True, include_file_revisions=True)
273
196
        self.assertEqual(False, tvi.version_info['clean'])
274
 
        self.assertEqual(['', 'a', 'b', 'c'],
 
197
        self.assertEqual(['', 'a', 'b', 'c'], 
275
198
                         sorted(tvi.file_revisions.keys()))
276
199
        self.assertEqual('r3', tvi.file_revisions['a'])
277
200
        self.assertEqual('r2', tvi.file_revisions['b'])
289
212
        wt.add('c')
290
213
        wt.rename_one('b', 'd')
291
214
        tvi = regen(check_for_clean=True, include_file_revisions=True)
292
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
 
215
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
293
216
                          sorted(tvi.file_revisions.keys()))
294
217
        self.assertEqual('modified', tvi.file_revisions['a'])
295
218
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
300
223
        wt.remove(['c', 'd'])
301
224
        os.remove('branch/d')
302
225
        tvi = regen(check_for_clean=True, include_file_revisions=True)
303
 
        self.assertEqual(['', 'a', 'c', 'd'],
 
226
        self.assertEqual(['', 'a', 'c', 'd'], 
304
227
                          sorted(tvi.file_revisions.keys()))
305
228
        self.assertEqual('r4', tvi.file_revisions['a'])
306
229
        self.assertEqual('unversioned', tvi.file_revisions['c'])
307
230
        self.assertEqual('removed', tvi.file_revisions['d'])
308
231
 
309
 
    def test_custom_null(self):
310
 
        sio = StringIO()
311
 
        wt = self.make_branch_and_tree('branch')
312
 
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
313
 
            template='revno: {revno}')
314
 
        builder.generate(sio)
315
 
        self.assertEquals("revno: 0", sio.getvalue())
316
 
 
317
 
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
318
 
            template='{revno} revid: {revision_id}')
319
 
        # revision_id is not available yet
320
 
        self.assertRaises(errors.MissingTemplateVariable, 
321
 
            builder.generate, sio)
322
 
 
323
 
    def test_custom_dotted_revno(self):
324
 
        sio = StringIO()
325
 
        wt = self.create_tree_with_dotted_revno()
326
 
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
327
 
            template='{revno} revid: {revision_id}')
328
 
        builder.generate(sio)
329
 
        self.assertEquals("1.1.1 revid: o2", sio.getvalue())
330
 
 
331
232
    def test_custom_version_text(self):
332
233
        wt = self.create_branch()
333
234
 
371
272
 
372
273
    def setUp(self):
373
274
        super(TestVersionInfoFormatRegistry, self).setUp()
374
 
        self.overrideAttr(version_info_formats,
375
 
                          'format_registry', registry.Registry())
 
275
        registry = version_info_formats.format_registry
 
276
        self._default_key = registry._default_key
 
277
        self._dict = registry._dict.copy()
 
278
        self._help_dict = registry._help_dict.copy()
 
279
        self._info_dict = registry._info_dict.copy()
 
280
        self.addCleanup(self._cleanup)
 
281
 
 
282
    def _cleanup(self):
 
283
        # Restore the registry to pristine state after the test runs
 
284
        registry = version_info_formats.format_registry
 
285
        registry._default_key = self._default_key
 
286
        registry._dict = self._dict
 
287
        registry._help_dict = self._help_dict
 
288
        registry._info_dict = self._info_dict
376
289
 
377
290
    def test_register_remove(self):
378
291
        registry = version_info_formats.format_registry