~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

Move the '_save' parameter from '__init__' to 'from_bytes', fix fallouts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
395
395
class TestIniConfig(tests.TestCaseInTempDir):
396
396
 
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()
400
400
 
401
401
 
405
405
        my_config = config.IniBasedConfig()
406
406
 
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)
410
410
 
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)
415
415
 
436
436
 
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.'],
450
450
 
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')
456
456
 
457
457
 
458
458
class TestIniBaseConfigOnDisk(tests.TestCaseInTempDir):
459
459
 
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)
463
463
 
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)
492
492
 
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)
495
495
        return c
496
496
 
497
497
    def test_simple_read_access(self):
711
711
        self.assertEqual('branch', branch.nick)
712
712
 
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)
718
718
 
719
719
    def test_config_local_path(self):
722
722
        self.assertEqual('branch', branch.nick)
723
723
 
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,),
 
727
            'branch',  save=True)
728
728
        self.assertEqual('barry', branch.nick)
729
729
 
730
730
    def test_config_creates_local(self):
780
780
class TestGlobalConfigItems(tests.TestCase):
781
781
 
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())
786
786
 
789
789
        self.assertEqual(None, my_config._get_user_id())
790
790
 
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())
794
794
 
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())
802
802
 
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())
810
810
 
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())
818
818
 
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)
821
821
        return my_config
822
822
 
823
823
    def test_gpg_signing_command(self):
1165
1165
        if global_config is None:
1166
1166
            global_config = sample_config_text
1167
1167
 
1168
 
        my_global_config = config.GlobalConfig(_content=global_config,
1169
 
                                               _save=True)
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,
 
1169
                                                          save=True)
 
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,
1243
 
                                                   _save=True)
 
1242
            my_global_config = config.GlobalConfig.from_bytes(global_config,
 
1243
                                                              save=True)
1244
1244
        if location_config is not None:
1245
 
            my_location_config = config.LocationConfig(my_branch.base,
1246
 
                                                       _content=location_config,
1247
 
                                                       _save=True)
 
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'] = \