~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Merge from bzr.dev, resolving conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    config,
28
28
    errors,
29
29
    osutils,
30
 
    mail_client,
31
30
    urlutils,
32
 
    trace,
33
31
    )
34
32
from bzrlib.branch import Branch
35
33
from bzrlib.bzrdir import BzrDir
415
413
        b = self.make_branch('!repo')
416
414
        self.assertEqual('!repo', b.get_config().get_nickname())
417
415
 
418
 
    def test_warn_if_masked(self):
419
 
        _warning = trace.warning
420
 
        warnings = []
421
 
        def warning(*args):
422
 
            warnings.append(args[0] % args[1:])
423
 
 
424
 
        def set_option(store, warn_masked=True):
425
 
            warnings[:] = []
426
 
            conf.set_user_option('example_option', repr(store), store=store,
427
 
                                 warn_masked=warn_masked)
428
 
        def assertWarning(warning):
429
 
            if warning is None:
430
 
                self.assertEqual(0, len(warnings))
431
 
            else:
432
 
                self.assertEqual(1, len(warnings))
433
 
                self.assertEqual(warning, warnings[0])
434
 
        trace.warning = warning
435
 
        try:
436
 
            branch = self.make_branch('.')
437
 
            conf = branch.get_config()
438
 
            set_option(config.STORE_GLOBAL)
439
 
            assertWarning(None)
440
 
            set_option(config.STORE_BRANCH)
441
 
            assertWarning(None)
442
 
            set_option(config.STORE_GLOBAL)
443
 
            assertWarning('Value "4" is masked by "3" from branch.conf')
444
 
            set_option(config.STORE_GLOBAL, warn_masked=False)
445
 
            assertWarning(None)
446
 
            set_option(config.STORE_LOCATION)
447
 
            assertWarning(None)
448
 
            set_option(config.STORE_BRANCH)
449
 
            assertWarning('Value "3" is masked by "0" from locations.conf')
450
 
            set_option(config.STORE_BRANCH, warn_masked=False)
451
 
            assertWarning(None)
452
 
        finally:
453
 
            trace.warning = _warning
454
 
 
455
416
 
456
417
class TestGlobalConfigItems(TestCase):
457
418
 
815
776
            self.my_location_config._get_option_policy(
816
777
            'http://www.example.com/norecurse', 'normal_option'),
817
778
            config.POLICY_NORECURSE)
 
779
        
818
780
 
819
781
    def test_post_commit_default(self):
820
782
        self.get_branch_config('/a/c')
1006
968
                                      location='http://example.com/specific')
1007
969
        self.assertEqual(my_config.get_user_option('option'), 'exact')
1008
970
 
1009
 
    def test_get_mail_client(self):
1010
 
        config = self.get_branch_config()
1011
 
        client = config.get_mail_client()
1012
 
        self.assertIsInstance(client, mail_client.DefaultMail)
1013
 
 
1014
 
        config.set_user_option('mail_client', 'default')
1015
 
        client = config.get_mail_client()
1016
 
        self.assertIsInstance(client, mail_client.DefaultMail)
1017
 
 
1018
 
        config.set_user_option('mail_client', 'editor')
1019
 
        client = config.get_mail_client()
1020
 
        self.assertIsInstance(client, mail_client.Editor)
1021
 
 
1022
 
        config.set_user_option('mail_client', 'thunderbird')
1023
 
        client = config.get_mail_client()
1024
 
        self.assertIsInstance(client, mail_client.Thunderbird)
1025
 
 
1026
 
        config.set_user_option('mail_client', 'evolution')
1027
 
        client = config.get_mail_client()
1028
 
        self.assertIsInstance(client, mail_client.Evolution)
1029
 
 
1030
 
        config.set_user_option('mail_client', 'kmail')
1031
 
        client = config.get_mail_client()
1032
 
        self.assertIsInstance(client, mail_client.KMail)
1033
 
 
1034
 
        config.set_user_option('mail_client', 'xdg-email')
1035
 
        client = config.get_mail_client()
1036
 
        self.assertIsInstance(client, mail_client.XDGEmail)
1037
 
 
1038
 
        config.set_user_option('mail_client', 'mapi')
1039
 
        client = config.get_mail_client()
1040
 
        self.assertIsInstance(client, mail_client.MAPIClient)
1041
 
 
1042
 
        config.set_user_option('mail_client', 'firebird')
1043
 
        self.assertRaises(errors.UnknownMailClient, config.get_mail_client)
1044
 
 
1045
971
 
1046
972
class TestMailAddressExtraction(TestCase):
1047
973
 
1050
976
                         config.extract_email_address('Jane <jane@test.com>'))
1051
977
        self.assertRaises(errors.NoEmailInUsername,
1052
978
                          config.extract_email_address, 'Jane Tester')
1053
 
 
1054
 
 
1055
 
class TestTreeConfig(TestCaseWithTransport):
1056
 
 
1057
 
    def test_get_value(self):
1058
 
        """Test that retreiving a value from a section is possible"""
1059
 
        branch = self.make_branch('.')
1060
 
        tree_config = config.TreeConfig(branch)
1061
 
        tree_config.set_option('value', 'key', 'SECTION')
1062
 
        tree_config.set_option('value2', 'key2')
1063
 
        tree_config.set_option('value3-top', 'key3')
1064
 
        tree_config.set_option('value3-section', 'key3', 'SECTION')
1065
 
        value = tree_config.get_option('key', 'SECTION')
1066
 
        self.assertEqual(value, 'value')
1067
 
        value = tree_config.get_option('key2')
1068
 
        self.assertEqual(value, 'value2')
1069
 
        self.assertEqual(tree_config.get_option('non-existant'), None)
1070
 
        value = tree_config.get_option('non-existant', 'SECTION')
1071
 
        self.assertEqual(value, None)
1072
 
        value = tree_config.get_option('non-existant', default='default')
1073
 
        self.assertEqual(value, 'default')
1074
 
        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
1075
 
        value = tree_config.get_option('key2', 'NOSECTION', default='default')
1076
 
        self.assertEqual(value, 'default')
1077
 
        value = tree_config.get_option('key3')
1078
 
        self.assertEqual(value, 'value3-top')
1079
 
        value = tree_config.get_option('key3', 'SECTION')
1080
 
        self.assertEqual(value, 'value3-section')