~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

merge shell-like-tests into description resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
139
139
        pb1.finished()
140
140
 
141
141
    def test_text_ui_get_boolean(self):
142
 
        stdin = tests.StringIOWrapper(
143
 
            "y\n" # True
144
 
            "n\n" # False
145
 
            "yes with garbage\nY\n" # True
146
 
            "not an answer\nno\n" # False
147
 
            "I'm sure!\nyes\n" # True
148
 
            "NO\n" # False
149
 
            "foo\n")
 
142
        stdin = tests.StringIOWrapper("y\n" # True
 
143
                                      "n\n" # False
 
144
                                      "yes with garbage\nY\n" # True
 
145
                                      "not an answer\nno\n" # False
 
146
                                      "I'm sure!\nyes\n" # True
 
147
                                      "NO\n" # False
 
148
                                      "foo\n")
150
149
        stdout = tests.StringIOWrapper()
151
150
        stderr = tests.StringIOWrapper()
152
151
        factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
250
249
            pb.finished()
251
250
 
252
251
 
 
252
class TestTextUIOutputStream(tests.TestCase):
 
253
    """Tests for output stream that synchronizes with progress bar."""
 
254
 
 
255
    def test_output_clears_terminal(self):
 
256
        stdout = tests.StringIOWrapper()
 
257
        stderr = tests.StringIOWrapper()
 
258
        clear_calls = []
 
259
 
 
260
        uif =  _mod_ui_text.TextUIFactory(None, stdout, stderr)
 
261
        uif.clear_term = lambda: clear_calls.append('clear')
 
262
 
 
263
        stream = _mod_ui_text.TextUIOutputStream(uif, uif.stdout)
 
264
        stream.write("Hello world!\n")
 
265
        stream.write("there's more...\n")
 
266
        stream.writelines(["1\n", "2\n", "3\n"])
 
267
 
 
268
        self.assertEqual(stdout.getvalue(),
 
269
            "Hello world!\n"
 
270
            "there's more...\n"
 
271
            "1\n2\n3\n")
 
272
        self.assertEqual(['clear', 'clear', 'clear'],
 
273
            clear_calls)
 
274
 
 
275
        stream.flush()
 
276
 
 
277
 
253
278
class UITests(tests.TestCase):
254
279
 
255
280
    def test_progress_construction(self):
350
375
        self.assertEqual('password',
351
376
                         uif.get_password('Password for %(host)s',
352
377
                                          host='example.com'))
353
 
        self.assertEqual(42, uif.get_integer('And all that jazz ?'))
354
378
 
355
379
 
356
380
class TestBoolFromString(tests.TestCase):