/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

Viewing changes to breezy/tests/test_version_info.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for version_info"""
18
18
 
19
 
from cStringIO import StringIO
20
19
import imp
21
20
import os
22
21
import sys
23
22
 
24
 
from bzrlib import (
 
23
from .. import (
25
24
    errors,
26
25
    registry,
27
26
    tests,
28
27
    version_info_formats,
29
28
    )
30
 
from bzrlib.tests import TestCaseWithTransport
31
 
from bzrlib.rio import read_stanzas
 
29
from ..sixish import (
 
30
    BytesIO,
 
31
    )
 
32
from . import TestCaseWithTransport
 
33
from ..rio import read_stanzas
32
34
 
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
 
35
from ..version_info_formats.format_custom import CustomVersionInfoBuilder
 
36
from ..version_info_formats.format_rio import RioVersionInfoBuilder
 
37
from ..version_info_formats.format_python import PythonVersionInfoBuilder
36
38
 
37
39
 
38
40
class VersionInfoTestCase(TestCaseWithTransport):
78
80
    def test_rio_null(self):
79
81
        wt = self.make_branch_and_tree('branch')
80
82
 
81
 
        sio = StringIO()
 
83
        sio = BytesIO()
82
84
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
83
85
        builder.generate(sio)
84
86
        val = sio.getvalue()
88
90
    def test_rio_dotted_revno(self):
89
91
        wt = self.create_tree_with_dotted_revno()
90
92
 
91
 
        sio = StringIO()
 
93
        sio = BytesIO()
92
94
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
93
95
        builder.generate(sio)
94
96
        val = sio.getvalue()
95
97
        self.assertContainsRe(val, 'revno: 1.1.1')
96
98
 
97
99
    def regen_text(self, wt, **kwargs):
98
 
        sio = StringIO()
 
100
        sio = BytesIO()
99
101
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
100
102
        builder.generate(sio)
101
103
        val = sio.getvalue()
133
135
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
134
136
 
135
137
    def regen(self, wt, **kwargs):
136
 
        sio = StringIO()
 
138
        sio = BytesIO()
137
139
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt, **kwargs)
138
140
        builder.generate(sio)
139
141
        sio.seek(0)
152
154
        self.assertEqual(['bloe'], stanza.get_all('bla'))
153
155
 
154
156
    def get_one_stanza(self, stanza, key):
155
 
        new_stanzas = list(read_stanzas(StringIO(stanza[key].encode('utf8'))))
 
157
        new_stanzas = list(read_stanzas(BytesIO(stanza[key].encode('utf8'))))
156
158
        self.assertEqual(1, len(new_stanzas))
157
159
        return new_stanzas[0]
158
160
 
238
240
    def test_python_null(self):
239
241
        wt = self.make_branch_and_tree('branch')
240
242
 
241
 
        sio = StringIO()
 
243
        sio = BytesIO()
242
244
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
243
245
        builder.generate(sio)
244
246
        val = sio.getvalue()
249
251
    def test_python_dotted_revno(self):
250
252
        wt = self.create_tree_with_dotted_revno()
251
253
 
252
 
        sio = StringIO()
 
254
        sio = BytesIO()
253
255
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
254
256
        builder.generate(sio)
255
257
        val = sio.getvalue()
265
267
        finally:
266
268
            outf.close()
267
269
        module_info = imp.find_module('test_version_information',
268
 
                                      [os.getcwdu()])
 
270
                                      [self.test_dir])
269
271
        tvi = imp.load_module('tvi', *module_info)
270
272
        # Make sure the module isn't cached
271
273
        sys.modules.pop('tvi', None)
286
288
        tvi = self.regen(wt)
287
289
        self.assertEqual('3', tvi.version_info['revno'])
288
290
        self.assertEqual('r3', tvi.version_info['revision_id'])
289
 
        self.assertTrue(tvi.version_info.has_key('date'))
 
291
        self.assertTrue('date' in tvi.version_info)
290
292
        self.assertEqual(None, tvi.version_info['clean'])
291
293
 
292
294
        tvi = self.regen(wt, check_for_clean=True)
334
336
class CustomVersionInfoTests(VersionInfoTestCase):
335
337
 
336
338
    def test_custom_null(self):
337
 
        sio = StringIO()
 
339
        sio = BytesIO()
338
340
        wt = self.make_branch_and_tree('branch')
339
341
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
340
342
            template='revno: {revno}')
348
350
            builder.generate, sio)
349
351
 
350
352
    def test_custom_dotted_revno(self):
351
 
        sio = StringIO()
 
353
        sio = BytesIO()
352
354
        wt = self.create_tree_with_dotted_revno()
353
355
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
354
356
            template='{revno} revid: {revision_id}')
356
358
        self.assertEqual("1.1.1 revid: o2", sio.getvalue())
357
359
 
358
360
    def regen(self, wt, tpl, **kwargs):
359
 
        sio = StringIO()
 
361
        sio = BytesIO()
360
362
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
361
363
                                           template=tpl, **kwargs)
362
364
        builder.generate(sio)
395
397
 
396
398
    def test_custom_without_template(self):
397
399
        builder = CustomVersionInfoBuilder(None)
398
 
        sio = StringIO()
 
400
        sio = BytesIO()
399
401
        self.assertRaises(errors.NoTemplate, builder.generate, sio)
400
402
 
401
403