~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Martin Pool
  • Date: 2009-06-22 09:53:28 UTC
  • mto: This revision was merged to the branch mainline in revision 4558.
  • Revision ID: mbp@sourcefrog.net-20090622095328-mpm51aoso6oe9fz3
SilentUIFactory now always errors when asked for input

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
class UITests(TestCase):
57
57
 
58
 
    def test_cli_factory_deprecated(self):
59
 
        uif = self.applyDeprecated(deprecated_in((1, 17, 0)),
60
 
            CLIUIFactory,
61
 
            StringIO(), StringIO(), StringIO())
62
 
        self.assertIsInstance(uif, UIFactory)
63
 
 
64
 
    def test_silent_factory(self):
65
 
        ui = SilentUIFactory()
66
 
        stdout = StringIO()
67
 
        self.assertRaises(
68
 
            NotImplementedError,
69
 
            self.apply_redirected,
70
 
            None, stdout, stdout, ui.get_password)
71
 
        self.assertEqual('', stdout.getvalue())
72
 
        self.assertEqual(None,
73
 
                         self.apply_redirected(None, stdout, stdout,
74
 
                                               ui.get_password,
75
 
                                               u'Hello\u1234 %(user)s',
76
 
                                               user=u'some\u1234'))
77
 
        self.assertEqual('', stdout.getvalue())
78
 
 
79
58
    def test_text_factory_ascii_password(self):
80
59
        ui = TestUIFactory(stdin='secret\n', stdout=StringIOWrapper(),
81
60
                           stderr=StringIOWrapper())
223
202
        # stdin should be empty
224
203
        self.assertEqual('', factory.stdin.readline())
225
204
 
226
 
    def test_silent_ui_getbool(self):
227
 
        factory = SilentUIFactory()
228
 
        self.assert_get_bool_acceptance_of_user_input(factory)
229
 
 
230
 
    def test_silent_factory_prompts_silently(self):
231
 
        factory = SilentUIFactory()
232
 
        stdout = StringIO()
233
 
        factory.stdin = StringIO("y\n")
234
 
        self.assertEqual(True,
235
 
                         self.apply_redirected(None, stdout, stdout,
236
 
                                               factory.get_boolean, "foo"))
237
 
        self.assertEqual("", stdout.getvalue())
238
 
        # stdin should be empty
239
 
        self.assertEqual('', factory.stdin.readline())
240
 
 
241
205
    def test_text_ui_getbool(self):
242
206
        factory = TextUIFactory(None, None, None)
243
207
        self.assert_get_bool_acceptance_of_user_input(factory)
283
247
        finally:
284
248
            pb.finished()
285
249
 
286
 
    def test_silent_ui_getusername(self):
287
 
        factory = SilentUIFactory()
288
 
        factory.stdin = StringIO("someuser\n\n")
289
 
        factory.stdout = StringIO()
290
 
        factory.stderr = StringIO()
291
 
        self.assertEquals(None,
292
 
            factory.get_username(u'Hello\u1234 %(host)s', host=u'some\u1234'))
293
 
        self.assertEquals("", factory.stdout.getvalue())
294
 
        self.assertEquals("", factory.stderr.getvalue())
295
 
        self.assertEquals("someuser\n\n", factory.stdin.getvalue())
296
 
 
297
250
    def test_text_ui_getusername(self):
298
251
        factory = TextUIFactory(None, None, None)
299
252
        factory.stdin = StringIO("someuser\n\n")
326
279
            pb.finished()
327
280
 
328
281
 
 
282
class CLIUITests(TestCase):
 
283
 
 
284
    def test_cli_factory_deprecated(self):
 
285
        uif = self.applyDeprecated(deprecated_in((1, 17, 0)),
 
286
            CLIUIFactory,
 
287
            StringIO(), StringIO(), StringIO())
 
288
        self.assertIsInstance(uif, UIFactory)
 
289
 
 
290
 
 
291
class SilentUITests(TestCase):
 
292
 
 
293
    def test_silent_factory(self):
 
294
        ui = SilentUIFactory()
 
295
        stdout = StringIO()
 
296
        self.assertRaises(
 
297
            NotImplementedError,
 
298
            self.apply_redirected,
 
299
            None, stdout, stdout, ui.get_password)
 
300
        # and it didn't write anything out either
 
301
        self.assertEqual('', stdout.getvalue())
 
302
 
 
303
    def test_silent_ui_getbool(self):
 
304
        factory = SilentUIFactory()
 
305
        stdout = StringIO()
 
306
        self.assertRaises(
 
307
            NotImplementedError,
 
308
            self.apply_redirected,
 
309
            None, stdout, stdout, factory.get_boolean, "foo")