~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testconfig.py

[merge] robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
sample_config_text = ("[DEFAULT]\n"
32
32
                      "email=Robert Collins <robertc@example.com>\n"
33
33
                      "editor=vim\n"
34
 
                      "gpg_signing_command=gnome-gpg\n")
 
34
                      "gpg_signing_command=gnome-gpg\n"
 
35
                      "user_global_option=something\n")
35
36
 
36
37
 
37
38
sample_always_signatures = ("[DEFAULT]\n"
58
59
                        "[/a/]\n"
59
60
                        "check_signatures=check-available\n"
60
61
                        "gpg_signing_command=false\n"
 
62
                        "user_local_option=local\n"
61
63
                        "# test trailing / matching\n"
62
64
                        "[/a/*]\n"
63
65
                        "#subdirs will match but not the parent\n"
148
150
        my_config = config.Config()
149
151
        self.assertEqual('gpg', my_config.gpg_signing_command())
150
152
 
 
153
    def test_get_user_option_default(self):
 
154
        my_config = config.Config()
 
155
        self.assertEqual(None, my_config.get_user_option('no_option'))
 
156
 
151
157
 
152
158
class TestConfigPath(TestCase):
153
159
 
268
274
                         my_config.signature_checking())
269
275
        self.assertEqual(False, my_config.signature_needed())
270
276
 
 
277
    def _get_sample_config(self):
 
278
        config_file = StringIO(sample_config_text)
 
279
        my_config = config.GlobalConfig()
 
280
        my_config._parser = my_config._get_parser(file=config_file)
 
281
        return my_config
 
282
 
271
283
    def test_gpg_signing_command(self):
272
 
        config_file = StringIO(sample_config_text)
273
 
        my_config = config.GlobalConfig()
274
 
        my_config._parser = my_config._get_parser(file=config_file)
 
284
        my_config = self._get_sample_config()
275
285
        self.assertEqual("gnome-gpg", my_config.gpg_signing_command())
276
286
        self.assertEqual(False, my_config.signature_needed())
277
287
 
 
288
    def _get_empty_config(self):
 
289
        config_file = StringIO("")
 
290
        my_config = config.GlobalConfig()
 
291
        my_config._parser = my_config._get_parser(file=config_file)
 
292
        return my_config
 
293
 
278
294
    def test_gpg_signing_command_unset(self):
279
 
        config_file = StringIO("")
280
 
        my_config = config.GlobalConfig()
281
 
        my_config._parser = my_config._get_parser(file=config_file)
 
295
        my_config = self._get_empty_config()
282
296
        self.assertEqual("gpg", my_config.gpg_signing_command())
283
297
 
 
298
    def test_get_user_option_default(self):
 
299
        my_config = self._get_empty_config()
 
300
        self.assertEqual(None, my_config.get_user_option('no_option'))
 
301
 
 
302
    def test_get_user_option_global(self):
 
303
        my_config = self._get_sample_config()
 
304
        self.assertEqual("something",
 
305
                         my_config.get_user_option('user_global_option'))
 
306
 
284
307
 
285
308
class TestLocationConfig(TestCase):
286
309
 
409
432
        self.get_location_config('/a')
410
433
        self.assertEqual("false", self.my_config.gpg_signing_command())
411
434
 
 
435
    def test_get_user_option_global(self):
 
436
        self.get_location_config('/a')
 
437
        self.assertEqual('something',
 
438
                         self.my_config.get_user_option('user_global_option'))
 
439
 
 
440
    def test_get_user_option_local(self):
 
441
        self.get_location_config('/a')
 
442
        self.assertEqual('local',
 
443
                         self.my_config.get_user_option('user_local_option'))
 
444
 
412
445
 
413
446
class TestBranchConfigItems(TestCase):
414
447
 
454
487
        (my_config._get_location_config().
455
488
            _get_global_config()._get_parser(config_file))
456
489
        self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
 
490
 
 
491
    def test_get_user_option_global(self):
 
492
        branch = FakeBranch()
 
493
        my_config = config.BranchConfig(branch)
 
494
        config_file = StringIO(sample_config_text)
 
495
        (my_config._get_location_config().
 
496
            _get_global_config()._get_parser(config_file))
 
497
        self.assertEqual('something',
 
498
                         my_config.get_user_option('user_global_option'))