395
395
class TestIniConfig(tests.TestCaseInTempDir):
397
397
def make_config_parser(self, s):
398
conf = config.IniBasedConfig(_content=s)
398
conf = config.IniBasedConfig.from_bytes(s)
399
399
return conf, conf._get_parser()
405
405
my_config = config.IniBasedConfig()
407
407
def test_from_fp(self):
408
my_config = config.IniBasedConfig(_content=sample_config_text)
408
my_config = config.IniBasedConfig.from_bytes(sample_config_text)
409
409
self.assertIsInstance(my_config._get_parser(), configobj.ConfigObj)
411
411
def test_cached(self):
412
my_config = config.IniBasedConfig(_content=sample_config_text)
412
my_config = config.IniBasedConfig.from_bytes(sample_config_text)
413
413
parser = my_config._get_parser()
414
414
self.failUnless(my_config._get_parser() is parser)
437
437
def test_get_parser_file_parameter_is_deprecated_(self):
438
438
config_file = StringIO(sample_config_text.encode('utf-8'))
439
conf = config.IniBasedConfig(_content=sample_config_text)
439
conf = config.IniBasedConfig.from_bytes(sample_config_text)
440
440
conf = self.callDeprecated([
441
441
'IniBasedConfig._get_parser(file=xxx) was deprecated in 2.3.'
442
442
' Use IniBasedConfig(_content=xxx) instead.'],
451
451
def test_saved_with_content(self):
452
452
content = 'foo = bar\n'
453
conf = config.IniBasedConfig(file_name='./test.conf',
454
_content=content,_save=True)
453
conf = config.IniBasedConfig.from_bytes(
454
content, file_name='./test.conf', save=True)
455
455
self.assertFileEqual(content, 'test.conf')
458
458
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
460
460
def test_cannot_reload_without_name(self):
461
conf = config.IniBasedConfig(_content=sample_config_text)
461
conf = config.IniBasedConfig.from_bytes(sample_config_text)
462
462
self.assertRaises(AssertionError, conf.reload)
464
464
def test_reload_see_new_value(self):
465
c1 = config.IniBasedConfig(file_name='./test/conf',
466
_content='editor=vim\n')
465
c1 = config.IniBasedConfig.from_bytes('editor=vim\n',
466
file_name='./test/conf')
467
467
c1._write_config_file()
468
c2 = config.IniBasedConfig(file_name='./test/conf',
469
_content='editor=emacs\n')
468
c2 = config.IniBasedConfig.from_bytes('editor=emacs\n',
469
file_name='./test/conf')
470
470
c2._write_config_file()
471
471
self.assertEqual('vim', c1.get_user_option('editor'))
472
472
self.assertEqual('emacs', c2.get_user_option('editor'))
491
491
return self.config_class(*self.config_args)
493
493
def create_config(self, content):
494
c = self.config_class(*self.config_args, _content=content, _save=True)
494
c = self.config_class.from_bytes(content, *self.config_args, save=True)
497
497
def test_simple_read_access(self):
711
711
self.assertEqual('branch', branch.nick)
713
713
local_url = urlutils.local_path_to_url('branch')
714
conf = config.LocationConfig(
715
local_url, _save=True,
716
_content=('[%s]\nnickname = foobar' % (local_url,)))
714
conf = config.LocationConfig.from_bytes(
715
'[%s]\nnickname = foobar' % (local_url,),
716
local_url, save=True)
717
717
self.assertEqual('foobar', branch.nick)
719
719
def test_config_local_path(self):
722
722
self.assertEqual('branch', branch.nick)
724
724
local_path = osutils.getcwd().encode('utf8')
725
conf = config.LocationConfig(
726
'branch', _save=True,
727
_content='[%s/branch]\nnickname = barry' % (local_path,))
725
conf = config.LocationConfig.from_bytes(
726
'[%s/branch]\nnickname = barry' % (local_path,),
728
728
self.assertEqual('barry', branch.nick)
730
730
def test_config_creates_local(self):
780
780
class TestGlobalConfigItems(tests.TestCase):
782
782
def test_user_id(self):
783
my_config = config.GlobalConfig(_content=sample_config_text)
783
my_config = config.GlobalConfig.from_bytes(sample_config_text)
784
784
self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
785
785
my_config._get_user_id())
789
789
self.assertEqual(None, my_config._get_user_id())
791
791
def test_configured_editor(self):
792
my_config = config.GlobalConfig(_content=sample_config_text)
792
my_config = config.GlobalConfig.from_bytes(sample_config_text)
793
793
self.assertEqual("vim", my_config.get_editor())
795
795
def test_signatures_always(self):
796
my_config = config.GlobalConfig(_content=sample_always_signatures)
796
my_config = config.GlobalConfig.from_bytes(sample_always_signatures)
797
797
self.assertEqual(config.CHECK_NEVER,
798
798
my_config.signature_checking())
799
799
self.assertEqual(config.SIGN_ALWAYS,
801
801
self.assertEqual(True, my_config.signature_needed())
803
803
def test_signatures_if_possible(self):
804
my_config = config.GlobalConfig(_content=sample_maybe_signatures)
804
my_config = config.GlobalConfig.from_bytes(sample_maybe_signatures)
805
805
self.assertEqual(config.CHECK_NEVER,
806
806
my_config.signature_checking())
807
807
self.assertEqual(config.SIGN_WHEN_REQUIRED,
809
809
self.assertEqual(False, my_config.signature_needed())
811
811
def test_signatures_ignore(self):
812
my_config = config.GlobalConfig(_content=sample_ignore_signatures)
812
my_config = config.GlobalConfig.from_bytes(sample_ignore_signatures)
813
813
self.assertEqual(config.CHECK_ALWAYS,
814
814
my_config.signature_checking())
815
815
self.assertEqual(config.SIGN_NEVER,
817
817
self.assertEqual(False, my_config.signature_needed())
819
819
def _get_sample_config(self):
820
my_config = config.GlobalConfig(_content=sample_config_text)
820
my_config = config.GlobalConfig.from_bytes(sample_config_text)
823
823
def test_gpg_signing_command(self):
1165
1165
if global_config is None:
1166
1166
global_config = sample_config_text
1168
my_global_config = config.GlobalConfig(_content=global_config,
1170
my_location_config = config.LocationConfig(
1171
my_branch.base, _content=sample_branches_text, _save=True)
1168
my_global_config = config.GlobalConfig.from_bytes(global_config,
1170
my_location_config = config.LocationConfig.from_bytes(
1171
sample_branches_text, my_branch.base, save=True)
1172
1172
my_config = config.BranchConfig(my_branch)
1173
1173
self.my_config = my_config
1174
1174
self.my_location_config = my_config._get_location_config()
1239
1239
location_config=None, branch_data_config=None):
1240
1240
my_branch = FakeBranch(location)
1241
1241
if global_config is not None:
1242
my_global_config = config.GlobalConfig(_content=global_config,
1242
my_global_config = config.GlobalConfig.from_bytes(global_config,
1244
1244
if location_config is not None:
1245
my_location_config = config.LocationConfig(my_branch.base,
1246
_content=location_config,
1245
my_location_config = config.LocationConfig.from_bytes(
1246
location_config, my_branch.base, save=True)
1248
1247
my_config = config.BranchConfig(my_branch)
1249
1248
if branch_data_config is not None:
1250
1249
my_config.branch.control_files.files['branch.conf'] = \