2615
2612
self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2618
class TestCommandLineSection(tests.TestCase):
2615
class TestCommandLineStore(tests.TestCase):
2620
2617
def setUp(self):
2621
super(TestCommandLineSection, self).setUp()
2622
self.section = config.CommandLineSection()
2618
super(TestCommandLineStore, self).setUp()
2619
self.store = config.CommandLineStore()
2621
def get_section(self):
2622
"""Get the unique section for the command line overrides."""
2623
sections = list(self.store.get_sections())
2624
self.assertLength(1, sections)
2625
store, section = sections[0]
2626
self.assertEquals(self.store, store)
2624
2629
def test_no_override(self):
2625
self.section._from_cmdline([])
2626
# FIXME: we want some iterator over all options, failing that, we peek
2627
# under the cover -- vila 2011-09026
2628
self.assertLength(0, self.section.options)
2630
self.store._from_cmdline([])
2631
section = self.get_section()
2632
self.assertLength(0, list(section.iter_option_names()))
2630
2634
def test_simple_override(self):
2631
self.section._from_cmdline(['a=b'])
2632
self.assertEqual('b', self.section.get('a'))
2635
self.store._from_cmdline(['a=b'])
2636
section = self.get_section()
2637
self.assertEqual('b', section.get('a'))
2634
2639
def test_list_override(self):
2635
self.section._from_cmdline(['l=1,2,3'])
2636
val = self.section.get('l')
2640
self.store._from_cmdline(['l=1,2,3'])
2641
val = self.get_section().get('l')
2637
2642
self.assertEqual('1,2,3', val)
2638
# Reminder: lists should registered as such explicitely, otherwise the
2639
# conversion needs to be done afterwards.
2643
# Reminder: lists should be registered as such explicitely, otherwise
2644
# the conversion needs to be done afterwards.
2640
2645
self.assertEqual(['1', '2', '3'], config.list_from_store(val))
2642
2647
def test_multiple_overrides(self):
2643
self.section._from_cmdline(['a=b', 'x=y'])
2644
self.assertEquals('b', self.section.get('a'))
2645
self.assertEquals('y', self.section.get('x'))
2648
self.store._from_cmdline(['a=b', 'x=y'])
2649
section = self.get_section()
2650
self.assertEquals('b', section.get('a'))
2651
self.assertEquals('y', section.get('x'))
2647
2653
def test_wrong_syntax(self):
2648
2654
self.assertRaises(errors.BzrCommandError,
2649
self.section._from_cmdline, ['a=b', 'c'])
2655
self.store._from_cmdline, ['a=b', 'c'])
2652
2658
class TestStore(tests.TestCaseWithTransport):
2654
def assertSectionContent(self, expected, section):
2660
def assertSectionContent(self, expected, (store, section)):
2655
2661
"""Assert that some options have the proper values in a section."""
2656
2662
expected_name, expected_options = expected
2657
2663
self.assertEquals(expected_name, section.id)
3171
3177
self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
3173
[section.id for section in store.get_sections()])
3179
[section.id for _, section in store.get_sections()])
3174
3180
matcher = config.LocationMatcher(store, '/foo/bar/quux')
3175
sections = list(matcher.get_sections())
3181
sections = [section for s, section in matcher.get_sections()]
3176
3182
self.assertEquals([3, 2],
3177
3183
[section.length for section in sections])
3178
3184
self.assertEquals(['/foo/bar', '/foo'],
3189
3195
section=/foo/bar
3191
3197
self.assertEquals(['/foo', '/foo/bar'],
3192
[section.id for section in store.get_sections()])
3198
[section.id for _, section in store.get_sections()])
3193
3199
matcher = config.LocationMatcher(store, '/foo/bar/baz')
3194
sections = list(matcher.get_sections())
3200
sections = [section for s, section in matcher.get_sections()]
3195
3201
self.assertEquals([3, 2],
3196
3202
[section.length for section in sections])
3197
3203
self.assertEquals(['/foo/bar', '/foo'],
3345
3351
self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
3348
class TestStackGetWithConverter(TestStackGet):
3354
class TestStackGetWithConverter(tests.TestCaseWithTransport):
3350
3356
def setUp(self):
3351
3357
super(TestStackGetWithConverter, self).setUp()
3352
3358
self.overrideAttr(config, 'option_registry', config.OptionRegistry())
3353
3359
self.registry = config.option_registry
3360
# We just want a simple stack with a simple store so we can inject
3361
# whatever content the tests need without caring about what section
3362
# names are valid for a given store/stack.
3363
store = config.IniFileStore(self.get_transport(), 'foo.conf')
3364
self.conf = config.Stack([store.get_sections], store)
3355
3366
def register_bool_option(self, name, default=None, default_from_env=None):
3356
3367
b = config.Option(name, help='A boolean.',