/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2012, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
16
16
 
17
17
"""Tests for version_info"""
18
18
 
 
19
from cStringIO import StringIO
 
20
import imp
19
21
import os
20
22
import sys
21
23
 
22
 
from .. import (
 
24
from bzrlib import (
 
25
    errors,
23
26
    registry,
24
27
    tests,
25
28
    version_info_formats,
26
29
    )
27
 
from ..sixish import (
28
 
    BytesIO,
29
 
    )
30
 
from . import TestCaseWithTransport
31
 
from ..rio import read_stanzas
 
30
from bzrlib.tests import TestCaseWithTransport
 
31
from bzrlib.rio import read_stanzas
32
32
 
33
 
from ..version_info_formats.format_custom import (
34
 
    CustomVersionInfoBuilder,
35
 
    MissingTemplateVariable,
36
 
    NoTemplate,
37
 
    )
38
 
from ..version_info_formats.format_rio import RioVersionInfoBuilder
39
 
from ..version_info_formats.format_python import PythonVersionInfoBuilder
 
33
from bzrlib.version_info_formats.format_custom import CustomVersionInfoBuilder
 
34
from bzrlib.version_info_formats.format_rio import RioVersionInfoBuilder
 
35
from bzrlib.version_info_formats.format_python import PythonVersionInfoBuilder
40
36
 
41
37
 
42
38
class VersionInfoTestCase(TestCaseWithTransport):
46
42
 
47
43
        self.build_tree(['branch/a'])
48
44
        wt.add('a')
49
 
        wt.commit('a', rev_id=b'r1')
 
45
        wt.commit('a', rev_id='r1')
50
46
 
51
47
        self.build_tree(['branch/b'])
52
48
        wt.add('b')
53
 
        wt.commit('b', rev_id=b'r2')
 
49
        wt.commit('b', rev_id='r2')
54
50
 
55
 
        self.build_tree_contents([('branch/a', b'new contents\n')])
56
 
        wt.commit(u'\xe52', rev_id=b'r3')
 
51
        self.build_tree_contents([('branch/a', 'new contents\n')])
 
52
        wt.commit(u'\xe52', rev_id='r3')
57
53
 
58
54
        return wt
59
55
 
61
57
        wt = self.make_branch_and_tree('branch')
62
58
        self.build_tree(['branch/a'])
63
59
        wt.add('a')
64
 
        wt.commit('a', rev_id=b'r1')
 
60
        wt.commit('a', rev_id='r1')
65
61
 
66
 
        other = wt.controldir.sprout('other').open_workingtree()
 
62
        other = wt.bzrdir.sprout('other').open_workingtree()
67
63
        self.build_tree(['other/b.a'])
68
64
        other.add(['b.a'])
69
 
        other.commit('b.a', rev_id=b'o2')
 
65
        other.commit('b.a', rev_id='o2')
70
66
 
71
67
        os.chdir('branch')
72
68
        self.run_bzr('merge ../other')
73
 
        wt.commit('merge', rev_id=b'merge')
 
69
        wt.commit('merge', rev_id='merge')
74
70
 
75
71
        wt.update(revision='o2')
76
72
 
82
78
    def test_rio_null(self):
83
79
        wt = self.make_branch_and_tree('branch')
84
80
 
85
 
        sio = BytesIO()
 
81
        sio = StringIO()
86
82
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
87
83
        builder.generate(sio)
88
84
        val = sio.getvalue()
92
88
    def test_rio_dotted_revno(self):
93
89
        wt = self.create_tree_with_dotted_revno()
94
90
 
95
 
        sio = BytesIO()
 
91
        sio = StringIO()
96
92
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
97
93
        builder.generate(sio)
98
94
        val = sio.getvalue()
99
95
        self.assertContainsRe(val, 'revno: 1.1.1')
100
96
 
101
97
    def regen_text(self, wt, **kwargs):
102
 
        sio = BytesIO()
 
98
        sio = StringIO()
103
99
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
104
100
        builder.generate(sio)
105
101
        val = sio.getvalue()
137
133
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
138
134
 
139
135
    def regen(self, wt, **kwargs):
140
 
        sio = BytesIO()
 
136
        sio = StringIO()
141
137
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
142
138
        builder.generate(sio)
143
139
        sio.seek(0)
156
152
        self.assertEqual(['bloe'], stanza.get_all('bla'))
157
153
 
158
154
    def get_one_stanza(self, stanza, key):
159
 
        new_stanzas = list(read_stanzas(BytesIO(stanza[key].encode('utf8'))))
 
155
        new_stanzas = list(read_stanzas(StringIO(stanza[key].encode('utf8'))))
160
156
        self.assertEqual(1, len(new_stanzas))
161
157
        return new_stanzas[0]
162
158
 
213
209
        wt.add('c')
214
210
        wt.rename_one('b', 'd')
215
211
 
216
 
        wt.commit('modified', rev_id=b'r4')
 
212
        wt.commit('modified', rev_id='r4')
217
213
 
218
214
        wt.remove(['c', 'd'])
219
215
        os.remove('branch/d')
242
238
    def test_python_null(self):
243
239
        wt = self.make_branch_and_tree('branch')
244
240
 
245
 
        sio = BytesIO()
 
241
        sio = StringIO()
246
242
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
247
243
        builder.generate(sio)
248
244
        val = sio.getvalue()
253
249
    def test_python_dotted_revno(self):
254
250
        wt = self.create_tree_with_dotted_revno()
255
251
 
256
 
        sio = BytesIO()
 
252
        sio = StringIO()
257
253
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
258
254
        builder.generate(sio)
259
255
        val = sio.getvalue()
261
257
 
262
258
    def regen(self, wt, **kwargs):
263
259
        """Create a test module, import and return it"""
264
 
        with open('test_version_information.py', 'wb') as outf:
 
260
        outf = open('test_version_information.py', 'wb')
 
261
        try:
265
262
            builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt,
266
263
                                               **kwargs)
