~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-26 10:41:48 UTC
  • mfrom: (2420.1.22 bzr.http.auth)
  • Revision ID: pqm@pqm.ubuntu.com-20070426104148-4l5wq2zemlzv0shg
http authentication and other integrated fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
import bzrlib
26
26
import bzrlib.errors as errors
27
 
from bzrlib.progress import DotsProgressBar, TTYProgressBar, ProgressBarStack
 
27
from bzrlib.progress import (
 
28
    DotsProgressBar,
 
29
    ProgressBarStack,
 
30
    TTYProgressBar,
 
31
    )
28
32
from bzrlib.tests import (
 
33
    TestCase,
29
34
    TestUIFactory,
30
35
    StringIOWrapper,
31
 
    TestCase,
32
36
    )
33
37
from bzrlib.tests.test_progress import _TTYStringIO
34
 
from bzrlib.ui import SilentUIFactory
 
38
from bzrlib.ui import (
 
39
    CLIUIFactory,
 
40
    SilentUIFactory,
 
41
    )
35
42
from bzrlib.ui.text import TextUIFactory
36
43
 
37
44
 
61
68
                                                   ui.get_password))
62
69
            # ': ' is appended to prompt
63
70
            self.assertEqual(': ', ui.stdout.getvalue())
 
71
            # stdin should be empty
 
72
            self.assertEqual('', ui.stdin.readline())
64
73
        finally:
65
74
            pb.finished()
66
75
 
84
93
            self.assertEqual(u'baz\u1234', password.decode('utf8'))
85
94
            self.assertEqual(u'Hello \u1234 some\u1234: ',
86
95
                             ui.stdout.getvalue().decode('utf8'))
 
96
            # stdin should be empty
 
97
            self.assertEqual('', ui.stdin.readline())
87
98
        finally:
88
99
            pb.finished()
89
100
 
99
110
            self.assertEqual(None, result)
100
111
            self.assertEqual("t\n", stdout.getvalue())
101
112
            # Since there was no update() call, there should be no clear() call
102
 
            self.failIf(re.search(r'^\r {10,}\r$', stderr.getvalue()) is not None,
 
113
            self.failIf(re.search(r'^\r {10,}\r$',
 
114
                                  stderr.getvalue()) is not None,
103
115
                        'We cleared the stderr without anything to put there')
104
116
        finally:
105
117
            pb.finished()
161
173
 
162
174
    def test_text_factory_setting_progress_bar(self):
163
175
        # we should be able to choose the progress bar type used.
164
 
        factory = bzrlib.ui.text.TextUIFactory(
165
 
            bar_type=DotsProgressBar)
 
176
        factory = TextUIFactory(bar_type=DotsProgressBar)
166
177
        bar = factory.nested_progress_bar()
167
178
        bar.finished()
168
179
        self.assertIsInstance(bar, DotsProgressBar)
169
180
 
170
181
    def test_cli_stdin_is_default_stdin(self):
171
 
        factory = bzrlib.ui.CLIUIFactory()
 
182
        factory = CLIUIFactory()
172
183
        self.assertEqual(sys.stdin, factory.stdin)
173
184
 
174
185
    def assert_get_bool_acceptance_of_user_input(self, factory):
175
 
        factory.stdin = StringIO("y\nyes with garbage\nyes\nn\nnot an answer\nno\nfoo\n")
 
186
        factory.stdin = StringIO("y\nyes with garbage\n"
 
187
                                 "yes\nn\nnot an answer\n"
 
188
                                 "no\nfoo\n")
176
189
        factory.stdout = StringIO()
177
190
        # there is no output from the base factory
178
191
        self.assertEqual(True, factory.get_boolean(""))
180
193
        self.assertEqual(False, factory.get_boolean(""))
181
194
        self.assertEqual(False, factory.get_boolean(""))
182
195
        self.assertEqual("foo\n", factory.stdin.read())
 
196
        # stdin should be empty
 
197
        self.assertEqual('', factory.stdin.readline())
183
198
 
184
199
    def test_silent_ui_getbool(self):
185
 
        factory = bzrlib.ui.SilentUIFactory()
 
200
        factory = SilentUIFactory()
186
201
        self.assert_get_bool_acceptance_of_user_input(factory)
187
202
 
188
203
    def test_silent_factory_prompts_silently(self):
189
 
        factory = bzrlib.ui.SilentUIFactory()
 
204
        factory = SilentUIFactory()
190
205
        stdout = StringIO()
191
206
        factory.stdin = StringIO("y\n")
192
 
        self.assertEqual(
193
 
            True,
194
 
            self.apply_redirected(
195
 
                None, stdout, stdout, factory.get_boolean, "foo")
196
 
            )
 
207
        self.assertEqual(True,
 
208
                         self.apply_redirected(None, stdout, stdout,
 
209
                                               factory.get_boolean, "foo"))
197
210
        self.assertEqual("", stdout.getvalue())
198
 
        
 
211
        # stdin should be empty
 
212
        self.assertEqual('', factory.stdin.readline())
 
213
 
199
214
    def test_text_ui_getbool(self):
200
 
        factory = bzrlib.ui.text.TextUIFactory()
 
215
        factory = TextUIFactory()
201
216
        self.assert_get_bool_acceptance_of_user_input(factory)
202
217
 
203
218
    def test_text_factory_prompts_and_clears(self):
204
219
        # a get_boolean call should clear the pb before prompting
205
 
        factory = bzrlib.ui.text.TextUIFactory(bar_type=DotsProgressBar)
 
220
        factory = TextUIFactory(bar_type=DotsProgressBar)
206
221
        factory.stdout = _TTYStringIO()
207
222
        factory.stdin = StringIO("yada\ny\n")
208
 
        pb = self.apply_redirected(
209
 
            factory.stdin, factory.stdout, factory.stdout, factory.nested_progress_bar)
 
223
        pb = self.apply_redirected(factory.stdin, factory.stdout,
 
224
                                   factory.stdout, factory.nested_progress_bar)
210
225
        pb.start_time = None
211
 
        self.apply_redirected(
212
 
            factory.stdin, factory.stdout, factory.stdout, pb.update, "foo", 0, 1)
213
 
        self.assertEqual(
214
 
            True,
215
 
            self.apply_redirected(
216
 
                None, factory.stdout, factory.stdout, factory.get_boolean, "what do you want")
217
 
            )
 
226
        self.apply_redirected(factory.stdin, factory.stdout,
 
227
                              factory.stdout, pb.update, "foo", 0, 1)
 
228
        self.assertEqual(True,
 
229
                         self.apply_redirected(None, factory.stdout,
 
230
                                               factory.stdout,
 
231
                                               factory.get_boolean,
 
232
                                               "what do you want"))
218
233
        output = factory.stdout.getvalue()
219
234
        self.assertEqual("foo: .\n"
220
235
                         "what do you want? [y/n]: what do you want? [y/n]: ",
221
236
                         factory.stdout.getvalue())
 
237
        # stdin should be empty
 
238
        self.assertEqual('', factory.stdin.readline())
 
239