~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Martin Pool
  • Date: 2009-07-24 03:15:56 UTC
  • mfrom: (4565 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4566.
  • Revision ID: mbp@sourcefrog.net-20090724031556-5zyef6f1ixtn6r3z
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
2
 
#   Authors: Robert Collins <robert.collins@canonical.com>
 
1
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
3
2
#
4
3
# This program is free software; you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License as published by
367
366
        parser = my_config._get_parser(file=config_file)
368
367
        self.failUnless(my_config._get_parser() is parser)
369
368
 
 
369
    def test_get_user_option_as_bool(self):
 
370
        config_file = StringIO("""
 
371
a_true_bool = true
 
372
a_false_bool = 0
 
373
an_invalid_bool = maybe
 
374
a_list = hmm, who knows ? # This interpreted as a list !
 
375
""".encode('utf-8'))
 
376
        my_config = config.IniBasedConfig(None)
 
377
        parser = my_config._get_parser(file=config_file)
 
378
        get_option = my_config.get_user_option_as_bool
 
379
        self.assertEqual(True, get_option('a_true_bool'))
 
380
        self.assertEqual(False, get_option('a_false_bool'))
 
381
        self.assertIs(None, get_option('an_invalid_bool'))
 
382
        self.assertIs(None, get_option('not_defined_in_this_config'))
370
383
 
371
384
class TestGetConfig(tests.TestCase):
372
385
 
1547
1560
"""))
1548
1561
        entered_password = 'typed-by-hand'
1549
1562
        stdout = tests.StringIOWrapper()
 
1563
        stderr = tests.StringIOWrapper()
1550
1564
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1551
 
                                            stdout=stdout)
 
1565
                                            stdout=stdout, stderr=stderr)
1552
1566
 
1553
1567
        # Since the password defined in the authentication config is ignored,
1554
1568
        # the user is prompted
1568
1582
"""))
1569
1583
        entered_password = 'typed-by-hand'
1570
1584
        stdout = tests.StringIOWrapper()
 
1585
        stderr = tests.StringIOWrapper()
1571
1586
        ui.ui_factory = tests.TestUIFactory(stdin=entered_password + '\n',
1572
 
                                            stdout=stdout)
 
1587
                                            stdout=stdout,
 
1588
                                            stderr=stderr)
1573
1589
 
1574
1590
        # Since the password defined in the authentication config is ignored,
1575
1591
        # the user is prompted