Rev 5745: Add tests for remove. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Apr 1 10:56:01 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5745
revision-id: v.ladeuil+lp at free.fr-20110401105601-b8bkyiz4q2jdybme
parent: v.ladeuil+lp at free.fr-20110401095926-okln8han4c4l7prr
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-section
timestamp: Fri 2011-04-01 12:56:01 +0200
message:
  Add tests for remove.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-01 09:59:26 +0000
+++ b/bzrlib/config.py	2011-04-01 10:56:01 +0000
@@ -2006,6 +2006,8 @@
     def get(self, name, default=None):
         return self.options.get(name, default)
 
+_Created = object()
+"""Was the option created during the MutableSection lifetime"""
 
 class MutableSection(ReadOnlySection):
 
@@ -2014,6 +2016,8 @@
         self.orig = {}
 
     def set(self, name, value):
+        if name not in self.options:
+            self.orig[name] = _Created
         if name not in self.orig:
             self.orig[name] = self.get(name, None)
         self.options[name] = value

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-01 09:59:26 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-01 10:56:01 +0000
@@ -1827,6 +1827,12 @@
         section = config.ReadOnlySection('myID', a_dict)
         self.assertEquals('bar', section.get('foo'))
 
+    def test_get_unkown_option(self):
+        a_dict = dict()
+        section = config.ReadOnlySection('myID', a_dict)
+        self.assertEquals('out of thin air',
+                          section.get('foo', 'out of thin air'))
+
     def test_options_is_shared(self):
         a_dict = dict()
         section = config.ReadOnlySection('myID', a_dict)
@@ -1858,6 +1864,30 @@
         self.assertTrue('foo' in section.orig)
         self.assertEquals('bar', section.orig.get('foo'))
 
+    def test_remove(self):
+        a_dict = dict(foo='bar')
+        section = config.MutableSection('myID', a_dict)
+        section.remove('foo')
+        # We get None for unknown options via the default value
+        self.assertEquals(None, section.get('foo'))
+        # Or we just get the default value
+        self.assertEquals('unknown', section.get('foo', 'unknown'))
+        self.assertFalse('foo' in section.options)
+        # We keep track of the deletion
+        self.assertTrue('foo' in section.orig)
+        self.assertEquals('bar', section.orig.get('foo'))
+
+    def test_remove_new_option(self):
+        a_dict = dict()
+        section = config.MutableSection('myID', a_dict)
+        section.set('foo', 'bar')
+        section.remove('foo')
+        self.assertFalse('foo' in section.options)
+        # The option didn't exist initially so it we need to keep track of it
+        # with a special value
+        self.assertTrue('foo' in section.orig)
+        self.assertEquals(config._Created, section.orig['foo'])
+
 
 class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
 



More information about the bazaar-commits mailing list