~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Martin
  • Date: 2012-07-28 15:26:22 UTC
  • mto: This revision was merged to the branch mainline in revision 6546.
  • Revision ID: gzlist@googlemail.com-20120728152622-wkjruul7dtg6c0ts
Add release notes

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
    def test_output_encoding_configuration(self):
58
58
        enc = fixtures.generate_unicode_encodings().next()
59
 
        config.GlobalStack().set('output_encoding', enc)
 
59
        config.GlobalConfig().set_user_option('output_encoding',
 
60
            enc)
60
61
        ui = tests.TestUIFactory(stdin=None,
61
62
            stdout=tests.StringIOWrapper(),
62
63
            stderr=tests.StringIOWrapper())
97
98
            pb.finished()
98
99
 
99
100
    def test_text_factory_utf8_password(self):
100
 
        """Test an utf8 password."""
101
 
        ui = _mod_ui_text.TextUIFactory(None, None, None)
102
 
        ui.stdin = tests.StringIOWrapper(u'baz\u1234'.encode('utf8'))
103
 
        ui.stdout = tests.StringIOWrapper()
104
 
        ui.stderr = tests.StringIOWrapper()
 
101
        """Test an utf8 password.
 
102
 
 
103
        We can't predict what encoding users will have for stdin, so we force
 
104
        it to utf8 to test that we transport the password correctly.
 
105
        """
 
106
        ui = self.make_test_ui_factory(u'baz\u1234'.encode('utf8'))
105
107
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
106
 
        password = ui.get_password(u'Hello \u1234 %(user)s', user=u'some\u1234')
107
 
        self.assertEqual(u'baz\u1234', password)
108
 
        self.assertEqual(u'Hello \u1234 some\u1234: ',
109
 
                         ui.stderr.getvalue().decode('utf8'))
110
 
        # stdin and stdout should be empty
111
 
        self.assertEqual('', ui.stdin.readline())
112
 
        self.assertEqual('', ui.stdout.getvalue())
 
108
        pb = ui.nested_progress_bar()
 
109
        try:
 
110
            password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
 
111
                                             ui.get_password,
 
112
                                             u'Hello \u1234 %(user)s',
 
113
                                             user=u'some\u1234')
 
114
            # We use StringIO objects, we need to decode them
 
115
            self.assertEqual(u'baz\u1234', password.decode('utf8'))
 
116
            self.assertEqual(u'Hello \u1234 some\u1234: ',
 
117
                             ui.stderr.getvalue().decode('utf8'))
 
118
            # stdin and stdout should be empty
 
119
            self.assertEqual('', ui.stdin.readline())
 
120
            self.assertEqual('', ui.stdout.readline())
 
121
        finally:
 
122
            pb.finished()
113
123
 
114
124
    def test_text_ui_get_boolean(self):
115
125
        stdin = tests.StringIOWrapper("y\n" # True
261
271
            pb.finished()
262
272
 
263
273
    def test_text_ui_getusername(self):
264
 
        ui = _mod_ui_text.TextUIFactory(None, None, None)
265
 
        ui.stdin = tests.StringIOWrapper('someuser\n\n')
266
 
        ui.stdout = tests.StringIOWrapper()
267
 
        ui.stderr = tests.StringIOWrapper()
268
 
        ui.stdout.encoding = 'utf8'
269
 
        self.assertEqual('someuser',
270
 
                         ui.get_username(u'Hello %(host)s', host='some'))
271
 
        self.assertEquals('Hello some: ', ui.stderr.getvalue())
272
 
        self.assertEquals('', ui.stdout.getvalue())
273
 
        self.assertEqual('', ui.get_username(u"Gebruiker"))
 
274
        factory = _mod_ui_text.TextUIFactory(None, None, None)
 
275
        factory.stdin = tests.StringIOWrapper("someuser\n\n")
 
276
        factory.stdout = tests.StringIOWrapper()
 
277
        factory.stderr = tests.StringIOWrapper()
 
278
        factory.stdout.encoding = "utf8"
 
279
        # there is no output from the base factory
 
280
        self.assertEqual("someuser",
 
281
                         factory.get_username(u'Hello %(host)s', host='some'))
 
282
        self.assertEquals("Hello some: ", factory.stderr.getvalue())
 
283
        self.assertEquals('', factory.stdout.getvalue())
 
284
        self.assertEqual("", factory.get_username(u"Gebruiker"))
274
285
        # stdin should be empty
275
 
        self.assertEqual('', ui.stdin.readline())
 
286
        self.assertEqual('', factory.stdin.readline())
276
287
 
277
288
    def test_text_ui_getusername_utf8(self):
278
 
        ui = _mod_ui_text.TextUIFactory(None, None, None)
279
 
        ui.stdin = tests.StringIOWrapper(u'someuser\u1234'.encode('utf8'))
280
 
        ui.stdout = tests.StringIOWrapper()
281
 
        ui.stderr = tests.StringIOWrapper()
 
289
        ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
 
290
                                 stdout=tests.StringIOWrapper(),
 
291
                                 stderr=tests.StringIOWrapper())
282
292
        ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
283
 
        username = ui.get_username(u'Hello %(host)s', host=u'some\u1234')
284
 
        self.assertEquals(u"someuser\u1234", username)
285
 
        self.assertEquals(u"Hello some\u1234: ",
286
 
                          ui.stderr.getvalue().decode("utf8"))
287
 
        self.assertEquals('', ui.stdout.getvalue())
 
293
        pb = ui.nested_progress_bar()
 
294
        try:
 
295
            # there is no output from the base factory
 
296
            username = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
 
297
                ui.get_username, u'Hello\u1234 %(host)s', host=u'some\u1234')
 
298
            self.assertEquals(u"someuser\u1234", username.decode('utf8'))
 
299
            self.assertEquals(u"Hello\u1234 some\u1234: ",
 
300
                              ui.stderr.getvalue().decode("utf8"))
 
301
            self.assertEquals('', ui.stdout.getvalue())
 
302
        finally:
 
303
            pb.finished()
288
304
 
289
305
    def test_quietness(self):
290
306
        self.overrideEnv('BZR_PROGRESS_BAR', 'text')