Rev 2563: [merge] James Westby's Fix for TreeConfig returning values from subsections. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration

John Arbash Meinel john at arbash-meinel.com
Thu Jun 28 23:18:53 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/jam-integration

------------------------------------------------------------
revno: 2563
revision-id: john at arbash-meinel.com-20070628221841-8vu77dl0wytbccyf
parent: pqm at pqm.ubuntu.com-20070628194410-pikmj08nsn9sci9h
parent: jw+debian at jameswestby.net-20070618203906-atz57382qnf4sdc0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Thu 2007-06-28 17:18:41 -0500
message:
  [merge] James Westby's Fix for TreeConfig returning values from subsections.
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
    ------------------------------------------------------------
    revno: 2533.1.1
    revision-id: jw+debian at jameswestby.net-20070618203906-atz57382qnf4sdc0
    parent: pqm at pqm.ubuntu.com-20070618142445-94nnc2l4o1yy6x8l
    committer: James Westby <jw+debian at jameswestby.net>
    branch nick: bzr.dev
    timestamp: Mon 2007-06-18 21:39:06 +0100
    message:
      Fix TreeConfig to return values from sections.
      
        * TreeConfig would mistakenly search the top level when asked for options
          from a section. This patch makes it respect the section argument and only
          search the specified section.
        * It also adds some more tests, explicity testing the behavior for
          both keys that are present and absent in both sections and the top level,
          keys that are present in both, default values, and missing sections.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2007-04-05 09:35:26 +0000
+++ b/bzrlib/config.py	2007-06-18 20:39:06 +0000
@@ -852,7 +852,7 @@
             obj = self._get_config()
             try:
                 if section is not None:
-                    obj[section]
+                    obj = obj[section]
                 result = obj[name]
             except KeyError:
                 result = default

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2007-03-05 14:34:28 +0000
+++ b/bzrlib/tests/test_config.py	2007-06-18 20:39:06 +0000
@@ -976,3 +976,31 @@
                          config.extract_email_address('Jane <jane at test.com>'))
         self.assertRaises(errors.NoEmailInUsername,
                           config.extract_email_address, 'Jane Tester')
+
+class TestTreeConfig(TestCaseWithTransport):
+
+    def test_get_value(self):
+        """Test that retreiving a value from a section is possible"""
+        branch = self.make_branch('.')
+        tree_config = config.TreeConfig(branch)
+        tree_config.set_option('value', 'key', 'SECTION')
+        tree_config.set_option('value2', 'key2')
+        tree_config.set_option('value3-top', 'key3')
+        tree_config.set_option('value3-section', 'key3', 'SECTION')
+        value = tree_config.get_option('key', 'SECTION')
+        self.assertEqual(value, 'value')
+        value = tree_config.get_option('key2')
+        self.assertEqual(value, 'value2')
+        self.assertEqual(tree_config.get_option('non-existant'), None)
+        value = tree_config.get_option('non-existant', 'SECTION')
+        self.assertEqual(value, None)
+        value = tree_config.get_option('non-existant', default='default')
+        self.assertEqual(value, 'default')
+        self.assertEqual(tree_config.get_option('key2', 'NOSECTION'), None)
+        value = tree_config.get_option('key2', 'NOSECTION', default='default')
+        self.assertEqual(value, 'default')
+        value = tree_config.get_option('key3')
+        self.assertEqual(value, 'value3-top')
+        value = tree_config.get_option('key3', 'SECTION')
+        self.assertEqual(value, 'value3-section')
+



More information about the bazaar-commits mailing list