2563
2563
class TestMutableSection(tests.TestCase):
2565
# FIXME: Parametrize so that all sections (including os.environ and the
2566
# ones produced by Stores) run these tests -- vila 2011-04-01
2565
scenarios = [('mutable',
2567
lambda opts: config.MutableSection('myID', opts)},),
2570
lambda opts: config.CommandLineSection(opts)},),
2568
2573
def test_set(self):
2569
2574
a_dict = dict(foo='bar')
2570
section = config.MutableSection('myID', a_dict)
2575
section = self.get_section(a_dict)
2571
2576
section.set('foo', 'new_value')
2572
2577
self.assertEquals('new_value', section.get('foo'))
2573
2578
# The change appears in the shared section
2579
2584
def test_set_preserve_original_once(self):
2580
2585
a_dict = dict(foo='bar')
2581
section = config.MutableSection('myID', a_dict)
2586
section = self.get_section(a_dict)
2582
2587
section.set('foo', 'first_value')
2583
2588
section.set('foo', 'second_value')
2584
2589
# We keep track of the original value
2588
2593
def test_remove(self):
2589
2594
a_dict = dict(foo='bar')
2590
section = config.MutableSection('myID', a_dict)
2595
section = self.get_section(a_dict)
2591
2596
section.remove('foo')
2592
2597
# We get None for unknown options via the default value
2593
2598
self.assertEquals(None, section.get('foo'))
2601
2606
def test_remove_new_option(self):
2602
2607
a_dict = dict()
2603
section = config.MutableSection('myID', a_dict)
2608
section = self.get_section(a_dict)
2604
2609
section.set('foo', 'bar')
2605
2610
section.remove('foo')
2606
2611
self.assertFalse('foo' in section.options)
2610
2615
self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2618
class TestCommandLineSection(tests.TestCase):
2621
super(TestCommandLineSection, self).setUp()
2622
self.section = config.CommandLineSection()
2624
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
def test_simple_override(self):
2631
self.section._from_cmdline(['a=b'])
2632
self.assertEqual('b', self.section.get('a'))
2634
def test_list_override(self):
2635
self.section._from_cmdline(['l=1,2,3'])
2636
val = self.section.get('l')
2637
self.assertEqual('1,2,3', val)
2638
# Reminder: lists should registered as such explicitely, otherwise the
2639
# conversion needs to be done afterwards.
2640
self.assertEqual(['1', '2', '3'], config.list_from_store(val))
2642
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'))
2647
def test_wrong_syntax(self):
2648
self.assertRaises(errors.BzrCommandError,
2649
self.section._from_cmdline, ['a=b', 'c'])
2613
2652
class TestStore(tests.TestCaseWithTransport):
2615
2654
def assertSectionContent(self, expected, section):