~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-27 10:48:00 UTC
  • mfrom: (5923.1.3 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20110527104800-fvcjlygvqloos6kl
(vila) Require prompts to always be unicode (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    def test_text_factory_confirm(self):
64
64
        # turns into reading a regular boolean
65
65
        ui = self.make_test_ui_factory('n\n')
66
 
        self.assertEquals(ui.confirm_action('Should %(thing)s pass?',
 
66
        self.assertEquals(ui.confirm_action(u'Should %(thing)s pass?',
67
67
            'bzrlib.tests.test_ui.confirmation',
68
68
            {'thing': 'this'},),
69
69
            False)
119
119
        stdout = tests.StringIOWrapper()
120
120
        stderr = tests.StringIOWrapper()
121
121
        factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
122
 
        self.assertEqual(True, factory.get_boolean(""))
123
 
        self.assertEqual(False, factory.get_boolean(""))
124
 
        self.assertEqual(True, factory.get_boolean(""))
125
 
        self.assertEqual(False, factory.get_boolean(""))
126
 
        self.assertEqual(True, factory.get_boolean(""))
127
 
        self.assertEqual(False, factory.get_boolean(""))
 
122
        self.assertEqual(True, factory.get_boolean(u""))
 
123
        self.assertEqual(False, factory.get_boolean(u""))
 
124
        self.assertEqual(True, factory.get_boolean(u""))
 
125
        self.assertEqual(False, factory.get_boolean(u""))
 
126
        self.assertEqual(True, factory.get_boolean(u""))
 
127
        self.assertEqual(False, factory.get_boolean(u""))
128
128
        self.assertEqual("foo\n", factory.stdin.read())
129
129
        # stdin should be empty
130
130
        self.assertEqual('', factory.stdin.readline())
137
137
        stdout = tests.StringIOWrapper()
138
138
        stderr = tests.StringIOWrapper()
139
139
        factory = _mod_ui_text.TextUIFactory(stdin, stdout, stderr)
140
 
        self.assertEqual(1, factory.get_integer(""))
141
 
        self.assertEqual(-2, factory.get_integer(""))
142
 
        self.assertEqual(42, factory.get_integer(""))
 
140
        self.assertEqual(1, factory.get_integer(u""))
 
141
        self.assertEqual(-2, factory.get_integer(u""))
 
142
        self.assertEqual(42, factory.get_integer(u""))
143
143
 
144
144
    def test_text_factory_prompt(self):
145
145
        # see <https://launchpad.net/bugs/365891>
146
146
        StringIO = tests.StringIOWrapper
147
147
        factory = _mod_ui_text.TextUIFactory(StringIO(), StringIO(), StringIO())
148
 
        factory.prompt('foo %2e')
 
148
        factory.prompt(u'foo %2e')
149
149
        self.assertEqual('', factory.stdout.getvalue())
150
150
        self.assertEqual('foo %2e', factory.stderr.getvalue())
151
151
 
166
166
                         self.apply_redirected(None, factory.stdout,
167
167
                                               factory.stdout,
168
168
                                               factory.get_boolean,
169
 
                                               "what do you want"))
 
169
                                               u"what do you want"))
170
170
        output = out.getvalue()
171
171
        self.assertContainsRe(output,
172
172
            "| foo *\r\r  *\r*")
195
195
        factory.stdout.encoding = "utf8"
196
196
        # there is no output from the base factory
197
197
        self.assertEqual("someuser",
198
 
                         factory.get_username('Hello %(host)s', host='some'))
 
198
                         factory.get_username(u'Hello %(host)s', host='some'))
199
199
        self.assertEquals("Hello some: ", factory.stderr.getvalue())
200
200
        self.assertEquals('', factory.stdout.getvalue())
201
 
        self.assertEqual("", factory.get_username("Gebruiker"))
 
201
        self.assertEqual("", factory.get_username(u"Gebruiker"))
202
202
        # stdin should be empty
203
203
        self.assertEqual('', factory.stdin.readline())
204
204
 
352
352
        self.assertRaises(
353
353
            NotImplementedError,
354
354
            self.apply_redirected,
355
 
            None, stdout, stdout, factory.get_boolean, "foo")
 
355
            None, stdout, stdout, factory.get_boolean, u"foo")
356
356
 
357
357
 
358
358
class TestUIFactoryTests(tests.TestCase):
371
371
 
372
372
    def test_canned_input_get_input(self):
373
373
        uif = _mod_ui.CannedInputUIFactory([True, 'mbp', 'password', 42])
374
 
        self.assertEqual(True, uif.get_boolean('Extra cheese?'))
375
 
        self.assertEqual('mbp', uif.get_username('Enter your user name'))
 
374
        self.assertEqual(True, uif.get_boolean(u'Extra cheese?'))
 
375
        self.assertEqual('mbp', uif.get_username(u'Enter your user name'))
376
376
        self.assertEqual('password',
377
 
                         uif.get_password('Password for %(host)s',
 
377
                         uif.get_password(u'Password for %(host)s',
378
378
                                          host='example.com'))
379
 
        self.assertEqual(42, uif.get_integer('And all that jazz ?'))
 
379
        self.assertEqual(42, uif.get_integer(u'And all that jazz ?'))
380
380
 
381
381
 
382
382
class TestBoolFromString(tests.TestCase):