~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-02 14:30:23 UTC
  • mto: (6123.1.7 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6124.
  • Revision ID: v.ladeuil+lp@free.fr-20110902143023-61h8n8cm3r96lov9
Disable list_values for config.Store, using a dedicated configobj object to trigger the string -> list conversion on-demand (via the option registration) only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2443
2443
                             from_unicode=config.list_from_store)
2444
2444
 
2445
2445
    def test_convert_invalid(self):
 
2446
        opt = self.get_option()
 
2447
        # We don't even try to convert a list into a list, we only expect
 
2448
        # strings
 
2449
        self.assertConvertInvalid(opt, [1])
2446
2450
        # No string is invalid as all forms can be converted to a list
2447
 
        pass
2448
2451
 
2449
2452
    def test_convert_valid(self):
2450
2453
        opt = self.get_option()
2457
2460
        self.assertConverted([u'42'], opt, u'42')
2458
2461
        # A single string
2459
2462
        self.assertConverted([u'bar'], opt, u'bar')
2460
 
        # A list remains a list (configObj will turn a string containing commas
2461
 
        # into a list, but that's not what we're testing here)
2462
 
        self.assertConverted([u'foo', u'1', u'True'],
2463
 
                             opt, [u'foo', u'1', u'True'])
2464
2463
 
2465
2464
 
2466
2465
class TestOptionRegistry(tests.TestCase):
2869
2868
        sections = list(store.get_sections())
2870
2869
        self.assertLength(4, sections)
2871
2870
        # The default section has no name.
2872
 
        # List values are provided as lists
2873
 
        self.assertSectionContent((None, {'foo': 'bar', 'l': ['1', '2']}),
 
2871
        # List values are provided as strings and need to be explicitly
 
2872
        # converted by specifying from_unicode=list_from_store at option
 
2873
        # registration
 
2874
        self.assertSectionContent((None, {'foo': 'bar', 'l': u'1,2'}),
2874
2875
                                  sections[0])
2875
2876
        self.assertSectionContent(
2876
2877
            ('DEFAULT', {'foo_in_DEFAULT': 'foo_DEFAULT'}), sections[1])
3329
3330
        self.conf.store._load_from_string('foo=m,o,r,e')
3330
3331
        self.assertEquals(['m', 'o', 'r', 'e'], self.conf.get('foo'))
3331
3332
 
 
3333
    def test_get_with_list_converter_embedded_spaces_many_items(self):
 
3334
        self.register_list_option('foo', None)
 
3335
        self.conf.store._load_from_string('foo=" bar", "baz "')
 
3336
        self.assertEquals([' bar', 'baz '], self.conf.get('foo'))
 
3337
 
 
3338
    def test_get_with_list_converter_stripped_spaces_many_items(self):
 
3339
        self.register_list_option('foo', None)
 
3340
        self.conf.store._load_from_string('foo= bar ,  baz ')
 
3341
        self.assertEquals(['bar', 'baz'], self.conf.get('foo'))
 
3342
 
3332
3343
 
3333
3344
class TestStackExpandOptions(tests.TestCaseWithTransport):
3334
3345
 
3413
3424
baz=end
3414
3425
list={foo},{bar},{baz}
3415
3426
''')
 
3427
        self.registry.register(
 
3428
            config.Option('list', from_unicode=config.list_from_store))
3416
3429
        self.assertEquals(['start', 'middle', 'end'],
3417
3430
                           self.conf.get('list', expand=True))
3418
3431
 
3423
3436
baz=end
3424
3437
list={foo}
3425
3438
''')
 
3439
        self.registry.register(
 
3440
            config.Option('list', from_unicode=config.list_from_store))
3426
3441
        self.assertEquals(['start', 'middle', 'end'],
3427
3442
                           self.conf.get('list', expand=True))
3428
3443
 
3435
3450
end=bar}
3436
3451
hidden={start}{middle}{end}
3437
3452
''')
3438
 
        # Nope, it's either a string or a list, and the list wins as soon as a
3439
 
        # ',' appears, so the string concatenation never occur.
3440
 
        self.assertEquals(['{foo', '}', '{', 'bar}'],
 
3453
        # What matters is what the registration says, the conversion happends
 
3454
        # only after all expansions have been performed
 
3455
        self.registry.register(
 
3456
            config.Option('hidden', from_unicode=config.list_from_store))
 
3457
        self.assertEquals(['bin', 'go'],
3441
3458
                          self.conf.get('hidden', expand=True))
3442
3459
 
3443
3460