~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Jonathan Riddell
  • Date: 2011-09-07 14:38:26 UTC
  • mfrom: (6123.1.10 +trunk)
  • mto: (6123.1.14 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6124.
  • Revision ID: jriddell@canonical.com-20110907143826-aewhasbrhsq8khyp
mergeĀ inĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2462
2462
                             from_unicode=config.list_from_store)
2463
2463
 
2464
2464
    def test_convert_invalid(self):
 
2465
        opt = self.get_option()
 
2466
        # We don't even try to convert a list into a list, we only expect
 
2467
        # strings
 
2468
        self.assertConvertInvalid(opt, [1])
2465
2469
        # No string is invalid as all forms can be converted to a list
2466
 
        pass
2467
2470
 
2468
2471
    def test_convert_valid(self):
2469
2472
        opt = self.get_option()
2476
2479
        self.assertConverted([u'42'], opt, u'42')
2477
2480
        # A single string
2478
2481
        self.assertConverted([u'bar'], opt, u'bar')
2479
 
        # A list remains a list (configObj will turn a string containing commas
2480
 
        # into a list, but that's not what we're testing here)
2481
 
        self.assertConverted([u'foo', u'1', u'True'],
2482
 
                             opt, [u'foo', u'1', u'True'])
2483
2482
 
2484
2483
 
2485
2484
class TestOptionRegistry(tests.TestCase):
2660
2659
 
2661
2660
 
2662
2661
class TestIniFileStoreContent(tests.TestCaseWithTransport):
2663
 
    """Simulate loading a config store without content of various encodings.
 
2662
    """Simulate loading a config store with content of various encodings.
2664
2663
 
2665
2664
    All files produced by bzr are in utf8 content.
2666
2665
 
2719
2718
 
2720
2719
 
2721
2720
class TestIniConfigContent(tests.TestCaseWithTransport):
2722
 
    """Simulate loading a IniBasedConfig without content of various encodings.
 
2721
    """Simulate loading a IniBasedConfig with content of various encodings.
2723
2722
 
2724
2723
    All files produced by bzr are in utf8 content.
2725
2724
 
2907
2906
        sections = list(store.get_sections())
2908
2907
        self.assertLength(4, sections)
2909
2908
        # The default section has no name.
2910
 
        # List values are provided as lists
2911
 
        self.assertSectionContent((None, {'foo': 'bar', 'l': ['1', '2']}),
 
2909
        # List values are provided as strings and need to be explicitly
 
2910
        # converted by specifying from_unicode=list_from_store at option
 
2911
        # registration
 
2912
        self.assertSectionContent((None, {'foo': 'bar', 'l': u'1,2'}),
2912
2913
                                  sections[0])
2913
2914
        self.assertSectionContent(
2914
2915
            ('DEFAULT', {'foo_in_DEFAULT': 'foo_DEFAULT'}), sections[1])
3367
3368
        self.conf.store._load_from_string('foo=m,o,r,e')
3368
3369
        self.assertEquals(['m', 'o', 'r', 'e'], self.conf.get('foo'))
3369
3370
 
 
3371
    def test_get_with_list_converter_embedded_spaces_many_items(self):
 
3372
        self.register_list_option('foo', None)
 
3373
        self.conf.store._load_from_string('foo=" bar", "baz "')
 
3374
        self.assertEquals([' bar', 'baz '], self.conf.get('foo'))
 
3375
 
 
3376
    def test_get_with_list_converter_stripped_spaces_many_items(self):
 
3377
        self.register_list_option('foo', None)
 
3378
        self.conf.store._load_from_string('foo= bar ,  baz ')
 
3379
        self.assertEquals(['bar', 'baz'], self.conf.get('foo'))
 
3380
 
3370
3381
 
3371
3382
class TestStackExpandOptions(tests.TestCaseWithTransport):
3372
3383
 
3451
3462
baz=end
3452
3463
list={foo},{bar},{baz}
3453
3464
''')
 
3465
        self.registry.register(
 
3466
            config.Option('list', from_unicode=config.list_from_store))
3454
3467
        self.assertEquals(['start', 'middle', 'end'],
3455
3468
                           self.conf.get('list', expand=True))
3456
3469
 
3461
3474
baz=end
3462
3475
list={foo}
3463
3476
''')
 
3477
        self.registry.register(
 
3478
            config.Option('list', from_unicode=config.list_from_store))
3464
3479
        self.assertEquals(['start', 'middle', 'end'],
3465
3480
                           self.conf.get('list', expand=True))
3466
3481
 
3473
3488
end=bar}
3474
3489
hidden={start}{middle}{end}
3475
3490
''')
3476
 
        # Nope, it's either a string or a list, and the list wins as soon as a
3477
 
        # ',' appears, so the string concatenation never occur.
3478
 
        self.assertEquals(['{foo', '}', '{', 'bar}'],
 
3491
        # What matters is what the registration says, the conversion happens
 
3492
        # only after all expansions have been performed
 
3493
        self.registry.register(
 
3494
            config.Option('hidden', from_unicode=config.list_from_store))
 
3495
        self.assertEquals(['bin', 'go'],
3479
3496
                          self.conf.get('hidden', expand=True))
3480
3497
 
3481
3498