~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-05 01:55:47 UTC
  • mfrom: (1551.15.37 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20070705015547-qyj4nsc5w3y53b4w
Warn when setting config values that will be masked (#122286)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    errors,
29
29
    osutils,
30
30
    urlutils,
 
31
    trace,
31
32
    )
32
33
from bzrlib.branch import Branch
33
34
from bzrlib.bzrdir import BzrDir
413
414
        b = self.make_branch('!repo')
414
415
        self.assertEqual('!repo', b.get_config().get_nickname())
415
416
 
 
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
 
416
454
 
417
455
class TestGlobalConfigItems(TestCase):
418
456
 
776
814
            self.my_location_config._get_option_policy(
777
815
            'http://www.example.com/norecurse', 'normal_option'),
778
816
            config.POLICY_NORECURSE)
779
 
        
780
817
 
781
818
    def test_post_commit_default(self):
782
819
        self.get_branch_config('/a/c')