~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_config.py

  • Committer: Patch Queue Manager
  • Date: 2011-09-08 11:01:15 UTC
  • mfrom: (6123.1.16 gpg-typo)
  • Revision ID: pqm@cupuasso-20110908110115-gbb9benwkdksvzk5
(jelmer) Fix a typo (invalid format identifier) in an error message in
 bzrlib.gpg. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
user_global_option=something
184
184
bzr.mergetool.sometool=sometool {base} {this} {other} -o {result}
185
185
bzr.mergetool.funkytool=funkytool "arg with spaces" {this_temp}
186
 
bzr.mergetool.newtool='"newtool with spaces" {this_temp}'
187
186
bzr.default_mergetool=sometool
188
187
[ALIASES]
189
188
h=help
1340
1339
        self.log(repr(tools))
1341
1340
        self.assertEqual(
1342
1341
            {u'funkytool' : u'funkytool "arg with spaces" {this_temp}',
1343
 
            u'sometool' : u'sometool {base} {this} {other} -o {result}',
1344
 
            u'newtool' : u'"newtool with spaces" {this_temp}'},
 
1342
            u'sometool' : u'sometool {base} {this} {other} -o {result}'},
1345
1343
            tools)
1346
1344
 
1347
1345
    def test_get_merge_tools_empty(self):
2562
2560
 
2563
2561
class TestMutableSection(tests.TestCase):
2564
2562
 
2565
 
    scenarios = [('mutable',
2566
 
                  {'get_section':
2567
 
                       lambda opts: config.MutableSection('myID', opts)},),
2568
 
                 ('cmdline',
2569
 
                  {'get_section':
2570
 
                       lambda opts: config.CommandLineSection(opts)},),
2571
 
        ]
 
2563
    # FIXME: Parametrize so that all sections (including os.environ and the
 
2564
    # ones produced by Stores) run these tests -- vila 2011-04-01
2572
2565
 
2573
2566
    def test_set(self):
2574
2567
        a_dict = dict(foo='bar')
2575
 
        section = self.get_section(a_dict)
 
2568
        section = config.MutableSection('myID', a_dict)
2576
2569
        section.set('foo', 'new_value')
2577
2570
        self.assertEquals('new_value', section.get('foo'))
2578
2571
        # The change appears in the shared section
2583
2576
 
2584
2577
    def test_set_preserve_original_once(self):
2585
2578
        a_dict = dict(foo='bar')
2586
 
        section = self.get_section(a_dict)
 
2579
        section = config.MutableSection('myID', a_dict)
2587
2580
        section.set('foo', 'first_value')
2588
2581
        section.set('foo', 'second_value')
2589
2582
        # We keep track of the original value
2592
2585
 
2593
2586
    def test_remove(self):
2594
2587
        a_dict = dict(foo='bar')
2595
 
        section = self.get_section(a_dict)
 
2588
        section = config.MutableSection('myID', a_dict)
2596
2589
        section.remove('foo')
2597
2590
        # We get None for unknown options via the default value
2598
2591
        self.assertEquals(None, section.get('foo'))
2605
2598
 
2606
2599
    def test_remove_new_option(self):
2607
2600
        a_dict = dict()
2608
 
        section = self.get_section(a_dict)
 
2601
        section = config.MutableSection('myID', a_dict)
2609
2602
        section.set('foo', 'bar')
2610
2603
        section.remove('foo')
2611
2604
        self.assertFalse('foo' in section.options)
2615
2608
        self.assertEquals(config._NewlyCreatedOption, section.orig['foo'])
2616
2609
 
2617
2610
 
2618
 
class TestCommandLineSection(tests.TestCase):
2619
 
 
2620
 
    def setUp(self):
2621
 
        super(TestCommandLineSection, self).setUp()
2622
 
        self.section = config.CommandLineSection()
2623
 
 
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)
2629
 
 
2630
 
    def test_simple_override(self):
2631
 
        self.section._from_cmdline(['a=b'])
2632
 
        self.assertEqual('b', self.section.get('a'))
2633
 
 
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))
2641
 
 
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'))
2646
 
 
2647
 
    def test_wrong_syntax(self):
2648
 
        self.assertRaises(errors.BzrCommandError,
2649
 
                          self.section._from_cmdline, ['a=b', 'c'])
2650
 
 
2651
 
 
2652
2611
class TestStore(tests.TestCaseWithTransport):
2653
2612
 
2654
2613
    def assertSectionContent(self, expected, section):