~amanica/bzr/320119-log_exclusive_lower_bound

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_ui.py

  • Committer: Marius Kruger
  • Date: 2009-07-19 19:57:11 UTC
  • mfrom: (4511.1.36 +trunk)
  • Revision ID: amanic@gmail.com-20090719195711-xo5o3jzwjmvidfgh
merge with bzr.dev. no conflicts. put news in its place.

Show diffs side-by-side

added added

removed removed

Lines of Context:
174
174
        pb1.finished()
175
175
 
176
176
    def assert_get_bool_acceptance_of_user_input(self, factory):
177
 
        factory.stdin = StringIO("y\nyes with garbage\n"
178
 
                                 "yes\nn\nnot an answer\n"
179
 
                                 "no\n"
180
 
                                 "N\nY\n"
181
 
                                 "foo\n"
182
 
                                )
 
177
        factory.stdin = StringIO("y\n" # True
 
178
                                 "n\n" # False
 
179
                                 "yes with garbage\nY\n" # True
 
180
                                 "not an answer\nno\n" # False
 
181
                                 "I'm sure!\nyes\n" # True
 
182
                                 "NO\n" # False
 
183
                                 "foo\n")
183
184
        factory.stdout = StringIO()
184
185
        factory.stderr = StringIO()
185
186
        # there is no output from the base factory
186
187
        self.assertEqual(True, factory.get_boolean(""))
187
 
        self.assertEqual(True, factory.get_boolean(""))
188
 
        self.assertEqual(False, factory.get_boolean(""))
189
 
        self.assertEqual(False, factory.get_boolean(""))
190
 
        self.assertEqual(False, factory.get_boolean(""))
191
 
        self.assertEqual(True, factory.get_boolean(""))
 
188
        self.assertEqual(False, factory.get_boolean(""))
 
189
        self.assertEqual(True, factory.get_boolean(""))
 
190
        self.assertEqual(False, factory.get_boolean(""))
 
191
        self.assertEqual(True, factory.get_boolean(""))
 
192
        self.assertEqual(False, factory.get_boolean(""))
192
193
        self.assertEqual("foo\n", factory.stdin.read())
193
194
        # stdin should be empty
194
195
        self.assertEqual('', factory.stdin.readline())
355
356
            r'[####|               ] a:b:c 1/2'
356
357
            , uif._progress_view._render_line())
357
358
 
 
359
 
 
360
class TestBoolFromString(tests.TestCase):
 
361
 
 
362
    def assertIsTrue(self, s, accepted_values=None):
 
363
        res = _mod_ui.bool_from_string(s, accepted_values=accepted_values)
 
364
        self.assertEquals(True, res)
 
365
 
 
366
    def assertIsFalse(self, s, accepted_values=None):
 
367
        res = _mod_ui.bool_from_string(s, accepted_values=accepted_values)
 
368
        self.assertEquals(False, res)
 
369
 
 
370
    def assertIsNone(self, s, accepted_values=None):
 
371
        res = _mod_ui.bool_from_string(s, accepted_values=accepted_values)
 
372
        self.assertIs(None, res)
 
373
 
 
374
    def test_know_valid_values(self):
 
375
        self.assertIsTrue('true')
 
376
        self.assertIsFalse('false')
 
377
        self.assertIsTrue('1')
 
378
        self.assertIsFalse('0')
 
379
        self.assertIsTrue('on')
 
380
        self.assertIsFalse('off')
 
381
        self.assertIsTrue('yes')
 
382
        self.assertIsFalse('no')
 
383
        self.assertIsTrue('y')
 
384
        self.assertIsFalse('n')
 
385
        # Also try some case variations
 
386
        self.assertIsTrue('True')
 
387
        self.assertIsFalse('False')
 
388
        self.assertIsTrue('On')
 
389
        self.assertIsFalse('Off')
 
390
        self.assertIsTrue('ON')
 
391
        self.assertIsFalse('OFF')
 
392
        self.assertIsTrue('oN')
 
393
        self.assertIsFalse('oFf')
 
394
 
 
395
    def test_invalid_values(self):
 
396
        self.assertIsNone(None)
 
397
        self.assertIsNone('doubt')
 
398
        self.assertIsNone('frue')
 
399
        self.assertIsNone('talse')
 
400
        self.assertIsNone('42')
 
401
 
 
402
    def test_provided_values(self):
 
403
        av = dict(y=True, n=False, yes=True, no=False)
 
404
        self.assertIsTrue('y', av)
 
405
        self.assertIsTrue('Y', av)
 
406
        self.assertIsTrue('Yes', av)
 
407
        self.assertIsFalse('n', av)
 
408
        self.assertIsFalse('N', av)
 
409
        self.assertIsFalse('No', av)
 
410
        self.assertIsNone('1', av)
 
411
        self.assertIsNone('0', av)
 
412
        self.assertIsNone('on', av)
 
413
        self.assertIsNone('off', av)