~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

(vila) AuthConfig alwaus return user/password as unicode. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

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