~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-04 23:36:44 UTC
  • mfrom: (2224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2225.
  • Revision ID: bialix@ukr.net-20070104233644-7znkxoj9b0y7ev28
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    errors,
29
29
    osutils,
30
30
    urlutils,
31
 
    trace,
32
31
    )
33
32
from bzrlib.branch import Branch
34
33
from bzrlib.bzrdir import BzrDir
270
269
 
271
270
    def setUp(self):
272
271
        super(TestConfigPath, self).setUp()
 
272
        self.old_home = os.environ.get('HOME', None)
 
273
        self.old_appdata = os.environ.get('APPDATA', None)
273
274
        os.environ['HOME'] = '/home/bogus'
274
 
        if sys.platform == 'win32':
275
 
            os.environ['BZR_HOME'] = \
276
 
                r'C:\Documents and Settings\bogus\Application Data'
 
275
        os.environ['APPDATA'] = \
 
276
            r'C:\Documents and Settings\bogus\Application Data'
277
277
 
 
278
    def tearDown(self):
 
279
        if self.old_home is None:
 
280
            del os.environ['HOME']
 
281
        else:
 
282
            os.environ['HOME'] = self.old_home
 
283
        if self.old_appdata is None:
 
284
            del os.environ['APPDATA']
 
285
        else:
 
286
            os.environ['APPDATA'] = self.old_appdata
 
287
        super(TestConfigPath, self).tearDown()
 
288
    
278
289
    def test_config_dir(self):
279
290
        if sys.platform == 'win32':
280
291
            self.assertEqual(config.config_dir(), 
402
413
 
403
414
    def test_config_creates_local(self):
404
415
        """Creating a new entry in config uses a local path."""
405
 
        branch = self.make_branch('branch', format='knit')
 
416
        branch = self.make_branch('branch')
406
417
        branch.set_push_location('http://foobar')
407
418
        locations = config.locations_config_filename()
408
419
        local_path = osutils.getcwd().encode('utf8')
414
425
        b = self.make_branch('!repo')
415
426
        self.assertEqual('!repo', b.get_config().get_nickname())
416
427
 
417
 
    def test_warn_if_masked(self):
418
 
        _warning = trace.warning
419
 
        warnings = []
420
 
        def warning(*args):
421
 
            warnings.append(args[0] % args[1:])
422
 
 
423
 
        def set_option(store, warn_masked=True):
424
 
            warnings[:] = []
425
 
            conf.set_user_option('example_option', repr(store), store=store,
426
 
                                 warn_masked=warn_masked)
427
 
        def assertWarning(warning):
428
 
            if warning is None:
429
 
                self.assertEqual(0, len(warnings))
430
 
            else:
431
 
                self.assertEqual(1, len(warnings))
432
 
                self.assertEqual(warning, warnings[0])
433
 
        trace.warning = warning
434
 
        try:
435
 
            branch = self.make_branch('.')
436
 
            conf = branch.get_config()
437
 
            set_option(config.STORE_GLOBAL)
438
 
            assertWarning(None)
439
 
            set_option(config.STORE_BRANCH)
440
 
            assertWarning(None)
441
 
            set_option(config.STORE_GLOBAL)
442
 
            assertWarning('Value "4" is masked by "3" from branch.conf')
443
 
            set_option(config.STORE_GLOBAL, warn_masked=False)
444
 
            assertWarning(None)
445
 
            set_option(config.STORE_LOCATION)
446
 
            assertWarning(None)
447
 
            set_option(config.STORE_BRANCH)
448
 
            assertWarning('Value "3" is masked by "0" from locations.conf')
449
 
            set_option(config.STORE_BRANCH, warn_masked=False)
450
 
            assertWarning(None)
451
 
        finally:
452
 
            trace.warning = _warning
453
 
 
454
428
 
455
429
class TestGlobalConfigItems(TestCase):
456
430
 
814
788
            self.my_location_config._get_option_policy(
815
789
            'http://www.example.com/norecurse', 'normal_option'),
816
790
            config.POLICY_NORECURSE)
 
791
        
817
792
 
818
793
    def test_post_commit_default(self):
819
794
        self.get_branch_config('/a/c')
1013
988
                         config.extract_email_address('Jane <jane@test.com>'))
1014
989
        self.assertRaises(errors.NoEmailInUsername,
1015
990
                          config.extract_email_address, 'Jane Tester')
1016
 
 
1017
 
 
1018
 
class TestTreeConfig(TestCaseWithTransport):
1019
 
 
1020
 
    def test_get_value(self):
1021
 
        """Test that retreiving a value from a section is possible"""
1022
 
        branch = self.make_branch('.')
1023
 
        tree_config = config.TreeConfig(branch)
1024
 
        tree_config.set_option('value', 'key', 'SECTION')
1025
 
        tree_config.set_option('value2', 'key2')
1026
 
        tree_config.set_option('value3-top', 'key3')
1027
 
        tree_config.set_option('value3-section', 'key3', 'SECTION')
1028
 
        value = tree_config.get_option('key', 'SECTION')
1029
 
        self.assertEqual(value, 'value')
1030
 
        value = tree_config.get_option('key2')
1031
 
        self.assertEqual(value, 'value2')
1032
 
        self.assertEqual(tree_config.get_option('non-existant'), None)
1033
 
        value = tree_config.get_option('non-existant', 'SECTION')
1034
 
        self.assertEqual(value, None)
1035
 
        value = tree_config.get_option('non-existant', default='default')
1036
 
        self.assertEqual(value, 'default')
1037
 
        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
1038
 
        value = tree_config.get_option('key2', 'NOSECTION', default='default')
1039
 
        self.assertEqual(value, 'default')
1040
 
        value = tree_config.get_option('key3')
1041
 
        self.assertEqual(value, 'value3-top')
1042
 
        value = tree_config.get_option('key3', 'SECTION')
1043
 
        self.assertEqual(value, 'value3-section')