~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Jelmer Vernooij
  • Date: 2012-04-02 01:44:26 UTC
  • mfrom: (6518 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6519.
  • Revision ID: jelmer@samba.org-20120402014426-0o5qtysohyl006b2
merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#import bzrlib specific imports here
28
28
from bzrlib import (
29
29
    branch,
30
 
    bzrdir,
31
30
    config,
 
31
    controldir,
32
32
    diff,
33
33
    errors,
34
34
    osutils,
115
115
 
116
116
def build_control_store(test):
117
117
    build_backing_branch(test, 'branch')
118
 
    b = bzrdir.BzrDir.open('branch')
 
118
    b = controldir.ControlDir.open('branch')
119
119
    return config.ControlStore(b)
120
120
config.test_store_builder_registry.register('control', build_control_store)
121
121
 
476
476
    def test_constructs(self):
477
477
        config.Config()
478
478
 
479
 
    def test_no_default_editor(self):
480
 
        self.assertRaises(
481
 
            NotImplementedError,
482
 
            self.applyDeprecated, deprecated_in((2, 4, 0)),
483
 
            config.Config().get_editor)
484
 
 
485
479
    def test_user_email(self):
486
480
        my_config = InstrumentedConfig()
487
481
        self.assertEqual('robert.collins@example.org', my_config.user_email())
689
683
        self.assertFileEqual(content, 'test.conf')
690
684
 
691
685
 
692
 
class TestIniConfigOptionExpansionDefaultValue(tests.TestCaseInTempDir):
693
 
    """What is the default value of expand for config options.
694
 
 
695
 
    This is an opt-in beta feature used to evaluate whether or not option
696
 
    references can appear in dangerous place raising exceptions, disapearing
697
 
    (and as such corrupting data) or if it's safe to activate the option by
698
 
    default.
699
 
 
700
 
    Note that these tests relies on config._expand_default_value being already
701
 
    overwritten in the parent class setUp.
702
 
    """
703
 
 
704
 
    def setUp(self):
705
 
        super(TestIniConfigOptionExpansionDefaultValue, self).setUp()
706
 
        self.config = None
707
 
        self.warnings = []
708
 
        def warning(*args):
709
 
            self.warnings.append(args[0] % args[1:])
710
 
        self.overrideAttr(trace, 'warning', warning)
711
 
 
712
 
    def get_config(self, expand):
713
 
        c = config.GlobalConfig.from_string('bzr.config.expand=%s' % (expand,),
714
 
                                            save=True)
715
 
        return c
716
 
 
717
 
    def assertExpandIs(self, expected):
718
 
        actual = config._get_expand_default_value()
719
 
        #self.config.get_user_option_as_bool('bzr.config.expand')
720
 
        self.assertEquals(expected, actual)
721
 
 
722
 
    def test_default_is_None(self):
723
 
        self.assertEquals(None, config._expand_default_value)
724
 
 
725
 
    def test_default_is_False_even_if_None(self):
726
 
        self.config = self.get_config(None)
727
 
        self.assertExpandIs(False)
728
 
 
729
 
    def test_default_is_False_even_if_invalid(self):
730
 
        self.config = self.get_config('<your choice>')
731
 
        self.assertExpandIs(False)
732
 
        # ...
733
 
        # Huh ? My choice is False ? Thanks, always happy to hear that :D
734
 
        # Wait, you've been warned !
735
 
        self.assertLength(1, self.warnings)
736
 
        self.assertEquals(
737
 
            'Value "<your choice>" is not a boolean for "bzr.config.expand"',
738
 
            self.warnings[0])
739
 
 
740
 
    def test_default_is_True(self):
741
 
        self.config = self.get_config(True)
742
 
        self.assertExpandIs(True)
743
 
 
744
 
    def test_default_is_False(self):
745
 
        self.config = self.get_config(False)
746
 
        self.assertExpandIs(False)
747
 
 
748
 
 
749
686
class TestIniConfigOptionExpansion(tests.TestCase):
750
687
    """Test option expansion from the IniConfig level.
751
688
 
1142
1079
 
1143
1080
    def test_get_config(self):
1144
1081
        """The Branch.get_config method works properly"""
1145
 
        b = bzrdir.BzrDir.create_standalone_workingtree('.').branch
 
1082
        b = controldir.ControlDir.create_standalone_workingtree('.').branch
1146
1083
        my_config = b.get_config()
1147
1084
        self.assertIs(my_config.get_user_option('wacky'), None)
1148
1085
        my_config.set_user_option('wacky', 'unlikely')
1246
1183
        my_config = config.GlobalConfig()
1247
1184
        self.assertEqual(None, my_config._get_user_id())
1248
1185
 
1249
 
    def test_configured_editor(self):
1250
 
        my_config = config.GlobalConfig.from_string(sample_config_text)
1251
 
        editor = self.applyDeprecated(
1252
 
            deprecated_in((2, 4, 0)), my_config.get_editor)
1253
 
        self.assertEqual('vim', editor)
1254
 
 
1255
1186
    def test_signatures_always(self):
1256
1187
        my_config = config.GlobalConfig.from_string(sample_always_signatures)
1257
1188
        self.assertEqual(config.CHECK_NEVER,
2203
2134
        self.assertGetHook(remote_branch._get_config(), 'file', 'branch')
2204
2135
 
2205
2136
    def test_get_hook_remote_bzrdir(self):
2206
 
        remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
 
2137
        remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2207
2138
        conf = remote_bzrdir._get_config()
2208
2139
        conf.set_option('remotedir', 'file')
2209
2140
        self.assertGetHook(conf, 'file', 'remotedir')
2231
2162
    def test_set_hook_remote_bzrdir(self):
2232
2163
        remote_branch = branch.Branch.open(self.get_url('tree'))
2233
2164
        self.addCleanup(remote_branch.lock_write().unlock)
2234
 
        remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
 
2165
        remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2235
2166
        self.assertSetHook(remote_bzrdir._get_config(), 'file', 'remotedir')
2236
2167
 
2237
2168
    def assertLoadHook(self, expected_nb_calls, name, conf_class, *conf_args):
2254
2185
        self.assertLoadHook(1, 'file', remote.RemoteBranchConfig, remote_branch)
2255
2186
 
2256
2187
    def test_load_hook_remote_bzrdir(self):
2257
 
        remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
 
2188
        remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2258
2189
        # The config file doesn't exist, set an option to force its creation
2259
2190
        conf = remote_bzrdir._get_config()
2260
2191
        conf.set_option('remotedir', 'file')
2285
2216
    def test_save_hook_remote_bzrdir(self):
2286
2217
        remote_branch = branch.Branch.open(self.get_url('tree'))
2287
2218
        self.addCleanup(remote_branch.lock_write().unlock)
2288
 
        remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
 
2219
        remote_bzrdir = controldir.ControlDir.open(self.get_url('tree'))
2289
2220
        self.assertSaveHook(remote_bzrdir._get_config())
2290
2221
 
2291
2222
 
2328
2259
        opt = config.Option('foo', default=bar_not_unicode)
2329
2260
        self.assertRaises(AssertionError, opt.get_default)
2330
2261
 
 
2262
    def test_get_help_topic(self):
 
2263
        opt = config.Option('foo')
 
2264
        self.assertEquals('foo', opt.get_help_topic())
 
2265
 
2331
2266
 
2332
2267
class TestOptionConverterMixin(object):
2333
2268
 
2925
2860
        store.save()
2926
2861
        self.assertEquals(False, self.has_store(store))
2927
2862
 
 
2863
    def test_mutable_section_shared(self):
 
2864
        store = self.get_store(self)
 
2865
        store._load_from_string('foo=bar\n')
 
2866
        # FIXME: There should be a better way than relying on the test
 
2867
        # parametrization to identify branch.conf -- vila 2011-0526
 
2868
        if self.store_id in ('branch', 'remote_branch'):
 
2869
            # branch stores requires write locked branches
 
2870
            self.addCleanup(store.branch.lock_write().unlock)
 
2871
        section1 = store.get_mutable_section(None)
 
2872
        section2 = store.get_mutable_section(None)
 
2873
        # If we get different sections, different callers won't share the
 
2874
        # modification
 
2875
        self.assertIs(section1, section2)
 
2876
 
2928
2877
    def test_save_emptied_succeeds(self):
2929
2878
        store = self.get_store(self)
2930
2879
        store._load_from_string('foo=bar\n')