267
264
            builder.generate(outf)
268
 
        import imp
 
265
        finally:
 
266
            outf.close()
269
267
        module_info = imp.find_module('test_version_information',
270
 
                                      [self.test_dir])
 
268
                                      [os.getcwdu()])
271
269
        tvi = imp.load_module('tvi', *module_info)
272
270
        # Make sure the module isn't cached
273
271
        sys.modules.pop('tvi', None)
288
286
        tvi = self.regen(wt)
289
287
        self.assertEqual('3', tvi.version_info['revno'])
290
288
        self.assertEqual('r3', tvi.version_info['revision_id'])
291
 
        self.assertTrue('date' in tvi.version_info)
 
289
        self.assertTrue(tvi.version_info.has_key('date'))
292
290
        self.assertEqual(None, tvi.version_info['clean'])
293
291
 
294
292
        tvi = self.regen(wt, check_for_clean=True)
322
320
        self.assertEqual('new', tvi.file_revisions['c'])
323
321
        self.assertEqual('renamed from b', tvi.file_revisions['d'])
324
322
 
325
 
        wt.commit('modified', rev_id=b'r4')
 
323
        wt.commit('modified', rev_id='r4')
326
324
        wt.remove(['c', 'd'])
327
325
        os.remove('branch/d')
328
326
        tvi = self.regen(wt, check_for_clean=True, include_file_revisions=True)
336
334
class CustomVersionInfoTests(VersionInfoTestCase):
337
335
 
338
336
    def test_custom_null(self):
339
 
        sio = BytesIO()
 
337
        sio = StringIO()
340
338
        wt = self.make_branch_and_tree('branch')
341
339
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
342
340
            template='revno: {revno}')
343
341
        builder.generate(sio)
344
 
        self.assertEqual("revno: 0", sio.getvalue())
 
342
        self.assertEquals("revno: 0", sio.getvalue())
345
343
 
346
344
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
347
345
            template='{revno} revid: {revision_id}')
348
346
        # revision_id is not available yet
349
 
        self.assertRaises(MissingTemplateVariable, builder.generate, sio)
 
347
        self.assertRaises(errors.MissingTemplateVariable, 
 
348
            builder.generate, sio)
350
349
 
351
350
    def test_custom_dotted_revno(self):
352
 
        sio = BytesIO()
 
351
        sio = StringIO()
353
352
        wt = self.create_tree_with_dotted_revno()
354
353
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
355
354
            template='{revno} revid: {revision_id}')
356
355
        builder.generate(sio)
357
 
        self.assertEqual("1.1.1 revid: o2", sio.getvalue())
 
356
        self.assertEquals("1.1.1 revid: o2", sio.getvalue())
358
357
 
359
358
    def regen(self, wt, tpl, **kwargs):
360
 
        sio = BytesIO()
 
359
        sio = StringIO()
361
360
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
362
361
                                           template=tpl, **kwargs)
363
362
        builder.generate(sio)
396
395
 
397
396
    def test_custom_without_template(self):
398
397
        builder = CustomVersionInfoBuilder(None)
399
 
        sio = BytesIO()
400
 
        self.assertRaises(NoTemplate, builder.generate, sio)
 
398
        sio = StringIO()
 
399
        self.assertRaises(errors.NoTemplate, builder.generate, sio)
401
400
 
402
401
 
403
402
class TestBuilder(version_info_formats.VersionInfoBuilder):