~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Patch Queue Manager
  • Date: 2014-10-06 16:32:42 UTC
  • mfrom: (6597.2.4 split-diff-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20141006163242-c2cll01cwc24grkk
(vila) Split some tests to be able to get finer grained failures (Vincent
 Ladeuil)

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.GlobalConfig().set_user_option('output_encoding',
60
 
            enc)
 
59
        config.GlobalStack().set('output_encoding', enc)
61
60
        ui = tests.TestUIFactory(stdin=None,
62
61
            stdout=tests.StringIOWrapper(),
63
62
            stderr=tests.StringIOWrapper())
98
97
            pb.finished()
99
98
 
100
99
    def test_text_factory_utf8_password(self):
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'))
 
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()
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()
 
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())
123
113
 
124
114
    def test_text_ui_get_boolean(self):
125
115
        stdin = tests.StringIOWrapper("y\n" # True
271
261
            pb.finished()
272
262
 
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())
287
276
 
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()
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()
 
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())
304
288
 
305
289
    def test_quietness(self):
306
290
        self.overrideEnv('BZR_PROGRESS_BAR', 'text')