~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Robert Collins
  • Date: 2010-02-27 12:27:33 UTC
  • mto: This revision was merged to the branch mainline in revision 5061.
  • Revision ID: robertc@robertcollins.net-20100227122733-2o3me3fkk3pk36ns
``bzrlib.branchbuilder.BranchBuilder.build_snapshot`` now accepts a
``message_callback`` in the same way that commit does. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import re
22
22
import time
23
23
 
24
 
from StringIO import StringIO
25
 
 
26
24
from bzrlib import (
27
 
    config,
28
25
    errors,
29
 
    remote,
30
 
    repository,
31
26
    tests,
32
27
    ui as _mod_ui,
33
28
    )
34
29
from bzrlib.symbol_versioning import (
35
30
    deprecated_in,
36
31
    )
37
 
from bzrlib.tests import (
38
 
    fixtures,
39
 
    test_progress,
40
 
    )
 
32
from bzrlib.tests import test_progress
41
33
from bzrlib.ui import text as _mod_ui_text
42
34
 
43
35
 
44
 
class TestUIConfiguration(tests.TestCaseWithTransport):
45
 
 
46
 
    def test_output_encoding_configuration(self):
47
 
        enc = fixtures.generate_unicode_encodings().next()
48
 
        config.GlobalConfig().set_user_option('output_encoding',
49
 
            enc)
50
 
        ui = tests.TestUIFactory(stdin=None,
51
 
            stdout=tests.StringIOWrapper(),
52
 
            stderr=tests.StringIOWrapper())
53
 
        os = ui.make_output_stream()
54
 
        self.assertEquals(os.encoding, enc)
55
 
 
56
 
 
57
36
class TestTextUIFactory(tests.TestCase):
58
37
 
59
38
    def test_text_factory_ascii_password(self):
266
245
        self.assertIsInstance(ui_factory._progress_view,
267
246
            _mod_ui_text.NullProgressView)
268
247
 
269
 
    def test_text_ui_show_user_warning(self):
270
 
        from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
271
 
        from bzrlib.repofmt.pack_repo import RepositoryFormatKnitPack5
272
 
        err = StringIO()
273
 
        out = StringIO()
274
 
        ui = tests.TextUIFactory(stdin=None, stdout=out, stderr=err)
275
 
        remote_fmt = remote.RemoteRepositoryFormat()
276
 
        remote_fmt._network_name = RepositoryFormatKnitPack5().network_name()
277
 
        ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
278
 
            to_format=remote_fmt)
279
 
        self.assertEquals('', out.getvalue())
280
 
        self.assertEquals("Doing on-the-fly conversion from RepositoryFormat2a() to "
281
 
            "RemoteRepositoryFormat(_network_name='Bazaar RepositoryFormatKnitPack5 "
282
 
            "(bzr 1.6)\\n').\nThis may take some time. Upgrade the repositories to "
283
 
            "the same format for better performance.\n",
284
 
            err.getvalue())
285
 
        # and now with it suppressed please
286
 
        err = StringIO()
287
 
        out = StringIO()
288
 
        ui = tests.TextUIFactory(stdin=None, stdout=out, stderr=err)
289
 
        ui.suppressed_warnings.add('cross_format_fetch')
290
 
        ui.show_user_warning('cross_format_fetch', from_format=RepositoryFormat2a(),
291
 
            to_format=remote_fmt)
292
 
        self.assertEquals('', out.getvalue())
293
 
        self.assertEquals('', err.getvalue())
294
 
 
295
248
 
296
249
class TestTextUIOutputStream(tests.TestCase):
297
250
    """Tests for output stream that synchronizes with progress bar."""
402
355
 
403
356
    def test_test_ui_factory_progress(self):
404
357
        # there's no output; we just want to make sure this doesn't crash -
405
 
        # see https://bugs.launchpad.net/bzr/+bug/408201
 
358
        # see https://bugs.edge.launchpad.net/bzr/+bug/408201
406
359
        ui = tests.TestUIFactory()
407
360
        pb = ui.nested_progress_bar()
408
361
        pb.update('hello')