~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Martin Pool
  • Date: 2010-09-14 06:46:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5426.
  • Revision ID: mbp@sourcefrog.net-20100914064618-1b05bktzv3513mx0
Add ConfirmationUserInterfacePolicy that lets specific confirmations be configured off.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""
19
19
 
20
20
import os
21
 
import re
22
21
import time
23
22
 
24
23
from StringIO import StringIO
25
24
 
 
25
from testtools.matchers import *
 
26
 
26
27
from bzrlib import (
27
28
    config,
28
29
    errors,
50
51
        ui = tests.TestUIFactory(stdin=None,
51
52
            stdout=tests.StringIOWrapper(),
52
53
            stderr=tests.StringIOWrapper())
53
 
        os = ui.make_output_stream()
54
 
        self.assertEquals(os.encoding, enc)
 
54
        output = ui.make_output_stream()
 
55
        self.assertEquals(output.encoding, enc)
55
56
 
56
57
 
57
58
class TestTextUIFactory(tests.TestCase):
442
443
        self.assertIsNone('0', av)
443
444
        self.assertIsNone('on', av)
444
445
        self.assertIsNone('off', av)
 
446
 
 
447
 
 
448
class TestConfirmationUserInterfacePolicy(tests.TestCase):
 
449
 
 
450
    def test_confirm_action_default(self):
 
451
        base_ui = _mod_ui.NoninteractiveUIFactory()
 
452
        for answer in [True, False]:
 
453
            self.assertEquals(
 
454
                _mod_ui.ConfirmationUserInterfacePolicy(base_ui, answer, {})
 
455
                .confirm_action("Do something?",
 
456
                    "bzrlib.tests.do_something", {}),
 
457
                answer)
 
458
 
 
459
    def test_confirm_action_specific(self):
 
460
        base_ui = _mod_ui.NoninteractiveUIFactory()
 
461
        for default_answer in [True, False]:
 
462
            for specific_answer in [True, False]:
 
463
                for conf_id in ['given_id', 'other_id']:
 
464
                    wrapper = _mod_ui.ConfirmationUserInterfacePolicy(
 
465
                        base_ui, default_answer, dict(given_id=specific_answer))
 
466
                    result = wrapper.confirm_action("Do something?", conf_id, {})
 
467
                    if conf_id == 'given_id':
 
468
                        self.assertEquals(result, specific_answer)
 
469
                    else:
 
470
                        self.assertEquals(result, default_answer)
 
471
 
 
472
    def test_repr(self):
 
473
        base_ui = _mod_ui.NoninteractiveUIFactory()
 
474
        wrapper = _mod_ui.ConfirmationUserInterfacePolicy(
 
475
            base_ui, True, dict(a=2))
 
476
        self.assertThat(repr(wrapper),
 
477
            Equals("ConfirmationUserInterfacePolicy("
 
478
                "NoninteractiveUIFactory(), True, {'a': 2})"))