~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Jonathan Lange
  • Date: 2009-06-26 08:46:52 UTC
  • mto: (4484.1.1 bring-1.16.1-back)
  • mto: This revision was merged to the branch mainline in revision 4485.
  • Revision ID: jml@canonical.com-20090626084652-x7wn8yimd3fj0j0y
Tweak NEWS slightly based on mbp's feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import sys
24
24
import time
25
25
 
26
 
from bzrlib import (
27
 
    errors,
28
 
    tests,
29
 
    ui as _mod_ui,
30
 
    )
 
26
import bzrlib
 
27
import bzrlib.errors as errors
31
28
from bzrlib.symbol_versioning import (
32
29
    deprecated_in,
33
30
    )
 
31
from bzrlib.tests import (
 
32
    TestCase,
 
33
    TestUIFactory,
 
34
    StringIOWrapper,
 
35
    )
34
36
from bzrlib.tests.test_progress import _TTYStringIO
 
37
from bzrlib.ui import (
 
38
    CLIUIFactory,
 
39
    SilentUIFactory,
 
40
    )
35
41
from bzrlib.ui.text import (
36
 
    NullProgressView,
37
42
    TextProgressView,
38
43
    TextUIFactory,
39
44
    )
40
45
 
41
46
 
42
 
class UITests(tests.TestCase):
 
47
class UITests(TestCase):
43
48
 
44
49
    def test_silent_factory(self):
45
 
        ui = _mod_ui.SilentUIFactory()
 
50
        ui = SilentUIFactory()
46
51
        stdout = StringIO()
47
52
        self.assertEqual(None,
48
53
                         self.apply_redirected(None, stdout, stdout,
56
61
        self.assertEqual('', stdout.getvalue())
57
62
 
58
63
    def test_text_factory_ascii_password(self):
59
 
        ui = tests.TestUIFactory(stdin='secret\n',
60
 
                                 stdout=tests.StringIOWrapper(),
61
 
                                 stderr=tests.StringIOWrapper())
 
64
        ui = TestUIFactory(stdin='secret\n', stdout=StringIOWrapper(),
 
65
                           stderr=StringIOWrapper())
62
66
        pb = ui.nested_progress_bar()
63
67
        try:
64
68
            self.assertEqual('secret',
79
83
        We can't predict what encoding users will have for stdin, so we force
80
84
        it to utf8 to test that we transport the password correctly.
81
85
        """
82
 
        ui = tests.TestUIFactory(stdin=u'baz\u1234'.encode('utf8'),
83
 
                                 stdout=tests.StringIOWrapper(),
84
 
                                 stderr=tests.StringIOWrapper())
 
86
        ui = TestUIFactory(stdin=u'baz\u1234'.encode('utf8'),
 
87
                           stdout=StringIOWrapper(),
 
88
                           stderr=StringIOWrapper())
85
89
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
86
90
        pb = ui.nested_progress_bar()
87
91
        try:
99
103
        finally:
100
104
            pb.finished()
101
105
 
102
 
    def test_progress_construction(self):
103
 
        """TextUIFactory constructs the right progress view.
104
 
        """
105
 
        os.environ['BZR_PROGRESS_BAR'] = 'none'
106
 
        self.assertIsInstance(TextUIFactory()._progress_view,
107
 
            NullProgressView)
108
 
 
109
 
        os.environ['BZR_PROGRESS_BAR'] = 'text'
110
 
        self.assertIsInstance(TextUIFactory()._progress_view,
111
 
            TextProgressView)
112
 
 
113
 
        os.environ['BZR_PROGRESS_BAR'] = 'text'
114
 
        self.assertIsInstance(TextUIFactory()._progress_view,
115
 
            TextProgressView)
116
 
 
117
 
        del os.environ['BZR_PROGRESS_BAR']
118
 
        self.assertIsInstance(TextUIFactory()._progress_view,
119
 
            TextProgressView)
120
 
 
121
106
    def test_progress_note(self):
122
107
        stderr = StringIO()
123
108
        stdout = StringIO()
189
174
        self.assertEqual('', factory.stdin.readline())
190
175
 
191
176
    def test_silent_ui_getbool(self):
192
 
        factory = _mod_ui.SilentUIFactory()
 
177
        factory = SilentUIFactory()
193
178
        self.assert_get_bool_acceptance_of_user_input(factory)
194
179
 
195
180
    def test_silent_factory_prompts_silently(self):
196
 
        factory = _mod_ui.SilentUIFactory()
 
181
        factory = SilentUIFactory()
197
182
        stdout = StringIO()
198
183
        factory.stdin = StringIO("y\n")
199
184
        self.assertEqual(True,
217
202
    def test_text_factory_prompts_and_clears(self):
218
203
        # a get_boolean call should clear the pb before prompting
219
204
        out = _TTYStringIO()
220
 
        factory = TextUIFactory(stdin=StringIO("yada\ny\n"),
221
 
                                stdout=out, stderr=out)
 
205
        factory = TextUIFactory(stdin=StringIO("yada\ny\n"), stdout=out, stderr=out)
222
206
        pb = factory.nested_progress_bar()
223
207
        pb.show_bar = False
224
208
        pb.show_spinner = False
249
233
            pb.finished()
250
234
 
251
235
    def test_silent_ui_getusername(self):
252
 
        factory = _mod_ui.SilentUIFactory()
 
236
        factory = SilentUIFactory()
253
237
        factory.stdin = StringIO("someuser\n\n")
254
238
        factory.stdout = StringIO()
255
239
        factory.stderr = StringIO()
275
259
        self.assertEqual('', factory.stdin.readline())
276
260
 
277
261
    def test_text_ui_getusername_utf8(self):
278
 
        ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
279
 
                                 stdout=tests.StringIOWrapper(),
280
 
                                 stderr=tests.StringIOWrapper())
 
262
        ui = TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
 
263
                           stdout=StringIOWrapper(), stderr=StringIOWrapper())
281
264
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
282
265
        pb = ui.nested_progress_bar()
283
266
        try:
292
275
            pb.finished()
293
276
 
294
277
 
295
 
class TestTextProgressView(tests.TestCase):
 
278
class TestTextProgressView(TestCase):
296
279
    """Tests for text display of progress bars.
297
280
    """
298
281
    # XXX: These might be a bit easier to write if the rendering and