~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-12 09:49:24 UTC
  • mfrom: (6015.9.10 2.4)
  • mto: This revision was merged to the branch mainline in revision 6066.
  • Revision ID: v.ladeuil+lp@free.fr-20110812094924-knc5s0g7vs31a2f1
Merge 2.4 into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
editor=vim
161
161
change_editor=vimdiff -of @new_path @old_path
162
162
gpg_signing_command=gnome-gpg
 
163
gpg_signing_key=DD4D5088
163
164
log_format=short
164
165
validate_signatures_in_log=true
165
166
acceptable_keys=amy
214
215
[/a/]
215
216
check_signatures=check-available
216
217
gpg_signing_command=false
 
218
gpg_signing_key=default
217
219
user_local_option=local
218
220
# test trailing / matching
219
221
[/a/*]
1225
1227
        self.assertEqual("gnome-gpg", my_config.gpg_signing_command())
1226
1228
        self.assertEqual(False, my_config.signature_needed())
1227
1229
 
 
1230
    def test_gpg_signing_key(self):
 
1231
        my_config = self._get_sample_config()
 
1232
        self.assertEqual("DD4D5088", my_config.gpg_signing_key())
 
1233
 
1228
1234
    def _get_empty_config(self):
1229
1235
        my_config = config.GlobalConfig()
1230
1236
        return my_config
1520
1526
        self.get_branch_config('/a')
1521
1527
        self.assertEqual("false", self.my_config.gpg_signing_command())
1522
1528
 
 
1529
    def test_gpg_signing_key(self):
 
1530
        self.get_branch_config('/b')
 
1531
        self.assertEqual("DD4D5088", self.my_config.gpg_signing_key())
 
1532
 
 
1533
    def test_gpg_signing_key_default(self):
 
1534
        self.get_branch_config('/a')
 
1535
        self.assertEqual("erik@bagfors.nu", self.my_config.gpg_signing_key())
 
1536
 
1523
1537
    def test_get_user_option_global(self):
1524
1538
        self.get_branch_config('/a')
1525
1539
        self.assertEqual('something',
2205
2219
    def setUp(self):
2206
2220
        super(TestOptionRegistry, self).setUp()
2207
2221
        # Always start with an empty registry
2208
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2222
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
2209
2223
        self.registry = config.option_registry
2210
2224
 
2211
2225
    def test_register(self):
2212
2226
        opt = config.Option('foo')
2213
 
        self.registry.register('foo', opt)
 
2227
        self.registry.register(opt)
2214
2228
        self.assertIs(opt, self.registry.get('foo'))
2215
2229
 
2216
 
    lazy_option = config.Option('lazy_foo')
2217
 
 
2218
 
    def test_register_lazy(self):
2219
 
        self.registry.register_lazy('foo', self.__module__,
2220
 
                                    'TestOptionRegistry.lazy_option')
2221
 
        self.assertIs(self.lazy_option, self.registry.get('foo'))
2222
 
 
2223
2230
    def test_registered_help(self):
2224
 
        opt = config.Option('foo')
2225
 
        self.registry.register('foo', opt, help='A simple option')
 
2231
        opt = config.Option('foo', help='A simple option')
 
2232
        self.registry.register(opt)
2226
2233
        self.assertEquals('A simple option', self.registry.get_help('foo'))
2227
2234
 
 
2235
    lazy_option = config.Option('lazy_foo', help='Lazy help')
 
2236
 
 
2237
    def test_register_lazy(self):
 
2238
        self.registry.register_lazy('lazy_foo', self.__module__,
 
2239
                                    'TestOptionRegistry.lazy_option')
 
2240
        self.assertIs(self.lazy_option, self.registry.get('lazy_foo'))
 
2241
 
 
2242
    def test_registered_lazy_help(self):
 
2243
        self.registry.register_lazy('lazy_foo', self.__module__,
 
2244
                                    'TestOptionRegistry.lazy_option')
 
2245
        self.assertEquals('Lazy help', self.registry.get_help('lazy_foo'))
 
2246
 
2228
2247
 
2229
2248
class TestRegisteredOptions(tests.TestCase):
2230
2249
    """All registered options should verify some constraints."""
2244
2263
    def test_help_is_set(self):
2245
2264
        option_help = self.registry.get_help(self.option_name)
2246
2265
        self.assertNotEquals(None, option_help)
2247
 
        # Come on, think about the user, he really wants to know whst the
 
2266
        # Come on, think about the user, he really wants to know what the
2248
2267
        # option is about
 
2268
        self.assertIsNot(None, option_help)
2249
2269
        self.assertNotEquals('', option_help)
2250
2270
 
2251
2271
 
2852
2872
    # FIXME: This should be parametrized for all known Stack or dedicated
2853
2873
    # paramerized tests created to avoid bloating -- vila 2011-03-31
2854
2874
 
 
2875
    def overrideOptionRegistry(self):
 
2876
        self.overrideAttr(config, 'option_registry', config.OptionRegistry())
 
2877
 
2855
2878
    def test_single_config_get(self):
2856
2879
        conf = dict(foo='bar')
2857
2880
        conf_stack = config.Stack([conf])
2860
2883
    def test_get_with_registered_default_value(self):
2861
2884
        conf_stack = config.Stack([dict()])
2862
2885
        opt = config.Option('foo', default='bar')
2863
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2886
        self.overrideOptionRegistry()
2864
2887
        config.option_registry.register('foo', opt)
2865
2888
        self.assertEquals('bar', conf_stack.get('foo'))
2866
2889
 
2867
2890
    def test_get_without_registered_default_value(self):
2868
2891
        conf_stack = config.Stack([dict()])
2869
2892
        opt = config.Option('foo')
2870
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2893
        self.overrideOptionRegistry()
2871
2894
        config.option_registry.register('foo', opt)
2872
2895
        self.assertEquals(None, conf_stack.get('foo'))
2873
2896
 
2874
2897
    def test_get_without_default_value_for_not_registered(self):
2875
2898
        conf_stack = config.Stack([dict()])
2876
2899
        opt = config.Option('foo')
2877
 
        self.overrideAttr(config, 'option_registry', registry.Registry())
 
2900
        self.overrideOptionRegistry()
2878
2901
        self.assertEquals(None, conf_stack.get('foo'))
2879
2902
 
2880
2903
    def test_get_first_definition(self):