100
99
def test_text_factory_utf8_password(self):
101
"""Test an utf8 password.
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.
106
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()
107
105
ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = 'utf8'
108
pb = ui.nested_progress_bar()
110
password = self.apply_redirected(ui.stdin, ui.stdout, ui.stderr,
112
u'Hello \u1234 %(user)s',
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())
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())
124
114
def test_text_ui_get_boolean(self):
125
115
stdin = tests.StringIOWrapper("y\n" # True
273
263
def test_text_ui_getusername(self):
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"))
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"))
285
274
# stdin should be empty
286
self.assertEqual('', factory.stdin.readline())
275
self.assertEqual('', ui.stdin.readline())
288
277
def test_text_ui_getusername_utf8(self):
289
ui = tests.TestUIFactory(stdin=u'someuser\u1234'.encode('utf8'),
290
stdout=tests.StringIOWrapper(),
291
stderr=tests.StringIOWrapper())
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()
292
282
ui.stderr.encoding = ui.stdout.encoding = ui.stdin.encoding = "utf8"
293
pb = ui.nested_progress_bar()
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())
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())
305
289
def test_quietness(self):
306
290
self.overrideEnv('BZR_PROGRESS_BAR', 'text')