~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-29 12:14:09 UTC
  • mto: This revision was merged to the branch mainline in revision 4489.
  • Revision ID: v.ladeuil+lp@free.fr-20090629121409-0ime74unkuaodwyj
(vila) Cleanup imports in some test files

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import sys
24
24
import time
25
25
 
26
 
import bzrlib
27
 
import bzrlib.errors as errors
 
26
from bzrlib import (
 
27
    errors,
 
28
    tests,
 
29
    ui as _mod_ui,
 
30
    )
28
31
from bzrlib.symbol_versioning import (
29
32
    deprecated_in,
30
33
    )
31
 
from bzrlib.tests import (
32
 
    TestCase,
33
 
    TestUIFactory,
34
 
    StringIOWrapper,
35
 
    )
36
34
from bzrlib.tests.test_progress import _TTYStringIO
37
 
from bzrlib.ui import (
38
 
    CLIUIFactory,
39
 
    SilentUIFactory,
40
 
    )
41
35
from bzrlib.ui.text import (
42
36
    NullProgressView,
43
37
    TextProgressView,
45
39
    )
46
40
 
47
41
 
48
 
class UITests(TestCase):
 
42
class UITests(tests.TestCase):
49
43
 
50
44
    def test_silent_factory(self):
51
 
        ui = SilentUIFactory()
 
45
        ui = _mod_ui.SilentUIFactory()
52
46
        stdout = StringIO()
53
47
        self.assertEqual(None,
54
48
                         self.apply_redirected(None, stdout, stdout,
62
56
        self.assertEqual('', stdout.getvalue())
63
57
 
64
58
    def test_text_factory_ascii_password(self):
65
 
        ui = TestUIFactory(stdin='secret\n', stdout=StringIOWrapper(),
66
 
                           stderr=StringIOWrapper())
 
59
        ui = tests.TestUIFactory(stdin='secret\n',
 
60
                                 stdout=tests.StringIOWrapper(),
 
61
                                 stderr=tests.StringIOWrapper())
67
62
        pb = ui.nested_progress_bar()
68
63
        try:
69
64
            self.assertEqual('secret',
84
79
        We can't predict what encoding users will have for stdin, so we force
85
80
        it to utf8 to test that we transport the password correctly.
86
81
        """
87
 
        ui = TestUIFactory(stdin=u'baz\u1234'.encode('utf8'),
88
 
                           stdout=StringIOWrapper(),
89
 
                           stderr=StringIOWrapper())
 
82
        ui = tests.TestUIFactory(stdin=u'baz\u1234'.encode('utf8'),
 
83
                                 stdout=tests.StringIOWrapper(),
 
84
                                 stderr=tests.StringIOWrapper())
90
85
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
91
86
        pb = ui.nested_progress_bar()
92
87
        try:
194
189
        self.assertEqual('', factory.stdin.readline())
195
190
 
196
191
    def test_silent_ui_getbool(self):
197
 
        factory = SilentUIFactory()
 
192
        factory = _mod_ui.SilentUIFactory()
198
193
        self.assert_get_bool_acceptance_of_user_input(factory)
199
194
 
200
195
    def test_silent_factory_prompts_silently(self):
201
 
        factory = SilentUIFactory()
 
196
        factory = _mod_ui.SilentUIFactory()
202
197
        stdout = StringIO()
203
198
        factory.stdin = StringIO("y\n")
204
199
        self.assertEqual(True,
222
217
    def test_text_factory_prompts_and_clears(self):
223
218
        # a get_boolean call should clear the pb before prompting
224
219
        out = _TTYStringIO()
225
 
        factory = TextUIFactory(stdin=StringIO("yada\ny\n"), stdout=out, stderr=out)
 
220
        factory = TextUIFactory(stdin=StringIO("yada\ny\n"),
 
221
                                stdout=out, stderr=out)
226
222
        pb = factory.nested_progress_bar()
227
223
        pb.show_bar = False
228
224
        pb.show_spinner = False
253
249
            pb.finished()
254
250
 
255
251
    def test_silent_ui_getusername(self):
256
 
        factory = SilentUIFactory()
 
252
        factory = _mod_ui.SilentUIFactory()
257
253
        factory.stdin = StringIO("someuser\n\n")
258
254
        factory.stdout = StringIO()
259
255
        factory.stderr = StringIO()
279
275
        self.assertEqual('', factory.stdin.readline())
280
276
 
281
277
    def test_text_ui_getusername_utf8(self):
282
 
        ui = TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
283
 
                           stdout=StringIOWrapper(), stderr=StringIOWrapper())
 
278
        ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
 
279
                                 stdout=tests.StringIOWrapper(),
 
280
                                 stderr=tests.StringIOWrapper())
284
281
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
285
282
        pb = ui.nested_progress_bar()
286
283
        try:
295
292
            pb.finished()
296
293
 
297
294
 
298
 
class TestTextProgressView(TestCase):
 
295
class TestTextProgressView(tests.TestCase):
299
296
    """Tests for text display of progress bars.
300
297
    """
301
298
    # XXX: These might be a bit easier to write if the rendering and