31
31
sample_config_text = ("[DEFAULT]\n"
32
32
"email=Robert Collins <robertc@example.com>\n"
34
"gpg_signing_command=gnome-gpg\n")
34
"gpg_signing_command=gnome-gpg\n"
35
"user_global_option=something\n")
37
38
sample_always_signatures = ("[DEFAULT]\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"
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())
153
def test_get_user_option_default(self):
154
my_config = config.Config()
155
self.assertEqual(None, my_config.get_user_option('no_option'))
152
158
class TestConfigPath(TestCase):
268
274
my_config.signature_checking())
269
275
self.assertEqual(False, my_config.signature_needed())
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)
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())
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)
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())
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'))
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'))
285
308
class TestLocationConfig(TestCase):
409
432
self.get_location_config('/a')
410
433
self.assertEqual("false", self.my_config.gpg_signing_command())
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'))
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'))
413
446
class TestBranchConfigItems(TestCase):
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())
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'))