~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-03-08 03:03:18 UTC
  • mfrom: (1551.2.23 Aaron's small fixes)
  • Revision ID: pqm@pqm.ubuntu.com-20060308030318-87f0fbd9525bb170
A whack of changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
sample_long_alias="log -r-15..-1 --line"
32
32
sample_config_text = ("[DEFAULT]\n"
33
 
                      "email=Robert Collins <robertc@example.com>\n"
 
33
                      u"email=Erik B\u00e5gfors <erik@bagfors.nu>\n"
34
34
                      "editor=vim\n"
35
35
                      "gpg_signing_command=gnome-gpg\n"
36
36
                      "log_format=short\n"
87
87
        self._calls.append(('__getitem__', key))
88
88
        return self
89
89
 
90
 
    def __init__(self, input):
91
 
        self._calls = [('__init__', input)]
 
90
    def __init__(self, input, encoding=None):
 
91
        self._calls = [('__init__', input, encoding)]
92
92
 
93
93
    def __setitem__(self, key, value):
94
94
        self._calls.append(('__setitem__', key, value))
254
254
        my_config = config.IniBasedConfig("nothing")
255
255
 
256
256
    def test_from_fp(self):
257
 
        config_file = StringIO(sample_config_text)
 
257
        config_file = StringIO(sample_config_text.encode('utf-8'))
258
258
        my_config = config.IniBasedConfig(None)
259
259
        self.failUnless(
260
260
            isinstance(my_config._get_parser(file=config_file),
261
261
                        ConfigObj))
262
262
 
263
263
    def test_cached(self):
264
 
        config_file = StringIO(sample_config_text)
 
264
        config_file = StringIO(sample_config_text.encode('utf-8'))
265
265
        my_config = config.IniBasedConfig(None)
266
266
        parser = my_config._get_parser(file=config_file)
267
267
        self.failUnless(my_config._get_parser() is parser)
282
282
        finally:
283
283
            config.ConfigObj = oldparserclass
284
284
        self.failUnless(isinstance(parser, InstrumentedConfigObj))
285
 
        self.assertEqual(parser._calls, [('__init__', config.config_filename())])
 
285
        self.assertEqual(parser._calls, [('__init__', config.config_filename(),
 
286
                                          'utf-8')])
286
287
 
287
288
 
288
289
class TestBranchConfig(TestCaseInTempDir):
303
304
class TestGlobalConfigItems(TestCase):
304
305
 
305
306
    def test_user_id(self):
306
 
        config_file = StringIO(sample_config_text)
 
307
        config_file = StringIO(sample_config_text.encode('utf-8'))
307
308
        my_config = config.GlobalConfig()
308
309
        my_config._parser = my_config._get_parser(file=config_file)
309
 
        self.assertEqual("Robert Collins <robertc@example.com>",
 
310
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
310
311
                         my_config._get_user_id())
311
312
 
312
313
    def test_absent_user_id(self):
316
317
        self.assertEqual(None, my_config._get_user_id())
317
318
 
318
319
    def test_configured_editor(self):
319
 
        config_file = StringIO(sample_config_text)
 
320
        config_file = StringIO(sample_config_text.encode('utf-8'))
320
321
        my_config = config.GlobalConfig()
321
322
        my_config._parser = my_config._get_parser(file=config_file)
322
323
        self.assertEqual("vim", my_config.get_editor())
346
347
        self.assertEqual(False, my_config.signature_needed())
347
348
 
348
349
    def _get_sample_config(self):
349
 
        config_file = StringIO(sample_config_text)
 
350
        config_file = StringIO(sample_config_text.encode('utf-8'))
350
351
        my_config = config.GlobalConfig()
351
352
        my_config._parser = my_config._get_parser(file=config_file)
352
353
        return my_config
546
547
 
547
548
    def get_location_config(self, location, global_config=None):
548
549
        if global_config is None:
549
 
            global_file = StringIO(sample_config_text)
 
550
            global_file = StringIO(sample_config_text.encode('utf-8'))
550
551
        else:
551
 
            global_file = StringIO(global_config)
552
 
        branches_file = StringIO(sample_branches_text)
 
552
            global_file = StringIO(global_config.encode('utf-8'))
 
553
        branches_file = StringIO(sample_branches_text.encode('utf-8'))
553
554
        self.my_config = config.LocationConfig(location)
554
555
        self.my_config._get_parser(branches_file)
555
556
        self.my_config._get_global_config()._get_parser(global_file)
596
597
        branch = FakeBranch()
597
598
        my_config = config.BranchConfig(branch)
598
599
        branch.control_files.email = None
599
 
        config_file = StringIO(sample_config_text)
 
600
        config_file = StringIO(sample_config_text.encode('utf-8'))
600
601
        (my_config._get_location_config().
601
602
            _get_global_config()._get_parser(config_file))
602
 
        self.assertEqual("Robert Collins <robertc@example.com>",
 
603
        self.assertEqual(u"Erik B\u00e5gfors <erik@bagfors.nu>",
603
604
                         my_config._get_user_id())
604
605
        branch.control_files.email = "John"
605
606
        self.assertEqual("John", my_config._get_user_id())
622
623
    def test_gpg_signing_command(self):
623
624
        branch = FakeBranch()
624
625
        my_config = config.BranchConfig(branch)
625
 
        config_file = StringIO(sample_config_text)
 
626
        config_file = StringIO(sample_config_text.encode('utf-8'))
626
627
        (my_config._get_location_config().
627
628
            _get_global_config()._get_parser(config_file))
628
629
        self.assertEqual('gnome-gpg', my_config.gpg_signing_command())
630
631
    def test_get_user_option_global(self):
631
632
        branch = FakeBranch()
632
633
        my_config = config.BranchConfig(branch)
633
 
        config_file = StringIO(sample_config_text)
 
634
        config_file = StringIO(sample_config_text.encode('utf-8'))
634
635
        (my_config._get_location_config().
635
636
            _get_global_config()._get_parser(config_file))
636
637
        self.assertEqual('something',
640
641
        branch = FakeBranch()
641
642
        branch.base='/a/c'
642
643
        my_config = config.BranchConfig(branch)
643
 
        config_file = StringIO(sample_config_text)
 
644
        config_file = StringIO(sample_config_text.encode('utf-8'))
644
645
        (my_config._get_location_config().
645
646
            _get_global_config()._get_parser(config_file))
646
647
        branch_file = StringIO(sample_branches_text)